Azure / azure-dev

A developer CLI that reduces the time it takes for you to get started on Azure. The Azure Developer CLI (azd) provides a set of developer-friendly commands that map to key stages in your workflow - code, build, deploy, monitor, repeat.
https://aka.ms/azd
MIT License
369 stars 166 forks source link

Make it possible to use endpoints to containers, projects or dockerfiles in bicep parameters #3839

Closed davidfowl closed 2 weeks ago

davidfowl commented 2 weeks ago

Follow up from https://github.com/Azure/azure-dev/pull/3820

The main scenario here is a webhooks. External services that need to call your compute (e.g. Azure event grid, azure web pubsub etc)

var builder = DistributedApplication.CreateBuilder(args);

var p = builder.AddProject<Projects.WebApplication1>("webapplication1");

var az = builder.AddAzureStorage("storage")
                .WithParameter("z", () => p.GetEndpoint("http"))
                .RunAsEmulator().AddQueues("q1");

builder.Build().Run();

Results in

module storage 'storage/storage.module.bicep' = {
  name: 'storage'
  scope: rg
  params: {
    location: location
    principalId: resources.outputs.MANAGED_IDENTITY_PRINCIPAL_ID
    principalType: 'ServicePrincipal'
    z: 'http://webapplication1.internal.{{ .Env.AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN }
  }
}

Notice the go template syntax in the bicep. This should just use the bicep value instead of the go template (when in this context).

Instead we want:

module storage 'storage/storage.module.bicep' = {
  name: 'storage'
  scope: rg
  params: {
    location: location
    principalId: resources.outputs.MANAGED_IDENTITY_PRINCIPAL_ID
    principalType: 'ServicePrincipal'
    z: 'http://webapplication1.${resources.outputs.AZURE_CONTAINER_APPS_ENVIRONMENT_DEFAULT_DOMAIN}'
  }
}
ellismg commented 2 weeks ago

Going to be interesting to consider what happens if there's a reference to something like .targetPort, which we would need to compute eagerly instead of waiting until deploy.

I think that's the only value in our reference syntax that we support today that we may not know at bicep generation time.

davidfowl commented 2 weeks ago

Going to be interesting to consider what happens if there's a reference to something like .targetPort, which we would need to compute eagerly instead of waiting until deploy.

Fail in this case.

We also fail if you reference a bicep secret output as a parameter so there's prior art