mirror of
https://github.com/puppetmaster/typhoon.git
synced 2024-12-26 06:19:33 +01:00
f3730b2bfa
* Introduce the ability to support Container Linux Config "snippets" for controllers and workers on cloud platforms. This allows end-users to customize hosts by providing Container Linux configs that are additively merged into the base configs defined by Typhoon. Config snippets are validated, merged, and show any errors during `terraform plan` * Example uses include adding systemd units, network configs, mounts, files, raid arrays, or other disk provisioning features provided by Container Linux Configs (using Ignition low-level) * Requires terraform-provider-ct v0.2.1 plugin
96 lines
2.8 KiB
HCL
96 lines
2.8 KiB
HCL
# Controller Instance DNS records
|
|
resource "digitalocean_record" "controllers" {
|
|
count = "${var.controller_count}"
|
|
|
|
# DNS zone where record should be created
|
|
domain = "${var.dns_zone}"
|
|
|
|
# DNS record (will be prepended to domain)
|
|
name = "${var.cluster_name}"
|
|
type = "A"
|
|
ttl = 300
|
|
|
|
# IPv4 addresses of controllers
|
|
value = "${element(digitalocean_droplet.controllers.*.ipv4_address, count.index)}"
|
|
}
|
|
|
|
# Discrete DNS records for each controller's private IPv4 for etcd usage
|
|
resource "digitalocean_record" "etcds" {
|
|
count = "${var.controller_count}"
|
|
|
|
# DNS zone where record should be created
|
|
domain = "${var.dns_zone}"
|
|
|
|
# DNS record (will be prepended to domain)
|
|
name = "${var.cluster_name}-etcd${count.index}"
|
|
type = "A"
|
|
ttl = 300
|
|
|
|
# private IPv4 address for etcd
|
|
value = "${element(digitalocean_droplet.controllers.*.ipv4_address_private, count.index)}"
|
|
}
|
|
|
|
# Controller droplet instances
|
|
resource "digitalocean_droplet" "controllers" {
|
|
count = "${var.controller_count}"
|
|
|
|
name = "${var.cluster_name}-controller-${count.index}"
|
|
region = "${var.region}"
|
|
|
|
image = "${var.image}"
|
|
size = "${var.controller_type}"
|
|
|
|
# network
|
|
ipv6 = true
|
|
private_networking = true
|
|
|
|
user_data = "${element(data.ct_config.controller_ign.*.rendered, count.index)}"
|
|
ssh_keys = ["${var.ssh_fingerprints}"]
|
|
|
|
tags = [
|
|
"${digitalocean_tag.controllers.id}",
|
|
]
|
|
}
|
|
|
|
# Tag to label controllers
|
|
resource "digitalocean_tag" "controllers" {
|
|
name = "${var.cluster_name}-controller"
|
|
}
|
|
|
|
# Controller Container Linux Config
|
|
data "template_file" "controller_config" {
|
|
count = "${var.controller_count}"
|
|
|
|
template = "${file("${path.module}/cl/controller.yaml.tmpl")}"
|
|
|
|
vars = {
|
|
# Cannot use cyclic dependencies on controllers or their DNS records
|
|
etcd_name = "etcd${count.index}"
|
|
etcd_domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
|
|
|
# etcd0=https://cluster-etcd0.example.com,etcd1=https://cluster-etcd1.example.com,...
|
|
etcd_initial_cluster = "${join(",", formatlist("%s=https://%s:2380", null_resource.repeat.*.triggers.name, null_resource.repeat.*.triggers.domain))}"
|
|
k8s_dns_service_ip = "${cidrhost(var.service_cidr, 10)}"
|
|
cluster_domain_suffix = "${var.cluster_domain_suffix}"
|
|
}
|
|
}
|
|
|
|
# Horrible hack to generate a Terraform list of a desired length without dependencies.
|
|
# Ideal ${repeat("etcd", 3) -> ["etcd", "etcd", "etcd"]}
|
|
resource null_resource "repeat" {
|
|
count = "${var.controller_count}"
|
|
|
|
triggers {
|
|
name = "etcd${count.index}"
|
|
domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
|
}
|
|
}
|
|
|
|
data "ct_config" "controller_ign" {
|
|
count = "${var.controller_count}"
|
|
content = "${element(data.template_file.controller_config.*.rendered, count.index)}"
|
|
pretty_print = false
|
|
|
|
snippets = ["${var.controller_clc_snippets}"]
|
|
}
|