From b8eeafe4f935fd9bbc810f82113cc270c3507c19 Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Tue, 21 Aug 2018 22:36:42 -0700 Subject: [PATCH] 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 --- .../container-linux/kubernetes/bootkube.tf | 2 +- .../container-linux/kubernetes/controllers.tf | 37 ++++++++++--------- .../kubernetes/workers/workers.tf | 19 +++++----- .../fedora-atomic/kubernetes/bootkube.tf | 2 +- .../fedora-atomic/kubernetes/controllers.tf | 16 ++++---- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/google-cloud/container-linux/kubernetes/bootkube.tf b/google-cloud/container-linux/kubernetes/bootkube.tf index 8b0617e6..d337d364 100644 --- a/google-cloud/container-linux/kubernetes/bootkube.tf +++ b/google-cloud/container-linux/kubernetes/bootkube.tf @@ -4,7 +4,7 @@ module "bootkube" { cluster_name = "${var.cluster_name}" 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}" networking = "${var.networking}" network_mtu = 1440 diff --git a/google-cloud/container-linux/kubernetes/controllers.tf b/google-cloud/container-linux/kubernetes/controllers.tf index a3d28c79..aec7ad52 100644 --- a/google-cloud/container-linux/kubernetes/controllers.tf +++ b/google-cloud/container-linux/kubernetes/controllers.tf @@ -36,7 +36,7 @@ resource "google_compute_instance" "controllers" { machine_type = "${var.controller_type}" 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 { @@ -59,8 +59,16 @@ resource "google_compute_instance" "controllers" { tags = ["${var.cluster_name}-controller"] } -# Controller Container Linux Config -data "template_file" "controller_config" { +# Controller Ignition configs +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}" 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}" # 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)}" 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. -# Ideal ${repeat("etcd", 3) -> ["etcd", "etcd", "etcd"]} -resource null_resource "repeat" { - count = "${var.controller_count}" +data "template_file" "etcds" { + count = "${var.controller_count}" + template = "etcd$${index}=https://$${cluster_name}-etcd$${index}.$${dns_zone}:2380" - triggers { - name = "etcd${count.index}" - domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}" + vars { + index = "${count.index}" + 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}"] -} diff --git a/google-cloud/container-linux/kubernetes/workers/workers.tf b/google-cloud/container-linux/kubernetes/workers/workers.tf index a8e38049..8a8d32ee 100644 --- a/google-cloud/container-linux/kubernetes/workers/workers.tf +++ b/google-cloud/container-linux/kubernetes/workers/workers.tf @@ -28,7 +28,7 @@ resource "google_compute_instance_template" "worker" { machine_type = "${var.machine_type}" metadata { - user-data = "${data.ct_config.worker_ign.rendered}" + user-data = "${data.ct_config.worker-ignition.rendered}" } scheduling { @@ -64,8 +64,15 @@ resource "google_compute_instance_template" "worker" { } } -# Worker Container Linux Config -data "template_file" "worker_config" { +# Worker Ignition 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")}" vars = { @@ -75,9 +82,3 @@ data "template_file" "worker_config" { 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}"] -} diff --git a/google-cloud/fedora-atomic/kubernetes/bootkube.tf b/google-cloud/fedora-atomic/kubernetes/bootkube.tf index 7dfef4c5..51b68723 100644 --- a/google-cloud/fedora-atomic/kubernetes/bootkube.tf +++ b/google-cloud/fedora-atomic/kubernetes/bootkube.tf @@ -4,7 +4,7 @@ module "bootkube" { cluster_name = "${var.cluster_name}" 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}" networking = "${var.networking}" network_mtu = 1440 diff --git a/google-cloud/fedora-atomic/kubernetes/controllers.tf b/google-cloud/fedora-atomic/kubernetes/controllers.tf index fe1f596d..ea49587d 100644 --- a/google-cloud/fedora-atomic/kubernetes/controllers.tf +++ b/google-cloud/fedora-atomic/kubernetes/controllers.tf @@ -71,7 +71,7 @@ data "template_file" "controller-cloudinit" { 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))}" + etcd_initial_cluster = "${join(",", data.template_file.etcds.*.rendered)}" kubeconfig = "${indent(6, module.bootkube.kubeconfig)}" 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. -# Ideal ${repeat("etcd", 3) -> ["etcd", "etcd", "etcd"]} -resource null_resource "repeat" { - count = "${var.controller_count}" +data "template_file" "etcds" { + count = "${var.controller_count}" + template = "etcd$${index}=https://$${cluster_name}-etcd$${index}.$${dns_zone}:2380" - triggers { - name = "etcd${count.index}" - domain = "${var.cluster_name}-etcd${count.index}.${var.dns_zone}" + vars { + index = "${count.index}" + cluster_name = "${var.cluster_name}" + dns_zone = "${var.dns_zone}" } }