I am trying to deploy multiple resources(azure RGs) using variable map and fore each below is the variable and resource block i used.
variable “locationsmap”{
type = map(string)
default = {
RG1 = “westus”
RG2 = “westeurope”
RG3 = “northeurope”
}
}
resource “azurerm_resource_group” “example” {
for_each = var.locationsmap
name = each.key
location = each.value
}
Plan and deployment ran without any issues and resources also created. but when i try run terraform.exe state show azurerm_resource_group.example[“RG1”] receiving an error.
Deployment completed with out any issues.
State file
{
“version”: 4,
“terraform_version”: “0.12.26”,
“serial”: 35,
“lineage”: “7cf68376-4966-9924-a4b8-464b6c33ff94”,
“outputs”: {
“RG”: {
“value”: {
“RG1”: {
“id”: “/subscriptions/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/resourceGroups/RG1”,
“location”: “westus”,
“name”: “RG1”,
“tags”: {},
“timeouts”: null
},
“RG2”: {
“id”: “/subscriptions/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/resourceGroups/RG2”,
“location”: “westeurope”,
“name”: “RG2”,
“tags”: {},
“timeouts”: null
},
“RG3”: {
“id”: “/subscriptions/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/resourceGroups/RG3”,
“location”: “northeurope”,
“name”: “RG3”,
“tags”: {},
“timeouts”: null
}
},
“type”: [
“object”,
{
“RG1”: [
“object”,
{
“id”: “string”,
“location”: “string”,
“name”: “string”,
“tags”: [
“map”,
“string”
],
“timeouts”: [
“object”,
{
“create”: “string”,
“delete”: “string”,
“read”: “string”,
“update”: “string”
}
]
}
],
“RG2”: [
“object”,
{
“id”: “string”,
“location”: “string”,
“name”: “string”,
“tags”: [
“map”,
“string”
],
“timeouts”: [
“object”,
{
“create”: “string”,
“delete”: “string”,
“read”: “string”,
“update”: “string”
}
]
}
],
“RG3”: [
“object”,
{
“id”: “string”,
“location”: “string”,
“name”: “string”,
“tags”: [
“map”,
“string”
],
“timeouts”: [
“object”,
{
“create”: “string”,
“delete”: “string”,
“read”: “string”,
“update”: “string”
}
]
}
]
}
]
}
},
“resources”: [
{
“mode”: “managed”,
“type”: “azurerm_resource_group”,
“name”: “example”,
“each”: “map”,
“provider”: “provider.azurerm”,
“instances”: [
{
“index_key”: “RG1”,
“schema_version”: 0,
“attributes”: {
“id”: “/subscriptions/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/resourceGroups/RG1”,
“location”: “westus”,
“name”: “RG1”,
“tags”: {},
“timeouts”: null
},
“private”: “eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo1NDAwMDAwMDAwMDAwLCJkZWxldGUiOjU0MDAwMDAwMDAwMDAsInJlYWQiOjMwMDAwMDAwMDAwMCwidXBkYXRlIjo1NDAwMDAwMDAwMDAwfX0=”
},
{
“index_key”: “RG2”,
“schema_version”: 0,
“attributes”: {
“id”: “/subscriptions/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/resourceGroups/RG2”,
“location”: “westeurope”,
“name”: “RG2”,
“tags”: {},
“timeouts”: null
},
“private”: “eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo1NDAwMDAwMDAwMDAwLCJkZWxldGUiOjU0MDAwMDAwMDAwMDAsInJlYWQiOjMwMDAwMDAwMDAwMCwidXBkYXRlIjo1NDAwMDAwMDAwMDAwfX0=”
},
{
“index_key”: “RG3”,
“schema_version”: 0,
“attributes”: {
“id”: “/subscriptions/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/resourceGroups/RG3”,
“location”: “northeurope”,
“name”: “RG3”,
“tags”: {},
“timeouts”: null
},
“private”: “eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo1NDAwMDAwMDAwMDAwLCJkZWxldGUiOjU0MDAwMDAwMDAwMDAsInJlYWQiOjMwMDAwMDAwMDAwMCwidXBkYXRlIjo1NDAwMDAwMDAwMDAwfX0=”
}
]
}
]
}