Repository navigation
Honor AsExisting() on AddAzureContainerAppEnvironment + add WithAcrPullIdentity - #17365
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 17365Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 17365" |
There was a problem hiding this comment.
Pull request overview
This PR fixes publish-time Azure Container Apps infrastructure generation so that AddAzureContainerAppEnvironment(...).AsExisting(...) (and PublishAsExisting) no longer emits Bicep that creates a new managed environment and related child resources. It also adds a new API to let callers supply an existing user-assigned identity for ACR image pulls (WithAcrPullIdentity), avoiding identity/role-assignment creation during deployment.
Changes:
- Short-circuit environment infrastructure generation when the Container Apps environment is marked as existing, emitting a thin “existing references + required outputs” module and rejecting incompatible features (delegated subnet, volumes).
- Add
WithAcrPullIdentity(...)to allow BYO user-assigned identity forAcrPull, skipping creation ofenv_miand its role assignment. - Add/refresh snapshot-based tests validating both greenfield and
AsExistingpublish output for these scenarios.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerAppEnvironmentExtensionsTests.WithAcrPullIdentity_PublishGeneratesEnvWithSuppliedIdentity.verified.json | Snapshot of manifest params for greenfield env + supplied AcrPull identity. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerAppEnvironmentExtensionsTests.WithAcrPullIdentity_PublishGeneratesEnvWithSuppliedIdentity.verified.bicep | Snapshot of Bicep ensuring no env-managed identity / AcrPull role assignment is created when identity is supplied. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerAppEnvironmentExtensionsTests.WithAcrPullIdentity_AsExisting_PublishGeneratesThinModuleWithSuppliedIdentity.verified.json | Snapshot of manifest params for existing env + existing ACR + supplied identity. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerAppEnvironmentExtensionsTests.WithAcrPullIdentity_AsExisting_PublishGeneratesThinModuleWithSuppliedIdentity.verified.bicep | Snapshot of thin Bicep module referencing existing env/ACR and outputting required values. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerAppEnvironmentExtensionsTests.AsExisting_WithExplicitContainerRegistry_PublishGeneratesThinModule.verified.json | Snapshot of manifest params for existing env + explicitly existing ACR. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerAppEnvironmentExtensionsTests.AsExisting_WithExplicitContainerRegistry_PublishGeneratesThinModule.verified.bicep | Snapshot validating thin module behavior while still creating identity/role assignment when no identity is supplied. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerAppEnvironmentExtensionsTests.AsExisting_PublishGeneratesThinModuleReferencingExistingEnvironment.verified.json | Snapshot of manifest params for existing env with default registry wiring. |
| tests/Aspire.Hosting.Azure.Tests/Snapshots/AzureContainerAppEnvironmentExtensionsTests.AsExisting_PublishGeneratesThinModuleReferencingExistingEnvironment.verified.bicep | Snapshot validating existing env reference (no new env/LAW/dashboard) and required outputs. |
| tests/Aspire.Hosting.Azure.Tests/AzureContainerAppEnvironmentExtensionsTests.cs | Adds regression and scenario tests (including delegated-subnet rejection) plus snapshot verification. |
| src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs | Core behavior change: honor existing env at publish-time, add AcrPull identity override path, and unify shared outputs helper. |
| src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppEnvironmentAcrPullIdentityAnnotation.cs | New internal annotation used to flow the supplied identity through infrastructure generation. |
When AddAzureContainerAppEnvironment(...).AsExisting(...) was used, the publish-time infrastructure callback still produced a brand-new managed environment, Log Analytics workspace, Aspire Dashboard component, and managed identity. Now it short-circuits to a thin Bicep module that references the existing managed environment via 'existing' and emits the required outputs. Also adds WithAcrPullIdentity to let the caller supply a pre-provisioned user-assigned identity for the AcrPull role on the container registry, so deployments into shared / locked-down subscriptions do not need to create identities or role assignments. Fixes #12977 Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
0c6d923 to
1677a9a
Compare
Mitch Denny (mitchdenny)
left a comment
There was a problem hiding this comment.
Two findings beyond what's already on the PR. Both are doc/UX gaps, not bugs.
Co-authored-by: Copilot <[email protected]>
The existing managed environment already owns its Log Analytics workspace, so a user-supplied workspace would be silently discarded. Throw a clear InvalidOperationException at publish time instead, matching the existing guardrails for WithDelegatedSubnet and volume mounts. Co-authored-by: Copilot <[email protected]>
…dentity Co-authored-by: Copilot <[email protected]>
|
❓ CLI E2E Tests unknown — 95 passed, 0 failed, 5 unknown (commit View all recordings
📹 Recordings uploaded automatically from CI run #26258589439 |
|
✅ No documentation update needed. docs_optional → bug_fix_restores_documented_behavior (+ existing docs PR already covers the new API surface) No triggered signals (signal_count = 0; recommendation = Changed files (12 total): all under Why no new docs PR is needed:
Please review microsoft/aspire.dev#1045 (already requested: |
Description
AddAzureContainerAppEnvironment(...).AsExisting(...)already marked the resource as existing for the model, but the publish-timeconfigureInfrastructurecallback still produced a brand-new managed environment, Log Analytics workspace, Aspire Dashboard component, storage account, and user-assigned identity. The generated Bicep tried to create the environment the user said already existed, which is the bug reported in #12977.This PR makes the callback short-circuit when the environment is marked as existing and emit a thin module that only references the existing resources and produces the outputs the rest of the publish pipeline consumes (
AZURE_CONTAINER_APPS_ENVIRONMENT_NAME/_ID/_DEFAULT_DOMAINandAZURE_CONTAINER_REGISTRY_NAME/_ENDPOINT/_MANAGED_IDENTITY_ID). Volumes andWithDelegatedSubnetare explicitly rejected with a clear error when combined withAsExisting, since both require creating new infrastructure.A common deployment scenario for #12977 also wants to BYO the managed identity that holds
AcrPullon the container registry, so the deployment principal does not need permission to create new identities or role assignments. This PR adds a small follow-on API for that:When
WithAcrPullIdentityis set, Aspire skips creating its ownenv_miidentity and theAcrPullrole assignment, and wires the user's identity id through a Bicep parameter intoAZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID. The caller is responsible for ensuring the supplied identity already hasAcrPullon the registry. This works in both the greenfield andAsExistingpaths.Refactor note: the six shared registry + env outputs are now produced from a single
AddSharedContainerAppEnvironmentOutputshelper so the new-vs-existing branches stay in lockstep.Associated docs PR: microsoft/aspire.dev#1045
Fixes #12977
Fixes #9094
Checklist
<remarks />and<code />elements on your triple slash comments?