Subchapter 14.11
references/recipes/azd/post-deployment.mdMarkdown4 KBView on GitHub
Execute critical post-deployment configuration after infrastructure provisioning completes.
⚠️ Run AFTER
azd uporazd provisioncompletes successfully
references/recipes/azd/8 filesPost-deployment steps are required when your deployment includes:
| Scenario | Required Actions |
|---|---|
| ASP.NET Core + Azure SQL + Managed Identity | Grant managed identity SQL access, apply EF migrations |
| App Service + Azure SQL + Entra auth | Grant App Service identity database permissions |
| Container Apps + SQL Database | Configure managed identity access, run migrations |
Complete workflow for apps using Entity Framework with Azure SQL Database.
azd up or azd provision completed successfullyGrant the App Service or Container App’s managed identity permissions on the SQL database.
See SQL Managed Identity Access for detailed SQL scripts and examples.
Quick Template:
# Get the app identity name from azd
eval $(azd env get-values)
APP_NAME=$SERVICE_API_NAME # or SERVICE_WEB_NAME
# Connect as Entra admin and grant permissions
# See sql-managed-identity.md for connection patternsPowerShell:
# Get the app identity name from azd
azd env get-values | ForEach-Object {
$name, $value = $_.Split('=', 2)
Set-Item "env:$name" $value
}
$AppName = $env:SERVICE_API_NAME # or SERVICE_WEB_NAME
# Connect as Entra admin and grant permissions
# See sql-managed-identity.md for connection patternsApply Entity Framework migrations to create database schema.
See EF Core Migrations for deployment patterns and troubleshooting.
Quick Options:
| Method | Command | Use When |
|---|---|---|
| azd hook | Add postprovision hook in azure.yaml | Automated deployments |
| Manual | dotnet ef database update | One-time or troubleshooting |
| SQL Script | dotnet ef migrations script --idempotent | Pre-generated scripts |
# Get app endpoint
ENDPOINT=$(azd env get-values | grep SERVICE_.*_URI | cut -d'=' -f2)
# Health check
curl -f "$ENDPOINT/health" || echo "Health check failed"
# Test database connectivity
curl -f "$ENDPOINT/api/test-db" || echo "Database connection failed"PowerShell:
# Get app endpoint
$Endpoint = azd env get-values | Select-String -Pattern 'SERVICE_.*_URI' |
Select-Object -First 1 | ForEach-Object { ($_ -split '=', 2)[1] }
# Health check
try { Invoke-WebRequest "$Endpoint/health" } catch { Write-Output "Health check failed" }
# Test database connectivity
try { Invoke-WebRequest "$Endpoint/api/test-db" } catch { Write-Output "Database connection failed" }Expected Result:
| Error | Cause | Solution |
|---|---|---|
Login failed for user '<token-identified principal>' | Managed identity not granted SQL access | Follow sql-managed-identity.md |
Cannot open database | Firewall rules block access | Check SQL firewall, ensure “Allow Azure services” enabled |
Invalid object name | Migrations not applied | Run EF migrations per ef-migrations.md |
No such table | Schema missing | Apply migrations or check connection string database name |
postprovision hook to azure.yaml for repeatable deploymentsdotnet ef migrations script --idempotent