0

Any advice on additional troubleshooting steps for the below error?

Error: Management Group "00000000-0000-0000-0000-000000000000" was not found
with data.azurerm_management_group.current
on main.tf line 40, in data "azurerm_management_group" "current":

data "azurerm_management_group" "current" {
  • I am using a service principal with the Contributor role assigned to authenticate to azure.
  • I have ensured the management group UUID set in the terraform config points to the correct ID.
  • I have ensured that access management for Azure resources in the azure active directory is enabled so that my user account can manage access to all Azure subscriptions and management groups in this tenant.
  • I know that the GET Management REST API throws errors when calls are made to azure ad tenants with large resource hierarchies that would return a payload greater than 15 MB. However, I only have 1 root tenant management group in my tenant that I want to reference.

The data source is configured as:

data "azurerm_management_group" "current" {
    # parent management group ID pulled in as a variable from terraform cloud using interpolation
    name = var.parent_mg_id
}

The management group resource which will be created once the data source can be referenced is currently set as follows:

resource "azurerm_management_group" "az104-02-mg1" {
    display_name = "az104-02-mg1"
    # current subscription associated with existing tenant assigned to this management group
    subscription_ids = [data.azurerm_subscription.current.subscription_id]
    # existing root management group within AAD tenant set as parent mg of az-104 lab 2 management group
    parent_management_group_id = data.azurerm_management_group.current.parent_management_group_id 
}

Thanks in advance!

jmhpecds
  • 1
  • 4

1 Answers1

0

I tried to reproduce the same issue in my environment and got the below results

I have used the following script for the management groups it worked for me

vi vm.tf

provider "azurerm" {
  features {}
}

data "azurerm_subscription" "current" {
}

resource "azurerm_management_group" "example_parent" {
  display_name = "ParentGroup"

  subscription_ids = [
    data.azurerm_subscription.current.subscription_id,
  ]
}

resource "azurerm_management_group" "example_child" {
  display_name               = "ChildGroup"
  parent_management_group_id = azurerm_management_group.example_parent.id

  subscription_ids = [
    data.azurerm_subscription.current.subscription_id,
  ]
}

Follow the below steps to execute the file

Terraform init

It will initialize the file

enter image description here

terraform plan

This will creates an execution plan and it will preview the changes that terraform plans to make the infrastructure

enter image description here

terraform apply

This will creates or updates the infrastructure depending on the configuration

enter image description here

Komali Annem
  • 649
  • 1
  • 1
  • 7