-
Notifications
You must be signed in to change notification settings - Fork 855
SQL Server deployment scripts fail when private endpoints are used (PublicNetworkAccess=Disabled) #14421
Description
Description
When AddPrivateEndpoint is used with an AzureSqlServerResource, the PublicNetworkAccess is set to Disabled. However, the AddRoleAssignments method in AzureSqlServerResource.cs uses an AzurePowerShellScript deployment script that connects to the SQL Server over the public FQDN to create database users:
$connectionString = "Server=tcp:${sqlServerFqdn},1433;Initial Catalog=${sqlDatabaseName};Authentication=Active Directory Default;"
Invoke-Sqlcmd -ConnectionString $connectionString -Query $sqlCmd
The Azure deployment script container runs outside the VNet, so when public network access is disabled, the TCP connection is blocked and the deployment fails with DeploymentFailed on the role assignment step.
Reproduction
var vnet = builder.AddAzureVirtualNetwork("vnet");
var acaSubnet = vnet.AddSubnet("aca-subnet", "10.0.0.0/23");
var peSubnet = vnet.AddSubnet("pe-subnet", "10.0.2.0/24");
builder.AddAzureContainerAppEnvironment("env")
.WithDelegatedSubnet(acaSubnet);
var sql = builder.AddAzureSqlServer("sql");
var db = sql.AddDatabase("db");
peSubnet.AddPrivateEndpoint(sql);
builder.AddProject<Projects.Web>("web")
.WithReference(db);Deploy with aspire deploy — the deployment fails at the provision-webfrontend-roles-sql step.
Root Cause
AzureSqlServerResource.AddRoleAssignments() (line 194-287) creates an AzurePowerShellScript that needs TCP access to the SQL Server. When private endpoints disable public access, the script container (which runs outside the VNet) cannot connect.
Suggested Fix
When private endpoints are present, the AzurePowerShellScript should be configured to run inside the VNet using the SubnetResourceIds property. Azure deployment scripts support VNet integration: https://learn.microsoft.com/azure/azure-resource-manager/bicep/deployment-script-vnet
Environment
- Aspire branch: main (PR Add VNet deployment E2E tests for Storage Blob, Key Vault, and SQL Server #14417)
- Consistently reproduces across multiple CI runs (runs 21847458646 and 21848932910)