Error: Invalid for_each argument
on .terraform/modules/hub.hub/main.tf line 14, in resource "azurerm_resource_group" "rg":
for_each = { for rg in local.resource_group_data : rg.name => rg }
local.resource_group_data is set of object with 1 element
The "for_each" map includes keys derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys that will identify the instances of this resource.
When working with unknown values in for_each, it's better to define the map keys statically in your configuration and place apply-time results only in the map values.
Alternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully converge.
Expected Behaviour
We expect the resource group to be created with the name defined by the Azure/naming/azurerm module
Actual Behaviour
Failure because a for_each loop based on the name of the resource_group leading Terraform to be unable to compute the amount of created resources since the name_unique will be known after the apply.
Is there an existing issue for this?
Greenfield/Brownfield provisioning
greenfield
Terraform Version
1.9.2
Module Version
1.2.0
AzureRM Provider Version
3.111.0
Affected Resource(s)/Data Source(s)
azurerm_resource_group
Terraform Configuration Files
tfvars variables values
Debug Output/Panic Output
Expected Behaviour
We expect the resource group to be created with the name defined by the
Azure/naming/azurerm
moduleActual Behaviour
Failure because a for_each loop based on the name of the resource_group leading Terraform to be unable to compute the amount of created resources since the name_unique will be known after the apply.
Steps to Reproduce
terraform plan
Important Factoids
No response
References
No response