This directory contains Terraform modules 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
- Terraform (1.5+)
- Docker
- Azure CLI + lstk CLI
- Python 3.12+
- PostgreSQL client (
psql) jq
brew install localstack/tap/lstk # or: npm install -g @localstack/lstkThe Terraform configuration provisions:
- Azure Resource Group.
- Azure Virtual Network with two subnets:
- app-subnet (delegated to
Microsoft.Web/serverFarmsfor the Web App's VNet integration) - pe-subnet (hosts the Private Endpoint to the flex 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 (AllowAllIPs,0.0.0.0–255.255.255.255) lets the deploy machine reach the server for the post-apply psql bootstrap. - PostgreSQL database
PlannerDB. - Azure App Service Plan.
- Azure Web App with regional VNet integration.
PG_HOST/PG_PORT/PG_DATABASEare written by Terraform;PG_USERandPG_PASSWORDare written bydeploy.shafter psql creates the application role. The app settingAPPLICATIONINSIGHTS_CONNECTION_STRINGholds the connection string of the Application Insights resource.
deploy.sh performs:
terraform init -upgradeterraform plan -out=tfplan(passingpg_admin_password)terraform apply -auto-approve tfplan- Reads outputs (
resource_group_name,web_app_name,postgres_server_name,postgres_fqdn,postgres_database_name). - Connects to the server as the admin via the public endpoint + firewall rule and creates the
testuserrole, grants schema rights, creates theactivitiestable, and seeds three rows. - Sets
PG_USER=testuser+PG_PASSWORD=<app-password>on the Web App viaaz webapp config appsettings set. - Zips the source under
../srcand deploys viaaz webapp deploy.
Override any of the variables in variables.tf by editing terraform.tfvars or passing -var to terraform plan. Notable PostgreSQL ones:
| Variable | Default | Description |
|---|---|---|
pg_admin_login |
pgadmin |
Server administrator login |
pg_admin_password |
P@ssw0rd1234! |
Server administrator password (sensitive) |
pg_version |
16 |
PostgreSQL major version |
pg_sku_name |
B_Standard_B1ms |
Compute SKU |
pg_storage_mb |
32768 |
Storage size in MB |
pg_backup_retention_days |
7 |
Backup retention |
pg_database_name |
PlannerDB |
Application database |
For non-dev deployments, set pg_admin_password via env var: PG_ADMIN_PASSWORD=... bash deploy.sh.
Once 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.