Skip to content
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

Can't customize Azure ProvisioningBuildOptions on AzureContainerApp resources #6496

Closed
eerhardt opened this issue Oct 25, 2024 · 0 comments
Closed
Assignees
Labels
area-integrations Issues pertaining to Aspire Integrations packages azure Issues associated specifically with scenarios tied to using Azure
Milestone

Comments

@eerhardt
Copy link
Member

eerhardt commented Oct 25, 2024

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'
@eerhardt eerhardt added area-integrations Issues pertaining to Aspire Integrations packages azure Issues associated specifically with scenarios tied to using Azure labels Oct 25, 2024
@eerhardt eerhardt added this to the 9.0 milestone Oct 25, 2024
eerhardt added a commit to eerhardt/aspire that referenced this issue Oct 25, 2024
@eerhardt eerhardt self-assigned this Oct 25, 2024
eerhardt added a commit that referenced this issue Oct 26, 2024
* Update Azure.Provisioning to latest

Respond to latest renames getting the API ready for GA release.

Fix #6376

* Rename properties to match new type names.
* Use IsAccessKeyAuthenticationDisabled property
* Fix ContainerAppExtensions for new Azure.Provisioning version
* Simplify BicepValueFormattableString
* Simplify ReferenceExpression to BicepValue<string> logic
* Fix Azure Redis test for new property order
* Update playground bicep
* Fix issue in AspireV8ResourceNamePropertyResolver when resource name has a dash.

In .NET Aspire 8.x, when the Aspire resource name has dashes, we used those dashes in the Azure resource name. But we are incorrectly converting them to underscores.

Fix #6474

* Allow customizing Azure ContainerApp resources with ProvisioningBuildOptions.

Fix #6496

---------

Co-authored-by: Eric Erhardt <[email protected]>
Co-authored-by: Jose Perez Rodriguez <[email protected]>
@github-actions github-actions bot locked and limited conversation to collaborators Nov 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages azure Issues associated specifically with scenarios tied to using Azure
Projects
None yet
Development

No branches or pull requests

1 participant