Hi All,
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.
locals{
json_data = jsondecode(file("main.tfvars.json"))}
resource "azurerm_network_interface" "sn-net-inf" {
for_each = local.json_data
name = format("%s-nic",each.key)
location = each.local.value.location
resource_group_name = each.local.value.resource_group_name
ip_configuration {
name = "IPConfig1"
subnet_id = each.value.subnet
private_ip_address = each.local.value.ip_config
private_ip_address_allocation = "static"
}
}
Below is the sample of json…
"VirtualMachines": {
"ECPDB": {
"OS": "SUSE Linux 15 SP1",
"type" : "Linux",
"resource_group_name": "poc_rg",
"location": "eastus",
"virtual_network": "hub-net",
"subnet":"app-subnet",
"ip_config":"10.1.1.1",
"Disk": [
{
"Name": "OS Disk",
...
Many thanks in advance.