I'm creating Azure Landing zones using Terraform. Here is the main.tf
data "azurerm_client_config" "core" {}
module "enterprise_scale" {
source = "Azure/caf-enterprise-scale/azurerm"
version = ">= 1.7.0" # change this to your desired version, https://www.terraform.io/language/expressions/version-constraints
default_location = "canadacentral"
providers = {
azurerm = azurerm
azurerm.connectivity = azurerm
azurerm.management = azurerm
}
root_parent_id = data.azurerm_client_config.core.tenant_id
root_id = var.root_id
root_name = var.root_name
deploy_management_resources = var.deploy_management_resources
subscription_id_management = data.azurerm_client_config.core.subscription_id
deploy_connectivity_resources = var.deploy_connectivity_resources
subscription_id_connectivity = data.azurerm_client_config.core.subscription_id
}
But I'm getting error when I run terraform apply command:
Error: creating Management Group Subscription Association between "aasba-management" and "Subscription (Subscription: "xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")": managementgroups.SubscriptionsClient#Create: Failure responding to request: StatusCode=400 -- Original Error: autorest/azure: Service returned an error. Status=400 Code="BadRequest" Message="Permission to write and delete on resources of type 'Microsoft.Authorization/roleAssignments' is required on the subscription or its ancestors." Details=[{"raw":"Subscription ID: '/subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'"}]
│
│ with module.enterprise_scale.azurerm_management_group_subscription_association.enterprise_scale["/providers/Microsoft.Management/managementGroups/aasba-management/subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"],
│ on .terraform\modules\enterprise_scale\resources.management_groups.tf line 114, in resource "azurerm_management_group_subscription_association" "enterprise_scale":
│ 114: resource "azurerm_management_group_subscription_association" "enterprise_scale" {
I created following custom role with the scope of same subscription but getting same error.
Any help to resolve the issue will be appreciated.
{
"Name": "Terraform Custom RBAC Role",
"IsCustom": true,
"Description": "Allow to create Role Assignment using Terraform in Azure Landing Zones.",
"Actions": [
"Microsoft.Authorization/roleAssignments/write",
"Microsoft.Authorization/roleAssignments/delete",
"Microsoft.Authorization/roleAssignments/read",
"Microsoft.Management/managementGroups/*",
"Microsoft.Authorization/*/read"
],
"NotActions": [],
"DataActions": [],
"NotDataActions": [],
"AssignableScopes": [
"/subscriptions/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
]
}