Template etcd_servers list to replace null_resource.repeat
* Remove the last usage of null_resource.repeat, which has always been an eyesore for creating the etcd server list * Originally, #224 switched to templating the etcd_servers list for all clouds, but had to revert on GCP in #237 * https://github.com/poseidon/typhoon/pull/224 * https://github.com/poseidon/typhoon/pull/237
This commit is contained in:
parent
bdf1e6986e
commit
b8eeafe4f9
|
@ -4,7 +4,7 @@ module "bootkube" {
|
||||||
|
|
||||||
cluster_name = "${var.cluster_name}"
|
cluster_name = "${var.cluster_name}"
|
||||||
api_servers = ["${format("%s.%s", var.cluster_name, var.dns_zone)}"]
|
api_servers = ["${format("%s.%s", var.cluster_name, var.dns_zone)}"]
|
||||||
etcd_servers = ["${null_resource.repeat.*.triggers.domain}"]
|
etcd_servers = ["${google_dns_record_set.etcds.*.name}"]
|
||||||
asset_dir = "${var.asset_dir}"
|
asset_dir = "${var.asset_dir}"
|
||||||
networking = "${var.networking}"
|
networking = "${var.networking}"
|
||||||
network_mtu = 1440
|
network_mtu = 1440
|
||||||
|
|
|
@ -36,7 +36,7 @@ resource "google_compute_instance" "controllers" {
|
||||||
machine_type = "${var.controller_type}"
|
machine_type = "${var.controller_type}"
|
||||||
|
|
||||||
metadata {
|
metadata {
|
||||||
user-data = "${element(data.ct_config.controller_ign.*.rendered, count.index)}"
|
user-data = "${element(data.ct_config.controller-ignitions.*.rendered, count.index)}"
|
||||||
}
|
}
|
||||||
|
|
||||||
boot_disk {
|
boot_disk {
|
||||||
|
@ -59,8 +59,16 @@ resource "google_compute_instance" "controllers" {
|
||||||
tags = ["${var.cluster_name}-controller"]
|
tags = ["${var.cluster_name}-controller"]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Controller Container Linux Config
|
# Controller Ignition configs
|
||||||
data "template_file" "controller_config" {
|
data "ct_config" "controller-ignitions" {
|
||||||
|
count = "${var.controller_count}"
|
||||||
|
content = "${element(data.template_file.controller-configs.*.rendered, count.index)}"
|
||||||
|
pretty_print = false
|
||||||
|
snippets = ["${var.controller_clc_snippets}"]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Controller Container Linux configs
|
||||||
|
data "template_file" "controller-configs" {
|
||||||
count = "${var.controller_count}"
|
count = "${var.controller_count}"
|
||||||
|
|
||||||
template = "${file("${path.module}/cl/controller.yaml.tmpl")}"
|
template = "${file("${path.module}/cl/controller.yaml.tmpl")}"
|
||||||
|
@ -71,7 +79,7 @@ data "template_file" "controller_config" {
|
||||||
etcd_domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
etcd_domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
||||||
|
|
||||||
# etcd0=https://cluster-etcd0.example.com,etcd1=https://cluster-etcd1.example.com,...
|
# 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))}"
|
etcd_initial_cluster = "${join(",", data.template_file.etcds.*.rendered)}"
|
||||||
|
|
||||||
kubeconfig = "${indent(10, module.bootkube.kubeconfig)}"
|
kubeconfig = "${indent(10, module.bootkube.kubeconfig)}"
|
||||||
ssh_authorized_key = "${var.ssh_authorized_key}"
|
ssh_authorized_key = "${var.ssh_authorized_key}"
|
||||||
|
@ -80,20 +88,13 @@ data "template_file" "controller_config" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Horrible hack to generate a Terraform list of a desired length without dependencies.
|
data "template_file" "etcds" {
|
||||||
# Ideal ${repeat("etcd", 3) -> ["etcd", "etcd", "etcd"]}
|
count = "${var.controller_count}"
|
||||||
resource null_resource "repeat" {
|
template = "etcd$${index}=https://$${cluster_name}-etcd$${index}.$${dns_zone}:2380"
|
||||||
count = "${var.controller_count}"
|
|
||||||
|
|
||||||
triggers {
|
vars {
|
||||||
name = "etcd${count.index}"
|
index = "${count.index}"
|
||||||
domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
cluster_name = "${var.cluster_name}"
|
||||||
|
dns_zone = "${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}"]
|
|
||||||
}
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ resource "google_compute_instance_template" "worker" {
|
||||||
machine_type = "${var.machine_type}"
|
machine_type = "${var.machine_type}"
|
||||||
|
|
||||||
metadata {
|
metadata {
|
||||||
user-data = "${data.ct_config.worker_ign.rendered}"
|
user-data = "${data.ct_config.worker-ignition.rendered}"
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduling {
|
scheduling {
|
||||||
|
@ -64,8 +64,15 @@ resource "google_compute_instance_template" "worker" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Worker Container Linux Config
|
# Worker Ignition config
|
||||||
data "template_file" "worker_config" {
|
data "ct_config" "worker-ignition" {
|
||||||
|
content = "${data.template_file.worker-config.rendered}"
|
||||||
|
pretty_print = false
|
||||||
|
snippets = ["${var.clc_snippets}"]
|
||||||
|
}
|
||||||
|
|
||||||
|
# Worker Container Linux config
|
||||||
|
data "template_file" "worker-config" {
|
||||||
template = "${file("${path.module}/cl/worker.yaml.tmpl")}"
|
template = "${file("${path.module}/cl/worker.yaml.tmpl")}"
|
||||||
|
|
||||||
vars = {
|
vars = {
|
||||||
|
@ -75,9 +82,3 @@ data "template_file" "worker_config" {
|
||||||
cluster_domain_suffix = "${var.cluster_domain_suffix}"
|
cluster_domain_suffix = "${var.cluster_domain_suffix}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data "ct_config" "worker_ign" {
|
|
||||||
content = "${data.template_file.worker_config.rendered}"
|
|
||||||
pretty_print = false
|
|
||||||
snippets = ["${var.clc_snippets}"]
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ module "bootkube" {
|
||||||
|
|
||||||
cluster_name = "${var.cluster_name}"
|
cluster_name = "${var.cluster_name}"
|
||||||
api_servers = ["${format("%s.%s", var.cluster_name, var.dns_zone)}"]
|
api_servers = ["${format("%s.%s", var.cluster_name, var.dns_zone)}"]
|
||||||
etcd_servers = ["${null_resource.repeat.*.triggers.domain}"]
|
etcd_servers = ["${google_dns_record_set.etcds.*.name}"]
|
||||||
asset_dir = "${var.asset_dir}"
|
asset_dir = "${var.asset_dir}"
|
||||||
networking = "${var.networking}"
|
networking = "${var.networking}"
|
||||||
network_mtu = 1440
|
network_mtu = 1440
|
||||||
|
|
|
@ -71,7 +71,7 @@ data "template_file" "controller-cloudinit" {
|
||||||
etcd_domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
etcd_domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
||||||
|
|
||||||
# etcd0=https://cluster-etcd0.example.com,etcd1=https://cluster-etcd1.example.com,...
|
# 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))}"
|
etcd_initial_cluster = "${join(",", data.template_file.etcds.*.rendered)}"
|
||||||
|
|
||||||
kubeconfig = "${indent(6, module.bootkube.kubeconfig)}"
|
kubeconfig = "${indent(6, module.bootkube.kubeconfig)}"
|
||||||
ssh_authorized_key = "${var.ssh_authorized_key}"
|
ssh_authorized_key = "${var.ssh_authorized_key}"
|
||||||
|
@ -80,13 +80,13 @@ data "template_file" "controller-cloudinit" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Horrible hack to generate a Terraform list of a desired length without dependencies.
|
data "template_file" "etcds" {
|
||||||
# Ideal ${repeat("etcd", 3) -> ["etcd", "etcd", "etcd"]}
|
count = "${var.controller_count}"
|
||||||
resource null_resource "repeat" {
|
template = "etcd$${index}=https://$${cluster_name}-etcd$${index}.$${dns_zone}:2380"
|
||||||
count = "${var.controller_count}"
|
|
||||||
|
|
||||||
triggers {
|
vars {
|
||||||
name = "etcd${count.index}"
|
index = "${count.index}"
|
||||||
domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}"
|
cluster_name = "${var.cluster_name}"
|
||||||
|
dns_zone = "${var.dns_zone}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue