azureazure-deploymentdotnet-aspireazure-azd

Specifying Ingress in .NET Aspire Deployment using azd


I have a Blazor web application and several API's that I'm orchestrating with Aspire and trying to deploy to Azure Container apps using Azure Developer CLI - azd (v1.14.0)

I'm following this Microsoft guide here

Which roughly equates to running: azd init, following prompts and subsequently azd up to deploy to Azure.

The azure.yaml file generated is relatively simple, same as in the guide:

name: AspireSample
services:
  app:
    language: dotnet
    project: .\AspireSample.AppHost\AspireSample.AppHost.csproj
    host: containerapp

All of this works fine. However, I was never prompted to pick a project that should be exposed to the internet. So every deployment I have to manually go into Azure and set the Ingress traffic to accept traffic from outside the container app environment:azure dashboard ingress screenshot

How can I configure this to set the ingress using azd?


Solution

  • Turns out, I had to configure this in the Aspire AppHost using WithExternalHttpEndpoints extension method. The resulting AppHost project looked like the following:

    using Aspire.Hosting;
    
    var builder = DistributedApplication.CreateBuilder(args);
    
    var api = builder.AddProject<Projects.Sustainability_Api>("sus-api");
    
    var msa = builder.AddProject<Projects.MicroserviceA_Api>("parts-api");
    var msb = builder.AddProject<Projects.MicroserviceB_Api>("persons-api");
    
    var gateway = builder.AddProject<Projects.ApiGateway>("microservicegateway")
        .WithReference(msa)
        .WithReference(msb);
    
    
    
    builder.AddProject<Projects.TeamPenske_Sustainability_Blazor_Server>("web-server")
        .WithExternalHttpEndpoints()
        .WithReference(gateway)
        .WithReference(api);
    
    
    
    builder.Build().Run();