-
Notifications
You must be signed in to change notification settings - Fork 744
Description
Reference article https://tomasherceg.com/blog/post/beware-of-dashes-in-connection-string-names-in-azure-app-service
App Service will remove any dashed from environment variable names. This means that if a resource's name contains dashes the client integrations won't be able to retrieve the related connection strings.
Repro:
App Host
var builder = DistributedApplication.CreateBuilder(args);
var appservice = builder.AddAzureAppServiceEnvironment("my-app-service");
var db1 = builder.AddAzurePostgresFlexibleServer("my-server")
.RunAsContainer()
.AddDatabase("my-db");
builder.AddProject<Projects.PostgresEndToEnd_ApiService>("api")
.WithExternalHttpEndpoints()
.WithReference(db1).WaitFor(db1);App:
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
builder.AddAzureNpgsqlDbContext<MyDb1Context>("my-db");The application, when deployed, will get these values and fail to connect.
"ConnectionStrings__mydb"
"APPSETTING_ConnectionStrings__mydb"
A mitigation is to resolve services with a fixed name: builder.AddAzureNpgsqlDbContext<MyDb1Context>("mydb");
Since there is no way to fix this without breaking all integrations we should fail during deployment of App Service apps if they try to add environment variables that will be changed. We may still provide a setting to allow these if this is not an issue, for instance it apps use other ways to connect like connection properties instead of connection strings (pending this PR is merged)