Closed praveenambati1233 closed 1 week ago
hi you can use the terraform import block to do this - see this issue: https://github.com/Azure/terraform-azurerm-caf-enterprise-scale/issues/992
Yes, I did try with the command - terraform import module.core.module.alz.azurerm_management_group.level_1["/providers/Microsoft.Management/managementGroups/client-mg"] '/providers/Microsoft.Management/managementGroups/client-mg'
Here is the error I am encountering
│ Error: Invalid for_each argument
│
│ on caf/resources.management_groups.tf line 32, in resource "azurerm_management_group" "level_3":
│ 32: for_each = local.azurerm_management_group_level_3
│ ├────────────────
│ │ local.azurerm_management_group_level_3 will be known only after apply
│
│ 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.
@matt-FFFFFF Updated the issue in the description with replication steps.
I don't think this error is due to the import. It's more likely that you have some module inputs that are not known until after apply.
It is fixed with import{}
import {
to = module.enterprise_scale.azurerm_management_group.level_1["/providers/Microsoft.Management/managementGroups/myorg"]
id = "/providers/Microsoft.Management/managementGroups/myorg"
}
Thank You for your support.
My client is already created the Level 1 Management Group. How can I refer the existing Level 1 Management Group and create the Level 2 Management Groups ( Platform and Landing Zones )?
How to replicate ?
root id
"myorg" androot name
"My Organization" Tenant Root Group"Error :
Troubleshooting
Tried to import the state but it is failed at CAF management group module
terraform import 'module.enterprise_scale.azurerm_management_group.level_1["/providers/Microsoft.Management/managementGroups/myorg"]' /providers/Microsoft.Management/managementGroups/myorg
Error :