Skip to content

Preserve unique suffixes in App Service site names - #18941

Draft
Bhupesh Cholake (RealBhupesh) wants to merge 2 commits into
microsoft:mainfrom
RealBhupesh:codex/app-service-name-uniqueness
Draft

Bhupesh Cholake (RealBhupesh) wants to merge 2 commits into
microsoft:mainfrom
RealBhupesh:codex/app-service-name-uniqueness

Conversation

@RealBhupesh

Copy link
Copy Markdown

Summary

  • truncate App Service resource-name prefixes before appending the resource-group uniqueness suffix
  • keep generated Bicep, service-discovery expressions, deployment summaries, and dashboard names consistent
  • add coverage for long resource names

Fixes #18750

Validation

  • dotnet build tests/Aspire.Hosting.Azure.Tests/Aspire.Hosting.Azure.Tests.csproj --no-restore
  • Focused test run was attempted, but the local bundled VSTest host is missing Microsoft.TestPlatform.CommunicationUtilities.

Copilot AI review requested due to automatic review settings July 30, 2026 13:17
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18941

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18941"

@github-actions github-actions Bot added the area-integrations Issues pertaining to Aspire Integrations packages label Jul 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates App Service naming to preserve resource-group suffixes after truncation.

Changes:

  • Truncates site-name prefixes before appending suffixes.
  • Aligns Bicep, service discovery, summaries, and dashboard naming.
  • Adds long-name regression coverage.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
AzureAppServiceTests.cs Tests long resource names.
AzureAppServiceWebSiteResource.cs Updates deployment-summary naming.
AzureAppServiceWebsiteContext.cs Updates generated site names.
AzureAppServiceEnvironmentUtility.cs Updates dashboard naming.
AzureAppServiceEnvironmentResource.cs Aligns service-discovery hostnames.
Comments suppressed due to low confidence (2)

src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteContext.cs:41

  • This changes every generated website-name expression, but the existing .verified.bicep snapshots still expect take('${toLower(name)}-${uniqueString(...) }', 60). Snapshot-backed tests such as AddAppServiceWithDeploymentSlot and the delegated-subnet cases will therefore fail until their verified artifacts are regenerated and reviewed.
    private BicepValue<string> HostName => BicepFunction.Interpolate(
        $"{BicepFunction.Take(BicepFunction.ToLower(resource.Name), AzureAppServiceWebSiteResource.MaxWebSiteNamePrefixLength)}-{AzureAppServiceEnvironmentResource.GetWebSiteSuffixBicep()}");

src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentUtility.cs:22

  • The dashboard Bicep expression has changed shape, but all existing dashboard .verified.bicep snapshots still contain the old outer take(..., 60) expression. Every snapshot test that provisions the App Service dashboard will fail until those verified artifacts are regenerated and reviewed.
        var dashboardPrefix = BicepFunction.Interpolate($"{BicepFunction.ToLower(aspireResourceName)}-{BicepFunction.ToLower(ResourceName)}");
        return BicepFunction.Interpolate(
            $"{BicepFunction.Take(dashboardPrefix, AzureAppServiceWebSiteResource.MaxWebSiteNamePrefixLength)}-{BicepFunction.GetUniqueString(BicepFunction.GetResourceGroup().Id)}");

Comment on lines +40 to +41
private BicepValue<string> HostName => BicepFunction.Interpolate(
$"{BicepFunction.Take(BicepFunction.ToLower(resource.Name), AzureAppServiceWebSiteResource.MaxWebSiteNamePrefixLength)}-{AzureAppServiceEnvironmentResource.GetWebSiteSuffixBicep()}");
Comment on lines +20 to +22
var dashboardPrefix = BicepFunction.Interpolate($"{BicepFunction.ToLower(aspireResourceName)}-{BicepFunction.ToLower(ResourceName)}");
return BicepFunction.Interpolate(
$"{BicepFunction.Take(dashboardPrefix, AzureAppServiceWebSiteResource.MaxWebSiteNamePrefixLength)}-{BicepFunction.GetUniqueString(BicepFunction.GetResourceGroup().Id)}");
Comment on lines +1128 to +1131
[Fact]
public async Task AppServiceWebsiteName_PreservesUniqueSuffixForLongResourceNames()
{
const string resourceName = "project-with-a-name-longer-than-forty-six-characters";
Copilot AI review requested due to automatic review settings July 30, 2026 13:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 41 out of 41 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (5)

src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteContext.cs:54

  • GetSlotHostName now assumes the parent site was named take(resourceName, 26)-uniqueSuffix, but BuildWebSite still creates that parent with HostName (take(resourceName, 46)-uniqueSuffix, up to 60 characters). App Service derives the slot host from the parent site name, and the existing deployment-summary helper models that as take(parentName, 40)-slot. For resource names over 26 characters this expression therefore points service discovery at a host different from the deployed slot, while the deployed host still loses the suffix. Make the parent site's physical name slot-aware (at most 40 characters with the suffix retained) and use that same value for outputs and summaries.
        var websitePrefix = BicepFunction.Interpolate(
            $"{BicepFunction.Take(BicepFunction.ToLower(resource.Name), AzureAppServiceWebSiteResource.MaxWebSiteNamePrefixLengthWithSlotUniqueSuffix)}-{AzureAppServiceEnvironmentResource.GetWebSiteSuffixBicep(resource.Name)}");

        return BicepFunction.Take(
            BicepFunction.Interpolate($"{websitePrefix}-{BicepFunction.ToLower(deploymentSlot)}"), AzureAppServiceWebSiteResource.MaxHostPrefixLengthWithSlot);

src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentResource.cs:512

  • This introduces lifecycle ordering into GetHostAddressExpression: the deployment target annotation is only installed by the before-start hook, so callers that request the compute-environment expression while constructing or inspecting the model now throw. The previous implementation returned a deferred expression immediately, and the updated test now has to build the app and run hooks to avoid this failure. Keep this API usable before lifecycle hooks, rather than requiring an annotation that does not yet exist.
        var deploymentTarget = resource.GetDeploymentTargetAnnotation(this)?.DeploymentTarget;
        if (deploymentTarget is not AzureAppServiceWebSiteResource website)
        {
            throw new InvalidOperationException($"Resource '{resource.Name}' does not have an Azure App Service deployment target.");

src/Aspire.Hosting.Azure.AppService/AzureAppServiceEnvironmentExtensions.cs:199

  • Removing this output changes every generated environment module, but three tracked Verify snapshots still expect output webSiteSuffix: AzureAppServiceTests.AddAppServiceToEnvironmentWithoutAutoScale, AzureAppServiceTests.AddAppServiceToEnvironmentWithAutomaticScaling, and AzureAppServiceEnvironmentExtensionsTests.CrossResourceGroupRegistry_UsesStandaloneAcrPullIdentityForFinalRegistry. Those snapshot tests will fail until their .verified.bicep files are regenerated (including the dashboard-name changes in the first two).
            infra.Add(new ProvisioningOutput("AZURE_CONTAINER_REGISTRY_NAME", typeof(string))

src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebSiteResource.cs:115

  • The deploy pipeline tests are still wired to the removed environment-level webSiteSuffix output and do not return the new per-website name output. In AzureDeployerTests.DeployAsync_WithAppServiceExternalEndpoint_IncludesPortalLinksInSummary, the fake returns [] for the api-website deployment, so this lookup resolves no name and the generated summary cannot match the asserted api-website123 URL. Update the deployment fakes/assertions (and the multiple-compute-environments fake) to provide and consume each website's name output.
    private async Task<string> GetAppServiceWebsiteBaseNameAsync(PipelineStepContext context)
    {
        return (await NameOutputReference.GetValueAsync(context.CancellationToken).ConfigureAwait(false))!;

src/Aspire.Hosting.Azure.AppService/AzureAppServiceWebsiteContext.cs:41

  • The AddAppServiceWithoutTargetPortUsesDefaultPort Verify snapshot was not regenerated for this naming change; it still expects name: take('${toLower('project1')}-${uniqueString(resourceGroup().id)}', 60) and has no website name output. That test will fail against the new generated Bicep.

This issue also appears on line 50 of the same file.

    private BicepValue<string> HostName => BicepFunction.Interpolate(
        $"{BicepFunction.Take(BicepFunction.ToLower(resource.Name), AzureAppServiceWebSiteResource.MaxWebSiteNamePrefixLength)}-{AzureAppServiceEnvironmentResource.GetWebSiteSuffixBicep(resource.Name)}");

Comment on lines +449 to +450
internal static BicepValue<string> GetWebSiteSuffixBicep(string resourceName) =>
BicepFunction.GetUniqueString(BicepFunction.ToLower(resourceName), BicepFunction.GetResourceGroup().Id);

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-integrations Issues pertaining to Aspire Integrations packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App Service site name truncation (take(name-uniqueString, 60)) can weaken uniqueness for long resource names

2 participants