Skip to content

Fix Azure Container Apps deployment failure with uppercase resource names #9752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 8, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 7, 2025

Problem

Adding project references with uppercase names (e.g., "WebFrontEnd") would work fine locally but cause deployment failures when publishing to Azure Container Apps:

Error: Invalid ContainerApp name 'WebFrontEnd'. A name must consist of lower case alphanumeric characters or '-', start with an alphabetic character, and end with an alphanumeric character and cannot have '--'. The length must not be more than 32 characters.

Root Cause

While the Container App's Name property was being set to lowercase, the Bicep resource identifier was still using the original uppercase name. Azure Container Apps require lowercase names, but the generated Bicep template contained uppercase identifiers, causing deployment failures.

Solution

Updated ContainerAppContext.cs to ensure both the Bicep resource identifier and container names are lowercase:

  1. Line 59: Fixed Bicep identifier creation to use lowercase name:

    var containerAppResource = new ContainerApp(Infrastructure.NormalizeBicepIdentifier(resource.Name.ToLowerInvariant()))
  2. Line 104: Fixed container name to use lowercase:

    containerAppContainer.Name = resource.Name.ToLowerInvariant();

Testing

  • Added comprehensive test ContainerAppWithUppercaseName_ShouldUseLowercaseInManifest
  • Verified that uppercase "WebFrontEnd" correctly becomes lowercase "webfrontend" in generated Bicep
  • All 46 Azure Container Apps tests pass with no regressions

Developer Experience

  • Developers can continue using any casing they prefer (e.g., "WebFrontEnd", "MyApi")
  • Names are automatically converted to comply with Azure Container Apps requirements
  • No breaking changes or additional warnings needed
  • Deployments now succeed reliably

This approach is consistent with existing Azure naming patterns throughout the codebase where automatic lowercase conversion is commonly used.

Fixes #4505.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Adding a project reference with an uppercase name breaks ACA publish Fix Azure Container Apps deployment failure with uppercase resource names Jun 7, 2025
@Copilot Copilot AI requested a review from davidfowl June 7, 2025 07:40
Copilot finished work on behalf of davidfowl June 7, 2025 07:40
@davidfowl
Copy link
Member

@copilot the container app name is being lowercased multiple times, we want to do it once. Also the host name calculated in ProcessEndpoints also uses the resource name (which maps to the container app name). Let's have a single property that represents the normalized container app name that will be used as the EndpointMapping host name and the name of the container app.

Also remove setting the container app name multiple times.

Address feedback from @davidfowl to eliminate multiple ToLowerInvariant() calls and create a single NormalizedContainerAppName property that is used consistently for both Bicep identifiers and endpoint mapping host names.

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 7, 2025

@copilot the container app name is being lowercased multiple times, we want to do it once. Also the host name calculated in ProcessEndpoints also uses the resource name (which maps to the container ap...

I've refactored the code to address your feedback. The changes include:

  1. Added a single NormalizedContainerAppName property that computes resource.Name.ToLowerInvariant() once
  2. Replaced all multiple calls to ToLowerInvariant() with this property
  3. Updated endpoint mappings to use the normalized name for host names
  4. Ensured consistent usage throughout the container app creation process

The normalized container app name is now used consistently for both the Bicep resource identifier and endpoint mapping host names as requested. Commit: 4cb15cf

Copilot finished work on behalf of davidfowl June 7, 2025 08:02
Copilot finished work on behalf of davidfowl June 7, 2025 08:21
Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copilot finished work on behalf of davidfowl June 7, 2025 09:25
@davidfowl davidfowl marked this pull request as ready for review June 7, 2025 17:29
@davidfowl davidfowl merged commit fe64638 into main Jun 8, 2025
495 of 498 checks passed
@davidfowl davidfowl deleted the copilot/fix-4505 branch June 8, 2025 08:06
@github-actions github-actions bot locked and limited conversation to collaborators Jul 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Error loading sessions

Retrying..

Successfully merging this pull request may close these issues.

Adding a project reference with an uppercase name breaks ACA publish
3 participants