Hello all,
I am curious on suggestions. I have a map list of values that I am passing from tfvars to a module to create x# for VM’s but then want to have a sparse list of managed disks as well. Here is an example of my map:
nodes = {
server = {
count = 1
vm_type = "Standard_DS1_v2"
os_size = 200
disk_names = ["yumcache", "opt", "cache", "work", "data", "assets"]
disk_sizes = [50, 200, 300, 100, 50, 25]
disk_lun = [10, 20, 30, 40, 50, 60]
}
Here is what my module block looks like:
module "nodes" {
for_each = var.nodes
source = "./modules/azurerm_vm"
name = each.key
node_count = each.value.count
azure_rg_name = module.resource_group.name
azure_rd_location = var.location
vnet_subnet_id = module.vnet.subnets["misc"].id
vm_type = each.value.vm_type
os_size = each.value.os_size
azure_nsg_id = module.nsg.id
tags = module.resource_group.tags
vm_admin = var.vm_admin
vm_zone = var.vm_zone
ssh_public_key = file(var.ssh_public_key)
create_public_ip = var.create_public_ip
disk_names = each.value["disk_names"]
disk_sizes = each.value["disk_sizes"]
disk_lun = each.value["disk_lun"]
depends_on = [module.vnet]
}
With what I currently have, it will create the VM’s based on the count I have and it will create the disks as outlined in my map. The problem I am running into is that I want to attach each corresponding disk to the previously created VM. I am not sure how to collect the “virtual_machine_id” and map it to the parent “server” key then associate it with the appropriate number of disks that I had created.
Curious if anyone has run into this before and/or could provide some advice on how I should proceed. I though of created a separate module for disk attachment and then having the virtual_machine_id’s in outputs but struggling with the approach on mapping VM id’s with the correct number of disks.