This directory contains the Bicep template and a deployment script for provisioning the sample's Azure resources. For details about the sample application, see Azure Web App with Azure Database for PostgreSQL flexible server.
- LocalStack for Azure
- Visual Studio Code + Bicep extension
- Docker
- Azure CLI + lstk CLI
- Python 3.12+
- PostgreSQL client (
psql) jq
brew install localstack/tap/lstk # or: npm install -g @localstack/lstkThe deploy.sh script creates the resource group while the Bicep modules create:
- Azure Virtual Network with two subnets:
- app-subnet: delegated to
Microsoft.Web/serverFarmsfor the Web App's regional VNet integration. - pe-subnet: hosts the Private Endpoint to the PostgreSQL flexible server.
- app-subnet: delegated to
- Azure Private DNS Zone
privatelink.postgres.database.azure.com, linked to the VNet. - Azure Private Endpoint (group
postgresqlServer). - Azure NAT Gateway.
- Network Security Groups: one per subnet.
- Azure Log Analytics Workspace, with a diagnostic setting that sends the audit records of the queries run on the workspace to the workspace itself.
- Azure Application Insights: workspace-based, it stores the telemetry of the web app in the Log Analytics workspace.
- Azure Database for PostgreSQL flexible server: public-access mode, Burstable
Standard_B1ms, version 16, 32 GiB, HA disabled. A permissive firewall rule (0.0.0.0–255.255.255.255) lets the deploy machine reach the server for the post-create psql bootstrap. - PostgreSQL database
PlannerDB(UTF8 /en_US.utf8). - Azure App Service Plan.
- Azure Web App with regional VNet integration into app-subnet. The Bicep template sets
PG_HOST,PG_PORT, andPG_DATABASEon the Web App but does not setPG_USERorPG_PASSWORD— those are written bydeploy.shafter psql creates the application role. The app settingAPPLICATIONINSIGHTS_CONNECTION_STRINGholds the connection string of the Application Insights resource.
Update main.bicepparam before deploying. The defaults are:
using 'main.bicep'
param prefix = 'local'
param suffix = 'test'
param runtimeName = 'python'
param runtimeVersion = '3.13'
param databaseName = 'PlannerDB'
param username = 'paolo'
param pgAdminLogin = 'pgadmin'
param pgAdminPassword = readEnvironmentVariable('PG_ADMIN_PASSWORD', '')
param pgVersion = '16'
param pgSkuTier = 'Burstable'
param pgSkuName = 'Standard_B1ms'
param pgStorageSizeGB = 32
param pgBackupRetentionDays = 7pgAdminPassword is read from the PG_ADMIN_PASSWORD env var. deploy.sh sets a default (P@ssw0rd1234!) if not provided; override for non-dev deployments.
# default values
bash deploy.sh
# override admin and app-user secrets
PG_ADMIN_PASSWORD='<your-admin-password>' \
PG_APP_PASSWORD='<your-app-password>' \
bash deploy.shThe script will:
- Ensure the resource group exists.
- Validate
main.bicep. - Deploy the template, passing
pgAdminPassword. - Use
psql(connected via the public endpoint + firewall rule) to create thetestuserrole, theactivitiestable, and the three demo rows. - Set the Web App's
PG_USER/PG_PASSWORDtotestuser/<app-password>— the server admin login is never written to the Web App. - Zip the application source under
../srcand deploy it.
PGPASSWORD='TestP@ssw0rd123' psql -h <fqdn> -p <port> -U testuser -d PlannerDB \
-c "SELECT id, username, activity, created_at FROM activities;"<port> is 5432 in real Azure, or the port suffix of the server's FQDN in LocalStack:
az postgres flexible-server show \
--resource-group local-rg --name local-pgflex-test \
--query fullyQualifiedDomainName --output tsvOnce the web app is deployed, read the telemetry it sent to Application Insights and the logs and metrics the diagnostic settings sent to the workspace. The scripts take the same PREFIX and SUFFIX as the deployment:
bash ../scripts/query-telemetry.sh
bash ../scripts/query-logs-and-metrics.shSee Application Insights and Logs and metrics for what they read.