I'm learning terraform, in the example below the first section puts a VM and returns the id of that VM. The second section adds an extra disk to vm. I have to enter an id in the virtual_machine_id parameter, but I don't know how (cloudstack_instance.worker[$name].id not working). Could someone have a hint?
resource "cloudstack_instance" "worker" {
for_each = {
for name, machine in var.machines :
name => machine
if machine.node_type == "worker"
}
name = "${var.prefix}-${each.key}"
service_offering = "K8S-RBD"
network_id = var.network_id
template = var.template_id
zone = var.zone
project = var.project_id
expunge = true
group = var.prefix
keypair = var.keypair
tags = {
name = "Terraform-VM"
}
}
resource "cloudstack_disk" "worker" {
for_each = {
for name, machine in var.machines :
name => machine
if machine.node_type == "worker"
}
name = "${var.prefix}-${each.key}"
attach = "true"
disk_offering = "Custom-RBD"
size = 50
virtual_machine_id = cloudstack_instance.worker[$name].id
zone = var.zone
project = var.project_id
depends_on = [cloudstack_instance.worker]
}