Skip to content

Commit c8522bc

Browse files
davidfowleerhardt
andauthored
Drop support for hybrid mode Azure Container Apps (#9500)
* Drop support for hybrid mode Azure Container Apps - Initially, azd generated the azure container app environment, but now that we've moved the logic to Aspire.Hosting.Azure.AppContainers, we can drop this hybrid mode. - PublishAsAzureContainerApps no longer lights up the infrastructure, it just adds customization annotations. - This change also removed support for BicepSecretOutput in the azure container apps logic (this simplifies things significantly) - Obsoleted BicepSecretOutput APIs - Updated tests * Update src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBResource.cs Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> * Update AzureContainerAppsInfrastructure.cs * Update src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppsInfrastructure.cs --------- Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
1 parent 6c26138 commit c8522bc

21 files changed

+128
-237
lines changed

src/Aspire.Hosting.Azure.AppContainers/AzdAzureContainerAppEnvironment.cs

Lines changed: 0 additions & 89 deletions
This file was deleted.

src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppContainerExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public static IResourceBuilder<T> PublishAsAzureContainerApp<T>(this IResourceBu
4242
return container;
4343
}
4444

45-
container.ApplicationBuilder.AddAzureContainerAppsInfrastructureCore();
46-
4745
container.WithAnnotation(new AzureContainerAppCustomizationAnnotation(configure));
4846

4947
return container;

src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppEnvironmentResource.cs

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,50 +12,50 @@ namespace Aspire.Hosting.Azure.AppContainers;
1212
/// <param name="configureInfrastructure">The callback to configure the Azure infrastructure for this resource.</param>
1313
public class AzureContainerAppEnvironmentResource(string name, Action<AzureResourceInfrastructure> configureInfrastructure) :
1414
#pragma warning disable ASPIRECOMPUTE001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
15-
AzureProvisioningResource(name, configureInfrastructure), IComputeEnvironmentResource, IAzureContainerAppEnvironment, IAzureContainerRegistry
15+
AzureProvisioningResource(name, configureInfrastructure), IComputeEnvironmentResource, IAzureContainerRegistry
1616
#pragma warning restore ASPIRECOMPUTE001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
1717
{
1818
internal bool UseAzdNamingConvention { get; set; }
1919

2020
/// <summary>
2121
/// Gets the unique identifier of the Container App Environment.
2222
/// </summary>
23-
private BicepOutputReference ContainerAppEnvironmentId => new("AZURE_CONTAINER_APPS_ENVIRONMENT_ID", this);
23+
internal BicepOutputReference ContainerAppEnvironmentId => new("AZURE_CONTAINER_APPS_ENVIRONMENT_ID", this);
2424

2525
/// <summary>
2626
/// Gets the default domain associated with the Container App Environment.
2727
/// </summary>
28-
private BicepOutputReference ContainerAppDomain => new("AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN", this);
28+
internal BicepOutputReference ContainerAppDomain => new("AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN", this);
2929

3030
/// <summary>
3131
/// Gets the URL endpoint of the associated Azure Container Registry.
3232
/// </summary>
33-
private BicepOutputReference ContainerRegistryUrl => new("AZURE_CONTAINER_REGISTRY_ENDPOINT", this);
33+
internal BicepOutputReference ContainerRegistryUrl => new("AZURE_CONTAINER_REGISTRY_ENDPOINT", this);
3434

3535
/// <summary>
3636
/// Gets the managed identity ID associated with the Azure Container Registry.
3737
/// </summary>
38-
private BicepOutputReference ContainerRegistryManagedIdentityId => new("AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID", this);
38+
internal BicepOutputReference ContainerRegistryManagedIdentityId => new("AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID", this);
3939

4040
/// <summary>
4141
/// Gets the unique identifier of the Log Analytics workspace.
4242
/// </summary>
43-
private BicepOutputReference LogAnalyticsWorkspaceId => new("AZURE_LOG_ANALYTICS_WORKSPACE_ID", this);
43+
internal BicepOutputReference LogAnalyticsWorkspaceId => new("AZURE_LOG_ANALYTICS_WORKSPACE_ID", this);
4444

4545
/// <summary>
4646
/// Gets the principal name of the managed identity.
4747
/// </summary>
48-
private BicepOutputReference PrincipalName => new("MANAGED_IDENTITY_NAME", this);
48+
internal BicepOutputReference PrincipalName => new("MANAGED_IDENTITY_NAME", this);
4949

5050
/// <summary>
5151
/// Gets the principal ID of the managed identity.
5252
/// </summary>
53-
private BicepOutputReference PrincipalId => new("MANAGED_IDENTITY_PRINCIPAL_ID", this);
53+
internal BicepOutputReference PrincipalId => new("MANAGED_IDENTITY_PRINCIPAL_ID", this);
5454

5555
/// <summary>
5656
/// Gets the name of the Container App Environment.
5757
/// </summary>
58-
private BicepOutputReference ContainerAppEnvironmentName => new("AZURE_CONTAINER_APPS_ENVIRONMENT_NAME", this);
58+
internal BicepOutputReference ContainerAppEnvironmentName => new("AZURE_CONTAINER_APPS_ENVIRONMENT_NAME", this);
5959

6060
/// <summary>
6161
/// Gets the container registry name.
@@ -64,35 +64,14 @@ public class AzureContainerAppEnvironmentResource(string name, Action<AzureResou
6464

6565
internal Dictionary<string, (IResource resource, ContainerMountAnnotation volume, int index, BicepOutputReference outputReference)> VolumeNames { get; } = [];
6666

67-
IManifestExpressionProvider IAzureContainerAppEnvironment.ContainerAppEnvironmentId => ContainerAppEnvironmentId;
68-
69-
IManifestExpressionProvider IAzureContainerAppEnvironment.ContainerAppDomain => ContainerAppDomain;
70-
71-
IManifestExpressionProvider IAzureContainerAppEnvironment.ContainerRegistryUrl => ContainerRegistryUrl;
72-
73-
IManifestExpressionProvider IAzureContainerAppEnvironment.ContainerRegistryManagedIdentityId => ContainerRegistryManagedIdentityId;
74-
75-
IManifestExpressionProvider IAzureContainerAppEnvironment.LogAnalyticsWorkspaceId => LogAnalyticsWorkspaceId;
76-
77-
IManifestExpressionProvider IAzureContainerAppEnvironment.PrincipalId => PrincipalId;
78-
79-
IManifestExpressionProvider IAzureContainerAppEnvironment.PrincipalName => PrincipalName;
80-
81-
IManifestExpressionProvider IAzureContainerAppEnvironment.ContainerAppEnvironmentName => ContainerAppEnvironmentName;
82-
8367
// Implement IAzureContainerRegistry interface
8468
ReferenceExpression IContainerRegistry.Name => ReferenceExpression.Create($"{ContainerRegistryName}");
8569

8670
ReferenceExpression IContainerRegistry.Endpoint => ReferenceExpression.Create($"{ContainerRegistryUrl}");
8771

8872
ReferenceExpression IAzureContainerRegistry.ManagedIdentityId => ReferenceExpression.Create($"{ContainerRegistryManagedIdentityId}");
8973

90-
IManifestExpressionProvider IAzureContainerAppEnvironment.GetSecretOutputKeyVault(AzureBicepResource resource)
91-
{
92-
throw new NotSupportedException("Automatic Key vault generation is not supported in this environment. Please create a key vault resource directly.");
93-
}
94-
95-
IManifestExpressionProvider IAzureContainerAppEnvironment.GetVolumeStorage(IResource resource, ContainerMountAnnotation volume, int volumeIndex)
74+
internal BicepOutputReference GetVolumeStorage(IResource resource, ContainerMountAnnotation volume, int volumeIndex)
9675
{
9776
var prefix = volume.Type switch
9877
{

src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExecutableExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public static IResourceBuilder<T> PublishAsAzureContainerApp<T>(this IResourceBu
4242
return executable;
4343
}
4444

45-
executable.ApplicationBuilder.AddAzureContainerAppsInfrastructureCore();
46-
4745
return executable.WithAnnotation(new AzureContainerAppCustomizationAnnotation(configure));
4846
}
4947
}

src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static class AzureContainerAppExtensions
3131
public static IDistributedApplicationBuilder AddAzureContainerAppsInfrastructure(this IDistributedApplicationBuilder builder) =>
3232
AddAzureContainerAppsInfrastructureCore(builder);
3333

34-
internal static IDistributedApplicationBuilder AddAzureContainerAppsInfrastructureCore(this IDistributedApplicationBuilder builder)
34+
private static IDistributedApplicationBuilder AddAzureContainerAppsInfrastructureCore(this IDistributedApplicationBuilder builder)
3535
{
3636
ArgumentNullException.ThrowIfNull(builder);
3737

src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppProjectExtensions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ public static IResourceBuilder<T> PublishAsAzureContainerApp<T>(this IResourceBu
4242
return project;
4343
}
4444

45-
project.ApplicationBuilder.AddAzureContainerAppsInfrastructureCore();
46-
4745
project.WithAnnotation(new AzureContainerAppCustomizationAnnotation(configure));
4846

4947
return project;

src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppsInfrastructure.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ public async Task BeforeStartAsync(DistributedApplicationModel appModel, Cancell
3838
throw new NotSupportedException("Multiple container app environments are not supported.");
3939
}
4040

41-
var environment = caes.FirstOrDefault() as IAzureContainerAppEnvironment ?? new AzdAzureContainerAppEnvironment();
41+
var environment = caes.FirstOrDefault();
42+
43+
if (environment is null)
44+
{
45+
return;
46+
}
4247

4348
var containerAppEnvironmentContext = new ContainerAppEnvironmentContext(
4449
logger,
@@ -64,8 +69,8 @@ public async Task BeforeStartAsync(DistributedApplicationModel appModel, Cancell
6469
// associated with each compute resource that needs an image
6570
r.Annotations.Add(new DeploymentTargetAnnotation(containerApp)
6671
{
67-
ContainerRegistry = caes.FirstOrDefault(),
68-
ComputeEnvironment = environment as IComputeEnvironmentResource // will be null if azd
72+
ContainerRegistry = environment,
73+
ComputeEnvironment = environment
6974
});
7075
}
7176

@@ -79,12 +84,6 @@ static void SetKnownParameterValue(AzureBicepResource r, string key, Func<AzureB
7984
}
8085
}
8186

82-
if (environment is AzdAzureContainerAppEnvironment)
83-
{
84-
// We avoid setting known values if azd is used, it will be resolved by azd at publish time.
85-
return;
86-
}
87-
8887
// Resolve the known parameters for the container app environment
8988
foreach (var r in appModel.Resources.OfType<AzureBicepResource>())
9089
{
@@ -93,7 +92,7 @@ static void SetKnownParameterValue(AzureBicepResource r, string key, Func<AzureB
9392

9493
// This will throw an exception if there's no value specified, in this new mode, we don't no longer support
9594
// automagic secret key vault references.
96-
SetKnownParameterValue(r, AzureBicepResource.KnownParameters.KeyVaultName, environment.GetSecretOutputKeyVault);
95+
SetKnownParameterValue(r, AzureBicepResource.KnownParameters.KeyVaultName, _ => throw new NotSupportedException("Automatic Key vault generation is not supported in this environment. Please create a key vault resource directly."));
9796

9897
// Set the known parameters for the container app environment
9998
SetKnownParameterValue(r, AzureBicepResource.KnownParameters.PrincipalId, _ => environment.PrincipalId);

src/Aspire.Hosting.Azure.AppContainers/ContainerAppContext.cs

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using Azure.Provisioning;
77
using Azure.Provisioning.AppContainers;
88
using Azure.Provisioning.Expressions;
9-
using Azure.Provisioning.KeyVault;
109
using Azure.Provisioning.Resources;
1110
using Microsoft.Extensions.Logging;
1211

@@ -29,13 +28,12 @@ record struct EndpointMapping(string Scheme, string Host, int Port, int? TargetP
2928
// bicep compatible values
3029
public Dictionary<string, object> EnvironmentVariables { get; } = [];
3130
public List<object> Args { get; } = [];
32-
public Dictionary<string, (ContainerMountAnnotation, IManifestExpressionProvider)> Volumes { get; } = [];
31+
public Dictionary<string, (ContainerMountAnnotation, BicepOutputReference)> Volumes { get; } = [];
3332

3433
// Bicep build state
3534
private ProvisioningParameter? _containerRegistryUrlParameter;
3635
private ProvisioningParameter? _containerRegistryManagedIdentityIdParameter;
37-
public Dictionary<string, KeyVaultService> KeyVaultRefs { get; } = [];
38-
public Dictionary<string, KeyVaultSecret> KeyVaultSecretRefs { get; } = [];
36+
3937
private AzureResourceInfrastructure? _infrastructure;
4038
public AzureResourceInfrastructure Infra => _infrastructure ?? throw new InvalidOperationException("Infra is not set");
4139

@@ -113,17 +111,6 @@ public void BuildContainerApp(AzureResourceInfrastructure infra)
113111
AddAzureClientId(appIdentityAnnotation?.IdentityResource, containerAppContainer);
114112
AddVolumes(template, containerAppContainer);
115113

116-
// Keyvault
117-
foreach (var (_, v) in KeyVaultRefs)
118-
{
119-
infra.Add(v);
120-
}
121-
122-
foreach (var (_, v) in KeyVaultSecretRefs)
123-
{
124-
infra.Add(v);
125-
}
126-
127114
infra.Add(containerAppResource);
128115

129116
if (resource.TryGetAnnotationsOfType<AzureContainerAppCustomizationAnnotation>(out var annotations))
@@ -535,15 +522,12 @@ BicepValue<string> GetHostValue(string? prefix = null, string? suffix = null)
535522
return (AllocateParameter(output, secretType: secretType), secretType);
536523
}
537524

538-
if (value is BicepSecretOutputReference secretOutputReference)
525+
#pragma warning disable CS0618 // Type or member is obsolete
526+
if (value is BicepSecretOutputReference)
539527
{
540-
if (parent is null)
541-
{
542-
return (AllocateKeyVaultSecretUriReference(secretOutputReference), SecretType.KeyVault);
543-
}
544-
545-
return (AllocateParameter(secretOutputReference, secretType: SecretType.KeyVault), SecretType.KeyVault);
528+
throw new NotSupportedException("Automatic Key vault generation is not supported in this environment. Please create a key vault resource directly.");
546529
}
530+
#pragma warning restore CS0618 // Type or member is obsolete
547531

548532
if (value is IAzureKeyVaultSecretReference vaultSecretReference)
549533
{
@@ -599,32 +583,6 @@ BicepValue<string> GetHostValue(string? prefix = null, string? suffix = null)
599583
throw new NotSupportedException("Unsupported value type " + value.GetType());
600584
}
601585

602-
private BicepValue<string> AllocateKeyVaultSecretUriReference(BicepSecretOutputReference secretOutputReference)
603-
{
604-
if (!KeyVaultRefs.TryGetValue(secretOutputReference.Resource.Name, out var kv))
605-
{
606-
// We resolve the keyvault that represents the storage for secret outputs
607-
var parameter = AllocateParameter(_containerAppEnvironmentContext.Environment.GetSecretOutputKeyVault(secretOutputReference.Resource));
608-
kv = KeyVaultService.FromExisting($"{parameter.BicepIdentifier}_kv");
609-
kv.Name = parameter;
610-
611-
KeyVaultRefs[secretOutputReference.Resource.Name] = kv;
612-
}
613-
614-
if (!KeyVaultSecretRefs.TryGetValue(secretOutputReference.ValueExpression, out var secret))
615-
{
616-
// Now we resolve the secret
617-
var secretBicepIdentifier = Infrastructure.NormalizeBicepIdentifier($"{kv.BicepIdentifier}_{secretOutputReference.Name}");
618-
secret = KeyVaultSecret.FromExisting(secretBicepIdentifier);
619-
secret.Name = secretOutputReference.Name;
620-
secret.Parent = kv;
621-
622-
KeyVaultSecretRefs[secretOutputReference.ValueExpression] = secret;
623-
}
624-
625-
return secret.Properties.SecretUri;
626-
}
627-
628586
private BicepValue<string> AllocateKeyVaultSecretUriReference(IAzureKeyVaultSecretReference secretOutputReference)
629587
{
630588
var secret = secretOutputReference.AsKeyVaultSecret(Infra);

0 commit comments

Comments
 (0)