-
Notifications
You must be signed in to change notification settings - Fork 604
Expose container app constants #8923
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
Comments
We made these private until further notice. What are you using it for? For now you can manually create a BicepOutputReference from it with right name. |
I feel that the fact that these variables may change over time supports exposing them - yes, if you change it, it breaks my code but it breaks it loud and ugly - the type of breaking change that is easy to address vs what I currently have - as you say manually creating it with the right name means if you change them, my code still breaks but I'm left wondering why. for reference - yes I have manually created the constants in my project - I'm using them for this: public static IResourceBuilder<AzureContainerRegistryResource> AddAzureContainerRegistry(this IDistributedApplicationBuilder builder, string name)
{
var registry = new AzureContainerRegistryResource(name, static infrastructure =>
{
var registryResource = (AzureContainerRegistryResource)infrastructure.AspireResource;
var containerRegistry = new ContainerRegistryService(registryResource.GetBicepIdentifier())
{
Sku = new() { Name = ContainerRegistrySkuName.Basic },
};
infrastructure.Add(containerRegistry);
infrastructure.Add(new ProvisioningOutput(AzureContainerConstants.AZURE_CONTAINER_REGISTRY_NAME, typeof(string))
{
Value = containerRegistry.Name
});
infrastructure.Add(new ProvisioningOutput(AzureContainerConstants.AZURE_CONTAINER_REGISTRY_ENDPOINT, typeof(string))
{
Value = containerRegistry.LoginServer
});
});
return builder.AddResource(registry);
}
public static IResourceBuilder<AzureContainerAppEnvironmentResource> WithReference(this IResourceBuilder<AzureContainerAppEnvironmentResource> builder, IResourceBuilder<AzureContainerRegistryResource> registryBuilder)
{
var managedIdentity = builder.GetOutput(AzureContainerConstants.AZURE_CONTAINER_REGISTRY_MANAGED_IDENTITY_ID);
var roleDefinitionId = BicepFunction.GetSubscriptionResourceId("Microsoft.Authorization/roleDefinitions", ContainerRegistryBuiltInRole.AcrPull.ToString());
registryBuilder.ConfigureInfrastructure(infrastructure =>
{
if (infrastructure.GetProvisionableResources().OfType<ContainerRegistryService>().FirstOrDefault() is { } containerRegistry)
{
var principalId = new ProvisioningParameter(AzureBicepResource.KnownParameters.PrincipalId, typeof(string));
infrastructure.Add(principalId);
var pullRa = containerRegistry.CreateRoleAssignment(ContainerRegistryBuiltInRole.AcrPull,
RoleManagementPrincipalType.ServicePrincipal, principalId, "test");
pullRa.Name = BicepFunction.CreateGuid(containerRegistry.Id, principalId, pullRa.RoleDefinitionId);
infrastructure.Add(pullRa);
}
}).WithParameter(AzureBicepResource.KnownParameters.PrincipalId, managedIdentity);
builder.ConfigureInfrastructure(infrastructure =>
{
if (infrastructure.GetProvisionableResources().OfType<ContainerRegistryService>().FirstOrDefault() is { } containerRegistry)
{
if (infrastructure.GetProvisionableResources().OfType<RoleAssignment>().FirstOrDefault(_ =>
{
return _.RoleDefinitionId.Value! == roleDefinitionId.Value!;
}) is { } roleAssignment)
{
infrastructure.Remove(roleAssignment);
}
infrastructure.Remove(containerRegistry);
}
var outputParameters = infrastructure.GetProvisionableResources().OfType<ProvisioningOutput>();
if (outputParameters.FirstOrDefault(_ => _.BicepIdentifier == AzureContainerConstants.AZURE_CONTAINER_REGISTRY_NAME) is { } registryName)
{
infrastructure.Remove(registryName);
}
if (outputParameters.FirstOrDefault(_ => _.BicepIdentifier == AzureContainerConstants.AZURE_CONTAINER_REGISTRY_ENDPOINT) is { } registryEndpoint)
{
infrastructure.Remove(registryEndpoint);
}
});
return builder;
} |
Can you explain what you’re trying to do and why? |
I'm decoupling my container registry from my container app environment because I want one registry but more than one environment (across multiple projects) |
I’d file an issue asking for that more directly |
Ok |
I believe @captainsafia has plans to support associating an existing acr with the ACA resource. Seems like it fits in well |
@FullStackChef TODO: rewrite issue to be more useful per suggestion |
#9005 tracks this. |
Background and Motivation
AddAzureContainerAppEnvironment outputs a number of provisioning parameters that can be referenced using their string names - these values can be useful within infrastructure provisioning; however it currently relies on using the string names.
Proposed API
Simply expos a constants object that includes the parameters exposed in AddAzureContainerAppEnvironment
Usage Examples
Alternative Designs
Risks
The text was updated successfully, but these errors were encountered: