We had created role assignments with version 2.57.0, and then we tried to bump the version to 3.49.0, but it started failing. Then we tried to incrementally increase the version and it works only till 2.61.0. Beyond this, we get the authorization failure error.
We even tried updating the resource type to azurerm_management_group_policy_assignment
as these assignments are on the root management group.
The same code with the latest version works on newly created assignments and roles. But the issue is only with the existing roles assignments that were created with version 2.57.0.
Here is the code:
locals {
rolename = ["Monitoring Contributor", "Log Analytics Contributor"]
management_group_scope = "/providers/Microsoft.Management/managementgroups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}
resource "azurerm_policy_assignment" "dine_policy" {
.....
}
resource "azurerm_role_assignment" "law_roles" {
count = length (local.rolename)
scope = local.management_group_scope
role_definition_name = local.rolename[count.index]
principal_id = azurerm_policy_assignment.dine_policy.idenity[0].principal_id
}
And here is the error:
Error loading Role assignment "/providers/Microsoft.Management/managementgroups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Authorization/roleAssignments/<ROLE_ID>": authorization.RoleAssignmentsClient#GetByID: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned ane error. Status=403 Code="AuthorizationFailed" Message="The client '<CLIENT ID>' with object id '<OBJECT ID>' does not have authorization to perform action 'Microsoft.Management.managementGroups/Microsoft.Management/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/Microsoft.Authorization/<ROLE_ID>/read' over scope '/providers/Microsoft.Management/managementGroups/providers/Microsoft.Management/managementgroups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Authorization/roleAssignments' or the scope is invalid. If access was recent;y granted, please refresh your credentials.
What we see is that the "/providers/Microsoft.Management/managementGroups/providers/Microsoft.Management/managementgroups" is repeating in the following string from the error message:
"/providers/Microsoft.Management/managementGroups/providers/Microsoft.Management/managementgroups/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/providers/Microsoft.Authorization/roleAssignments"
The SPN has management group contributor on the root tenant, so it has enough permissions to read the role assignments. The same code works for newly created role assignments.
Going through the query it seems like you are encountering an issue with Terraform while managing Azure Role Assignments.
2.57.0
to3.49.0
is a significant jump and there might be breaking changes or updates in the AzureRM provider that could affect existing infrastructure.azurerm_management_group_policy_assignment
. Ensure that this change is compatible with your existing setup and that all necessary permissions are in place for this resource type.local.management_group_scope
variable and ensure that it is correctly formatted. It should typically be in the format:/providers/Microsoft.Management/managementGroups/{management-group-id}
My Demo Terraform Configuration:
This code is for reference purposes so please check with respective placeholders.
You can also check with the error bug request raised which was caused by the change in the provider version.