I am trying to use a local variable using jsondecode function to parse a json file. I am not sure about the code which i should use to pass the attributes for the resources.
I am trying to create VMs, Nic, disk etc using the below code, but stuck at the first step while createing nic card.
Thanks for spotting the error. I have adjusted the code and observer the below error. I noticed the key name only VirtualMachines were picked by the code and i removed it for testing purpose.
on vm_linux.tf line 59, in resource “azurerm_network_interface” “sn-net-inf”:
59: subnet_id = local.json_data[each.key].subnet.id
|----------------
| each.key is “ECPDB”
| local.json_data is object with 1 attribute “ECPDB”
My assumption here is that something is up with the parsing of your JSON, or the structure … I’d debug by making some output {} values where you access values within your JSON. Using the lookup function could help if you have defaults you want to fall back to (however, you might want the error, in order to demonstrate when traversing the object has failed).
I have fixed the issue finally. The JSON format seems to be correct… I had an issue in the data block of the subsets. It took a while for me to figure out… thanks a lot for your support and advice.