ACA environment deployment fails: ACR registry name mismatch when using default resource naming
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
## Description
When deploying Azure Container Apps with `aspire deploy` using **default resource naming** (custom naming disabled), the `ContainerAppEnvironment` ARM template fails because it computes a different ACR registry name than what the `ContainerRegistry` step actually created.
## Steps to Reproduce
1. Configure an Aspire AppHost with an `AddAzureContainerRegistry` resource and a container app environment
2. Disable custom resource naming (use default Aspire naming)
3. Run `aspire deploy` to a target resource group
## Expected Behavior
The `ContainerAppEnvironment` ARM template should reference the ACR registry by the name created in the `ContainerRegistry` deployment step, or use the passed `billgrokkeracr_outputs_name` parameter.
## Actual Behavior
The ACR deployment step creates the registry with name:
```
take(format('billgrokkeracr{0}', uniqueString(resourceGroup().id)), 50)
```
Result: `billgrokkeracr7oorjc6g2okm2`
The ACA environment deployment step independently computes the ACR name as:
```
replace(format('acr-{0}', uniqueString(resourceGroup().id)), '-', '')
```
Result: `acr7oorjc6g2okm2`
The prefix differs (`billgrokkeracr` vs `acr`), causing a `ResourceNotFound` error.
## Error Output
```
Failed to provision billgrokker-aca-env: Deployment failed: Error code = ResourceNotFound,
Message = The Resource 'Microsoft.ContainerRegistry/registries/acr7oorjc6g2okm2'
under resource group 'xxx' was not found.
```
## Root Cause
In the generated `ContainerAppEnvironment` ARM template:
1. The parameter `billgrokkeracr_outputs_name` **is correctly passed** and contains the actual ACR name
2. However, the template **never uses this parameter** for the registry reference
3. Instead, it independently recomputes the name using `replace(format('acr-{0}', variables('resourceToken')), '-', '')` which produces a different name
4. This formula is used in the role assignment scope, the `AZURE_CONTAINER_REGISTRY_NAME` output, and the `AZURE_CONTAINER_REGISTRY_ENDPOINT` output
## Affected Code Points in Generated Template
The role assignment `scope` uses the wrong formula:
```json
"scope": "[resourceId('Microsoft.ContainerRegistry/registries', replace(format('acr-{0}', variables('resourceToken')), '-', ''))]"
```
Should use the passed parameter:
```json
"scope": "[resourceId('Microsoft.ContainerRegistry/registries', parameters('billgrokkeracr_outputs_name'))]"
```
Same issue in outputs `AZURE_CONTAINER_REGISTRY_NAME` and `AZURE_CONTAINER_REGISTRY_ENDPOINT`.
## Environment
- Aspire CLI: 13.3.0
- Target: Azure Container Apps
- Resource naming: Default (custom naming disabled)
Contributor guide
Assessment
This issue has not been assessed yet.