I’m using map(any) variables in an Azure Terraform environment. I need to import some existing Azure resource groups, and they need to correlate to the mappings. For example:
Resource group ID | map key in tfvars
|/subscriptions/guid/resourceGroups/Marketing |Team1
|/subscriptions/guid/resourceGroups/Infrastructure|Team2
|/subscriptions/guid/resourceGroups/Legal|Team2
and so forth.
If I just run terraform import --var-file=varfile.tfvars azurerm_resource_group.rg-list /subscriptions/guid/resourceGroups/Marketing
, it imports the resource, but running terraform apply with the mappings doesn’t reflect that the RG already exists and wants to destroy it.
If I run it with escaped quotes, e.g. terraform import -var-file varfile.tfvars 'azurerm_resource_group.rg-list[\"Team2\"]' /subscriptions/guid/resourceGroups/Marketing
, it prepares the import but then errors out multiple times that the given key does not identify an element in the collection value.
How do I go about importing these resource groups corresponding to their map keys so that they remain under management?