Fix: Resolve duplicate Key Vault Administrator role assignment in workload zone deployment#998
Merged
KimForss merged 1 commit intoAzure:release/january-2026from Jan 15, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a duplicate Key Vault Administrator role assignment error that occurs during workload zone deployments with new Key Vaults. The issue was caused by two resources attempting to assign the same role to the same managed identity on the same Key Vault scope.
Changes:
- Modified
role_assignment_msicount condition to only execute for existing Key Vaults - Modified
role_assignment_msi_officercount condition to only execute for existing Key Vaults - Ensures mutually exclusive role assignment behavior:
role_assignment_msi*for existing KVs,kv_user_msi_rbac*for new KVs
Comments suppressed due to low confidence (2)
deploy/terraform/terraform-units/modules/sap_landscape/key_vault_sap_landscape.tf:107
- The scope conditional expression is now redundant. Since the count condition already ensures that this resource only runs when
var.key_vault.user.existsis true, the ternary operator in the scope will always evaluate to the first branch. Consider simplifying the scope to just usedata.azurerm_key_vault.kv_user[0].iddirectly for clarity.
scope = var.key_vault.user.exists ? (
data.azurerm_key_vault.kv_user[0].id) : (
azurerm_key_vault.kv_user[0].id
)
deploy/terraform/terraform-units/modules/sap_landscape/key_vault_sap_landscape.tf:139
- The scope conditional expression is now redundant. Since the count condition already ensures that this resource only runs when
var.key_vault.user.existsis true, the ternary operator in the scope will always evaluate to the first branch. Consider simplifying the scope to just usedata.azurerm_key_vault.kv_user[0].iddirectly for clarity.
scope = var.key_vault.user.exists ? (
data.azurerm_key_vault.kv_user[0].id) : (
azurerm_key_vault.kv_user[0].id
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
KimForss
approved these changes
Jan 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes duplicate Key Vault Administrator role assignment error when deploying workload zones with existing Key Vaults.
Problem
Workload zone deployments fail with error:
This occurs because when
var.key_vault.user.exists = true, both:role_assignment_msi(line 103)kv_user_msi_rbac(line 183)attempt to assign the Key Vault Administrator role to the MSI, creating a conflict.
Solution
Modified role assignment count conditions in
key_vault_sap_landscape.tfThis ensures MSI role assignments only apply to existing Key Vaults, while kv_user_msi_rbac handles new Key Vaults
Testing
Validated against workload zone deployment scenario