This directory contains Terraform modules and deploy.sh deployment script for creating Azure services. For more information, see Azure Functions Sample with LocalStack for Azure.
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
- Terraform: Infrastructure as Code tool for provisioning Azure resources
- .NET SDK: Required for building and publishing the C# Azure Functions application
- Docker: Container runtime required for LocalStack
- Azure CLI: Azure command-line interface
- azlocal CLI: LocalStack Azure CLI wrapper
- jq: JSON processor for scripting and parsing command outputs
The deploy.sh 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 main.tf Terraform module creates the following Azure resources:
- Azure Resource Group: Logical container for all gaming system resources
- Azure Storage Account: Provides blob containers, queues, and tables for the gaming system
- Azure App Service Plan: Hosting plan for the Azure Functions application
- Azure Linux Function App Serverless compute platform hosting the gaming logic with consumption plan
The system implements a complete gaming scoreboard with multiple Azure Functions that handle HTTP requests, process blob uploads, manage queue messages, and maintain game statistics.
See deploy.sh for the complete deployment automation. The script performs:
- Detects environment (LocalStack vs Azure Cloud) and uses appropriate CLI (
tflocal/azlocalorterraform/az) - Initializes Terraform and downloads required providers
- Creates and validates Terraform execution plan with custom variables
- Applies Terraform configuration to provision Azure resources
- Extracts output values (resource group name, function app name)
- Builds and publishes the .NET application in Release configuration
- Creates deployment zip package from published output
- Deploys the zip to Azure Function App using Azure CLI
-
You can set up the Azure emulator by utilizing LocalStack for Azure Docker image. Before starting, ensure you have a valid
LOCALSTACK_AUTH_TOKENto access the Azure emulator. Refer to the Auth Token guide to obtain your Auth Token and specify it in theLOCALSTACK_AUTH_TOKENenvironment 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-alpha
-
Start 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 start
-
Navigate to the scripts directory
cd samples/function-app-and-storage/dotnet/terraform -
Make the script executable:
chmod +x deploy.sh
-
Run the deployment script:
./deploy.sh
After 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 function app status
$AZ functionapp show \
--name local-func-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-errors
# List storage queues
$AZ storage queue list \
--account-name localstoragetest \
--output table \
--only-show-errors
# List storage tables
$AZ storage table 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.
- Azure Functions Documentation
- Terraform Azure Provider
- LocalStack for Azure Documentation
- Azure Functions Methods Documentation - Detailed documentation of all implemented functions