Can I programmatically provision Azure Management Groups using Terraform?

Alex Rom 60 Reputation points
2023-11-25T20:24:23.5466667+00:00

Working on an Azure DevOps pipeline that creates IaC! Was wondering if it would be possible to create an Azure Management Group Can programmatically?

Azure Managed Applications
Azure Managed Applications
An Azure service that enables managed service providers, independent software vendors, and enterprise IT teams to deliver turnkey solutions through the Azure Marketplace or service catalog.
113 questions
{count} votes

Accepted answer
  1. AdamZachary 2,866 Reputation points
    2023-11-25T20:31:32+00:00

    Hi Alex,

    Yes, you can programmatically provision Azure Management Groups using Terraform. The Terraform AzureRM provider includes a resource specifically for this purpose. To create a management group within Azure using Terraform, you would use the azurerm_management_group resource. This resource allows you to define and manage an Azure Management Group, which is useful for organizing resources and implementing governance across multiple Azure subscriptions.

    https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/management_groupUser's image

    But please pay attention that HashiCorp update regarding Subscription_ID when trying to associate subscription to a MG.

    Also, it's important to note that when creating a management group in Azure, you need to set the scope to / for the management group in the management group deployment​​. This detail, along with other configuration specifics, can be found in the Terraform documentation linked above.

    Here is a basic example of how you might define a management group in Terraform:

    resource "azurerm_management_group" "example" {
    		name = "example-management-group"    
    		# Optional arguments  display_name = "Example Management Group"   
    		parent_management_group_id = "parent-management-group-id" 
    }   
    

    You also can replace the name, display_name, parent_management_groups_id parameter's value with variables.

    Kindly if you find the provided information helpful and it resolves your query, please consider accepting the answer. Your feedback is valuable and helps ensure the quality and relevance of the responses.

    0 comments No comments

0 additional answers

Sort by: Most helpful