Accessing Subscription ID in deployed app? #11903
-
Hi, I'm deploying a Container App using aspire. I'm also deploying another app as a Container App Job. I'm able to start a new job from from my app using the SubscriptionId and the ResourceGroupName with hardcoded values that I inject into my app environment variables using .WithEnvironment() Is there a way to inject the SubscriptionId of my deploy context to my deployed app as an environment variable ? I know I can put it into appSettings.json and it will get into IConfiguration, but that's somewhat the same as hardcoding it, because if I were to deploy it to another subscription the value in appsettings would be out of synch. I tried reading it from the active .env file only to realize the file is only created after calling azd up and the like. Any help will be appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You can use an expression like this: builder.AddProject<Projects.Api>("api")
.PublishAsAzureContainerApp((infra, app) =>
{
// Add an environment variable to the container app that resolved the current subscription id
app.Template.Containers[0].Value.Env.Add(new ContainerAppEnvironmentVariable
{
Name = "SUBSCRIPTION_ID",
Value = BicepFunction.GetSubscription().Id
});
}); |
Beta Was this translation helpful? Give feedback.
You can use an expression like this: