You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using azurerm_role_definition to create a role scoped to a Management Group instead to a Subscription or Resource Group, terraform destroy fails cause the scope sent to the API is empty.
This seems to be casued by the parseRoleDefinitionId function defined here, which asumes that every roleDefinitionId starts with the scope which is not the case for Roles scoped to a Management Group.
Community Note
Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform (and AzureRM Provider) Version
Terraform v0.12.17
provider.azurerm v1.38.0
Affected Resource(s)
azurerm_role_definition
Terraform Configuration Files
terraform {
required_providers {
azurerm=">= 1.38.0"
}
}
variable"mg_id" {
type=stringdescription="Existing Management Group ID"
}
locals {
scope="/providers/Microsoft.Management/managementGroups/${var.mg_id}"
}
resource"azurerm_role_definition""RoleInManagementGroup" {
name="[REMOVE] Role In Management Group"scope=local.scopedescription="This is a custom role created via Terraform"permissions {
actions=["*"]
not_actions=[]
}
assignable_scopes=[
local.scope
]
}
Error deleting Role Definition "00000000-0000-0000-0000-000000000000" at Scope "": authorization.RoleDefinitionsClient#Delete: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailed" Message="The client 'live.com#[email protected]' with object id '00000000-0000-0000-0000-000000000000' does not have authorization to perform action 'Microsoft.Authorization/roleDefinitions/delete' over scope '/providers/Microsoft.Authorization/roleDefinitions/fc4a1caf-aee2-b29b-14e4-11de9aa09cd6' or the scope is invalid. If access was recently granted, please refresh your credentials."
Issue seems to be related to the fact that Terraform is sending en empty scope.
Steps to Reproduce
You'll need to have an existing management group. The config file will ask for the ID of the group.
terraform apply
terraform destroy
Important Factoids
References
The text was updated successfully, but these errors were encountered:
Hi @katbyte, @tombuildsstuff I fixed this in e4a0e56 on a branch based on tag v1.38.0. Since the master branch has changed so much should I make a PR based on that tag?
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!
ghost
locked as resolved and limited conversation to collaborators
Oct 9, 2020
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
When using azurerm_role_definition to create a role scoped to a Management Group instead to a Subscription or Resource Group,
terraform destroy
fails cause the scope sent to the API is empty.This seems to be casued by the parseRoleDefinitionId function defined here, which asumes that every roleDefinitionId starts with the scope which is not the case for Roles scoped to a Management Group.
Community Note
Terraform (and AzureRM Provider) Version
Terraform v0.12.17
Affected Resource(s)
azurerm_role_definition
Terraform Configuration Files
Debug Output
https://gist.github.com/cmendible/e44f10b665ba9c97cb9a9d1167c5bd99#file-debug-log
Panic Output
Expected Behavior
Role must be deleted by
terraform destroy
Actual Behavior
terraform destroy
results in:Error deleting Role Definition "00000000-0000-0000-0000-000000000000" at Scope "": authorization.RoleDefinitionsClient#Delete: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailed" Message="The client 'live.com#[email protected]' with object id '00000000-0000-0000-0000-000000000000' does not have authorization to perform action 'Microsoft.Authorization/roleDefinitions/delete' over scope '/providers/Microsoft.Authorization/roleDefinitions/fc4a1caf-aee2-b29b-14e4-11de9aa09cd6' or the scope is invalid. If access was recently granted, please refresh your credentials."
Issue seems to be related to the fact that Terraform is sending en empty scope.
Steps to Reproduce
You'll need to have an existing management group. The config file will ask for the ID of the group.
terraform apply
terraform destroy
Important Factoids
References
The text was updated successfully, but these errors were encountered: