Hi,
I’m using the template_cloud_init_config
as a data source in order to provision several virtual machines with cloud-init configuration. And I’m using part
blocks so that I can separate the user-data
cloud-init config from the additional bash scripts that the virtual machines will run afterwards.
I’m trying to use a different value in the cloud-init template for each virtual machine. The issue I’m having is that I cannot use count.index
in the part
blocks (within template_cloud_init_config
).
This is my config:
data "template_cloudinit_config" "work" {
# split in parts - 1st is cloud-init cfg as such; from 2nd onwards, shell scripts.
# default gzip is true + base64 encoded (for proxmox don't encode or zip the cloud-init)
gzip = false
base64_encode = false
part {
filename = "cloud-init.cfg"
content_type = "text/cloud-config"
content = templatefile("${path.module}/files/cloud_init_ub2004.tpl", {
root_ssh_key = file("${path.module}/files/id_ed25519.pub")
ejobs-cert = file("${path.module}/files/comp-cert.yaml")
haproxy-deploy = file("${path.module}/files/haproxy-deploy.yaml")
haproxy-ingress = file("${path.module}/files/haproxy-ingress.yaml")
dockerconfigjson = file("${path.module}/files/dockerconfigjson")
instance_ip = var.ip[count.index + 1]
})
}
part {
filename = "kube-init.sh"
content_type = "text/x-shellscript"
content = templatefile("${path.module}/files/kube-init.sh", {
cidr = local.cidr
})
}
}
With this config I get:
╷
│ Error: Reference to "count" in non-counted context
│
│ on main.tf line 49, in data "template_cloudinit_config" "work":
│ 49: instance_ip = var.ip[count.index + 1]
│
│ The "count" object can only be used in "module", "resource", and "data" blocks, and only when the
│ "count" argument is set.
╵
the ip
variable is a list with IPs.
Any ideas how I could get around this issue?