'Terraform convert list from csv to map
I have a csv file with thoses values to create azure vm.
"os_type","vm_hostname","vm_os_simple","vm_size","data_sa1_type","data_disk1_size_gb","data_sa2_type","data_disk2_size_gb","enable_accelerated_networking"
I would like to have an idea how to create a map of data disk informations to create multiple data disks by vm's with datadisk names based on machine name and data disk index.
for exemple if I created a var.data_disks map object like below
data_disks = [
{
name = "disk1"
disk_size_gb = 100
storage_account_type = "StandardSSD_LRS"
},
{
name = "disk2"
disk_size_gb = 200
storage_account_type = "Standard_LRS"
}
]
I can get my information like this
vm_data_disks = { for idx, data_disk in var.data_disks : data_disk.name => { idx : idx, data_disk : data_disk,}}
which produced
Changes to Outputs:
+ nulresource = {
+ disk1 = {
+ data_disk = {
+ disk_size_gb = 100
+ name = "disk1"
+ storage_account_type = "StandardSSD_LRS"
}
+ idx = 0
}
+ disk2 = {
+ data_disk = {
+ disk_size_gb = 200
+ name = "disk2"
+ storage_account_type = "Standard_LRS"
}
+ idx = 1
}
but in my case I used csvdecode to get my information
locals {
vmparameters = csvdecode(file("input.csv"))
}
and I would like from the csv input create the same résult like the output above my goals is to loop throught this map my to create my datadisk. below is what I tried by it's it not good
# dynamic storage_data_disk {
# for_each = [for k,v in {for val in local.vmparameters : val.nb_data_disk => index(local.vmparameters, val) if val.os_type == "windows"} : k ]
# content {
# name = format("${upper(each.key)}-datadisk%02", storage_data_disk.key + 1)
# create_option = "Empty"
# lun = 0
# disk_size_gb = each.value.data_disk_size_gb
# managed_disk_type = each.value.data_sa_type
# }
# }
Some ideas ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
