Skip to content

Deployment stack does not delete old role assignments when name changes #233

@Rick-van-Dam

Description

@Rick-van-Dam

Describe the bug
We changed the name of a Microsoft.Authorization/roleAssignments@2022-04-01 from name: guid(keyVaultName, roleName, identity.name, subscription().subscriptionId, env) to name: guid(kv.id, roleIdToAssign, identity.principalId) and noticed that the old role assignment is not deleted. This then results in this error:

{
            "code": "RoleAssignmentExists",
            "message": "The role assignment already exists."
}

To Reproduce

  1. Deploy a roleassignment using a deployment stack
  2. Change name of roleassignment
  3. Notice the old assignment is nog deleted and you get an error due to duplicate role assignments

Additional context
This is the part of the build that invokes bicep:

                - task: AzureCLI@2
                  displayName: "Deploy Bicep stack template in ${{ parameters.location }}"
                  inputs:
                    connectedServiceNameARM: ${{ variables.azureSubscription }}
                    scriptType: "pscore"
                    scriptLocation: "inlineScript"
                    inlineScript: |
                      az stack sub create `
                      --location ${{ parameters.location }} `
                      --name ${{ variables.deploymentStackName }} `
                      --template-file ${{ variables.templateFilePath }} `
                      --action-on-unmanage deleteAll `
                      --deny-settings-mode none `
                      $(deploymentArguments) `
                      --verbose

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions