Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Can't customize Azure ProvisioningBuildOptions on AzureContainerApp resources #6496

@eerhardt

Description

@eerhardt

When users need to configure their bicep, one way to do it across all resources is to configure the AzureProvisioningOptions and tweak the ProvisioningBuildOptions to provide InfrastructureResolvers.

Configuring these options when using PublishAsAzureContainerApp isn't working because the following code isn't setting the ProvisioningBuildOptions on the AzureProvisioningResource.

var provisioningResource = new AzureProvisioningResource(resource.Name, context.BuildContainerApp);
provisioningResource.Annotations.Add(new ManifestPublishingCallbackAnnotation(provisioningResource.WriteToManifest));
return provisioningResource;

Repro Steps

Publish the manifest/bicep for the following:

var builder = DistributedApplication.CreateBuilder(args);

builder.Services.Configure<AzureProvisioningOptions>(options => options.ProvisioningBuildOptions.InfrastructureResolvers.Insert(0, new MyResourceNamePropertyResolver()));

builder.AddProject<Projects.AzureContainerApps_ApiService>("api")
       .WithExternalHttpEndpoints()
       .PublishAsAzureContainerApp((module, app) =>
       {
           // Scale to 0
           app.Template.Scale.MinReplicas = 0;
       });
builder.Build().Run();

public sealed class MyResourceNamePropertyResolver : DynamicResourceNamePropertyResolver
{
    public override void ResolveProperties(ProvisionableConstruct construct, ProvisioningBuildOptions options)
    {
        if (construct is ContainerApp app)
        {
            app.Name = "myContainerAppName";
        }

        base.ResolveProperties(construct, options);
    }
}

Expected results

The MyResourceNamePropertyResolver should have been used to give the api ContainerApp an Azure name of "myContainerAppName".

Actual results

The MyResourceNamePropertyResolver is not used and instead it gets:

resource api 'Microsoft.App/containerApps@2024-03-01' = {
  name: 'api'

Metadata

Metadata

Assignees

Labels

area-integrationsIssues pertaining to Aspire Integrations packagesazureIssues associated specifically with scenarios tied to using Azure

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions