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_group
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.