From bfa8dfc75d7dda8860d02b58e0c8798bf7c26103 Mon Sep 17 00:00:00 2001 From: Dalton Hubble Date: Tue, 17 Oct 2017 18:20:15 -0700 Subject: [PATCH] Conditionally set networkd content on bare-metal * Without this change, if a cluster doesn't set the controller or worker networkd lists, an err "element() may not be used with an empty list" occurs. * controller_networkds and worker_networks are intended to be optional and temporary, not required at all --- bare-metal/container-linux/kubernetes/profiles.tf | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bare-metal/container-linux/kubernetes/profiles.tf b/bare-metal/container-linux/kubernetes/profiles.tf index 6dd57cf6..c9d188c7 100644 --- a/bare-metal/container-linux/kubernetes/profiles.tf +++ b/bare-metal/container-linux/kubernetes/profiles.tf @@ -87,7 +87,9 @@ data "template_file" "controller-configs" { etcd_initial_cluster = "${join(",", formatlist("%s=https://%s:2380", var.controller_names, var.controller_domains))}" k8s_dns_service_ip = "${module.bootkube.kube_dns_service_ip}" ssh_authorized_key = "${var.ssh_authorized_key}" - networkd_content = "${element(var.controller_networkds, count.index)}" + + # Terraform evaluates both sides regardless and element cannot be used on 0 length lists + networkd_content = "${length(var.controller_networkds) == 0 ? "" : element(concat(var.controller_networkds, list("")), count.index)}" } } @@ -107,6 +109,8 @@ data "template_file" "worker-configs" { domain_name = "${element(var.worker_domains, count.index)}" k8s_dns_service_ip = "${module.bootkube.kube_dns_service_ip}" ssh_authorized_key = "${var.ssh_authorized_key}" - networkd_content = "${element(var.worker_networkds, count.index)}" + + # Terraform evaluates both sides regardless and element cannot be used on 0 length lists + networkd_content = "${length(var.worker_networkds) == 0 ? "" : element(concat(var.worker_networkds, list("")), count.index)}" } }