This directory contains the Bicep template and a deployment script for provisioning Azure services in LocalStack for Azure. Refer to the Azure Web App with Managed Identity guide for details about the sample application.
Before deploying this solution, ensure you have the following tools installed:
- LocalStack for Azure: Local Azure cloud emulator for development and testing
- Visual Studio Code: Code editor installed on one of the supported platforms
- Bicep extension: VS Code extension for Bicep language support and IntelliSense
- Docker: Container runtime required for LocalStack
- Azure CLI: Azure command-line interface
- azlocal CLI: LocalStack Azure CLI wrapper
- Python: Python runtime (version 3.12 or above)
- jq: JSON processor for scripting and parsing command outputs
The deploy.sh Bash script uses the azlocal CLI instead of the standard Azure CLI to work with LocalStack. Install it using:
pip install azlocalFor more information, see Get started with the az tool on LocalStack.
The deploy.sh script creates the Azure Resource Group for all the Azure resources, while the main.bicep Bicep module creates the following Azure resources:
- Azure Storage Account: Provides blob storage for persisting vacation activity data. The web application stores each activity as a JSON blob file in the
activitiescontainer. - Azure App Service Plan: Defines the compute resources (CPU, memory, and scaling options) that host the web application.
- Azure Web App: Hosts the Python Flask-based Vacation Planner application. The web app uses managed identity to securely access the Azure Storage Account without requiring explicit credentials.
- Managed Identity: Provides secure, credential-free authentication between the web app and storage account. Supports both system-assigned and user-assigned identity types.
- Role Assignment: Grants the web app's managed identity the Storage Blob Data Contributor role, enabling read/write access to blob containers.
- App Service Source Control: (Optional) Enables continuous deployment from a Git repository for automated application updates.
The web app allows users to plan and manage vacation activities, storing all activity data as blob files in the activities containers in the Azure Storage Account. For more information, see Azure Web App with Managed Identity.
See deploy.sh for the complete deployment script. The script performs the following operations:
- Detects environment (LocalStack or Azure Cloud) and selects appropriate CLI
- Creates resource group if it doesn't exist
- Validates Bicep template syntax and parameters
- Optionally runs what-if deployment for preview
- Deploys Bicep template to create all Azure resources
- Extracts deployment outputs (resource names, URLs) using jq
- Packages web application code into zip file
- Deploys zip package to Azure Web App
- Cleans up temporary artifacts
You can set up the Azure emulator by utilizing LocalStack for Azure Docker image. Before starting, ensure you have a valid LOCALSTACK_AUTH_TOKEN to access the Azure emulator. Refer to the Auth Token guide to obtain your Auth Token and specify it in the LOCALSTACK_AUTH_TOKEN environment variable. The Azure Docker image is available on the LocalStack Docker Hub. To pull the Azure Docker image, execute the following command:
docker pull localstack/localstack-azure-alphaStart the LocalStack Azure emulator using the localstack CLI, execute the following command:
export LOCALSTACK_AUTH_TOKEN=<your_auth_token>
IMAGE_NAME=localstack/localstack-azure-alpha localstack startNavigate to the bicep folder:
cd samples/web-app-managed-identity/python/bicepMake the script executable:
chmod +x deploy.shRun the deployment script:
./deploy.shAfter deployment, you can use the validate.sh script to verify that all resources were created and configured correctly:
#!/bin/bash
# Variables
ENVIRONMENT=$(az account show --query environmentName --output tsv)
# Choose the appropriate CLI based on the environment
if [[ $ENVIRONMENT == "LocalStack" ]]; then
echo "Using azlocal for LocalStack emulator environment."
AZ="azlocal"
else
echo "Using standard az for AzureCloud environment."
AZ="az"
fi
# Check resource group
$AZ group show \
--name local-rg \
--output table
# List resources
$AZ resource list \
--resource-group local-rg \
--output table
# Check Azure Web App
$AZ webapp show \
--name local-webapp-test \
--resource-group local-rg \
--output table
# Check storage account properties
$AZ storage account show \
--name localstoragetest \
--resource-group local-rg \
--output table
# List storage containers
$AZ storage container list \
--account-name localstoragetest \
--output table \
--only-show-errorsTo destroy all created resources:
# Delete resource group and all contained resources
az group delete --name local-rg --yes --no-wait
# Verify deletion
az group list --output tableThis will remove all Azure resources created by the CLI deployment script.