Repository navigation
fix: Add identity placeholders for existing principalId and clientId (#3972) - #3974
Open
Sebastian Claesson (SebastianClaesson) wants to merge 1 commit into
Conversation
…zure#3972) When a template references an `existing` user-assigned identity that is not part of the deployment, `reference()` returns an unknown mock for its `principalId` and `clientId`. Placed inside an object or array literal, such as a module parameter, the unknown mock expands to `null`, so a nested `uniqueString()` or `guid()` over the value failed with "The argument 'additional parameters as needed' for 'UniqueString' is not a valid string", and the whole file was skipped. Add `principalId` and `clientId` of `Microsoft.ManagedIdentity/userAssignedIdentities` to the typed resource placeholder table added in Azure#3908, so they resolve to a string. The placeholder is the same `ffffffff-ffff-ffff-ffff-ffffffffffff` GUID that is already used for identities deployed in the template. The pinned role assignment name in the symbolic name test changes because `guid(principalId)` now hashes the placeholder instead of an empty string. Fixes Azure#3972 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sebastian Claesson (SebastianClaesson)
requested a review
from a team
as a code owner
November 10, 2026 15:49
This branch has not been deployed
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.
PR Summary
Fixes #3972.
Expanding a template fails when a nested module's name or a role assignment's name hashes the
principalId(orclientId) of anexistinguser-assigned identity, for exampleuniqueString(grant.name, grant.principalId). The error is: "The argument 'additional parameters as needed' for 'UniqueString' is not a valid string", and the whole file is skipped.Root cause:
reference()on anexistingidentity that isn't part of the deployment returns an unknown mock forprincipalId/clientId. Once that mock is placed inside an object or array literal, such as a module parameter, it expands tonull, so the nesteduniqueString()/guid()gets a non-string.Fix: add
principalIdandclientIdofMicrosoft.ManagedIdentity/userAssignedIdentitiesto the typed resource placeholder table introduced in #3908, so they resolve to a string. The placeholder isffffffff-ffff-ffff-ffff-ffffffffffff, the value already used asPLACEHOLDER_GUIDfor identities deployed in the template, so existing and deployed identities now expand the same way. The expression functions stay strict, as in #3908.Scope and trade-offs:
tenantIdisn't added: its right value is the configured tenant, which the static table can't reach.resource.identity.principalIdgoes through a different path and isn't covered here.Tests:
Tests.Bicep.46fixture: an existing cross-resource-group identity, a module namedra-${uniqueString(grant.name, grant.principalId)}, and a role assignment named withguid(..., principalId, ...). Compiled with Bicep 0.48.1.TemplateVisitorTests.ProcessTemplate_WhenExistingResourcePropertyPassedToModuleAndHashed_ShouldExpandandFunctionTests.ReferenceWithIdentityPlaceholders. Both fail without the fix and pass with it.BicepSymbolicNameTests: one pinned role assignment name changes becauseguid(principalId)now hashes the placeholder instead of an empty string.PR Checklist