Hello,
I have the following map (of map) variable:
kubernetes_servers = {
etcd-1 = {
ip_address = "10.88.88.222"
}
etcd-2 = {
ip_address = "10.88.88.223"
}
etcd-3 = {
ip_address = "10.88.88.224"
}
kube-controlplane-1 = {
ip_address = "10.88.88.225"
}
kube-controlplane-2 = {
ip_address = "10.88.88.226"
}
kube-worker-1 = {
ip_address = "10.88.88.227"
}
}
What I need to achieve is eventually this:
initial-cluster: etcd-1=https://10.88.88.222:2380,etcd2=https://10.88.88.223:2380,etcd3=https://10.88.88.224:2380
What I tried doing was to split the variables into two lists, so that it’s accepted by the terraform template as such:
kubeadm_config_file = templatefile("${path.module}/files/kubernetes/kubeadm-config.tpl", {
etcd_names = [ for name, v in var.kubernetes_servers : "${name}" if startswith(name, "etcd-") ]
etcd_ips = [ for name, v in var.kubernetes_servers : "${v["ip_address"]}" if startswith(name, "etcd-") ]
})
But with this solution I have two big issues: two variables instead of one, so I’m not sure how I’m supposed to use a loop where I’d use the values of both variables for the same iteration (name and ip) and the second issue is that I need to do this all in one line.
Maybe it made more sense to do it directly in hcl and the insert the string as such into the template, if it’s even possible?