Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/run-samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name: Samples CI
# 1. Parallel Testing: Splits the sample suite into shards to reduce execution time.
# 2. Standardized Tooling: Uses a Makefile for environment setup and test orchestration.
# 3. Cloud Emulation: Configures the Azure CLI to target the LocalStack emulator.
# 4. IaC Coverage: Tests bash scripts, Terraform deployments, and Bicep deployments.

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
Expand Down Expand Up @@ -122,6 +123,7 @@ jobs:

- name: Run Test Scripts
# Executes the sharded test suite. Each shard runs a subset of samples in parallel.
# This includes bash scripts, Terraform deployments, and Bicep deployments.
run: make test SHARD=${{ matrix.shard }} SPLITS=${{ matrix.splits }}
env:
LOCALSTACK_AUTH_TOKEN: ${{ secrets.TEST_LOCALSTACK_AUTH_TOKEN }}
Expand Down
42 changes: 39 additions & 3 deletions run-samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,18 @@ TERRAFORM_SAMPLES=(
"samples/web-app-sql-database/python/terraform|bash deploy.sh"
)

# 3b. Define Bicep Samples
BICEP_SAMPLES=(
#"samples/web-app-sql-database/python/bicep|bash deploy.sh"
"samples/function-app-managed-identity/python/bicep|bash deploy.sh"
"samples/function-app-storage-http/dotnet/bicep|bash deploy.sh"
"samples/web-app-cosmosdb-mongodb-api/python/bicep|bash deploy.sh"
"samples/web-app-managed-identity/python/bicep|bash deploy.sh"
)

# 4. Calculate Shard
# Combine both script-based and Terraform samples into one array
ALL_SAMPLES=("${SAMPLES[@]}" "${TERRAFORM_SAMPLES[@]}")
# Combine script-based, Terraform, and Bicep samples into one array
ALL_SAMPLES=("${SAMPLES[@]}" "${TERRAFORM_SAMPLES[@]}" "${BICEP_SAMPLES[@]}")
TOTAL=${#ALL_SAMPLES[@]}
SHARD=${1:-1}
SPLITS=${2:-1}
Expand All @@ -107,7 +116,7 @@ if [ "$SHARD" -eq "$SPLITS" ]; then
fi

echo "Running samples shard $SHARD of $SPLITS (index $START, count $COUNT)"
echo "Total samples (scripts + terraform): $TOTAL"
echo "Total samples (scripts + terraform + bicep): $TOTAL"

# 5. Run Samples
for (( i=START; i<START+COUNT; i++ )); do
Expand All @@ -133,6 +142,33 @@ for (( i=START; i<START+COUNT; i++ )); do
rm -rf .terraform terraform.tfstate terraform.tfstate.backup .terraform.lock.hcl tfplan || true
fi

# Cleanup Bicep artifacts for bicep tests
if [[ "$path" == *"/bicep" ]]; then
echo "Cleaning up Bicep artifacts..."
# Clean up zip files if any were created
rm -f *.zip || true

# Clean up Azure resources to prevent state pollution between tests
echo "Cleaning up Azure resources in LocalStack..."
if command -v azlocal >/dev/null 2>&1; then
echo "Deleting all resource groups..."
# List and delete all resource groups
RG_LIST=$(azlocal group list --query "[].name" -o tsv 2>/dev/null || echo "")
if [[ -n "$RG_LIST" ]]; then
echo "$RG_LIST" | while read -r rg; do
if [[ -n "$rg" ]]; then
echo " - Deleting resource group: $rg"
azlocal group delete --name "$rg" --yes --no-wait 2>/dev/null || true
fi
done
# Wait a bit for deletions to process
sleep 2
else
echo " No resource groups to clean up"
fi
fi
fi

popd > /dev/null
echo "Completed: $path"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PREFIX='local'
SUFFIX='test'
TEMPLATE="main.bicep"
PARAMETERS="main.bicepparam"
RESOURCE_GROUP_NAME="$PREFIX-rg"
RESOURCE_GROUP_NAME="$PREFIX-func-mi-rg"
LOCATION="westeurope"
MANAGED_IDENTITY_TYPE='UserAssigned' # SystemAssigned or UserAssigned
VALIDATE_TEMPLATE=1
Expand Down
2 changes: 1 addition & 1 deletion samples/function-app-storage-http/dotnet/bicep/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Variables
TEMPLATE="main.bicep"
PARAMETERS="main.bicepparam"
RESOURCE_GROUP_NAME="bingo-rg"
RESOURCE_GROUP_NAME="local-func-storage-rg"
LOCATION="westeurope"
VALIDATE_TEMPLATE=1
USE_WHAT_IF=0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PREFIX='local'
SUFFIX='test'
TEMPLATE="main.bicep"
PARAMETERS="main.bicepparam"
RESOURCE_GROUP_NAME="${PREFIX}-rg"
RESOURCE_GROUP_NAME="${PREFIX}-webapp-cosmos-rg"
LOCATION="westeurope"
VALIDATE_TEMPLATE=1
USE_WHAT_IF=0
Expand Down
12 changes: 11 additions & 1 deletion samples/web-app-managed-identity/python/bicep/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash

# Enable verbose debugging
set -x

# Variables
PREFIX='local'
SUFFIX='test'
TEMPLATE="main.bicep"
PARAMETERS="main.bicepparam"
RESOURCE_GROUP_NAME="$PREFIX-rg"
RESOURCE_GROUP_NAME="$PREFIX-webapp-mi-rg"
LOCATION="westeurope"
VALIDATE_TEMPLATE=1
USE_WHAT_IF=0
Expand All @@ -15,6 +18,13 @@ ZIPFILE="webapp_app.zip"
MANAGED_IDENTITY_TYPE="UserAssigned" # SystemAssigned or UserAssigned
ENVIRONMENT=$(az account show --query environmentName --output tsv)

echo "=================================================="
echo "DEBUG: Starting bicep deployment for web-app-managed-identity"
echo "DEBUG: Resource Group: $RESOURCE_GROUP_NAME"
echo "DEBUG: Environment: $ENVIRONMENT"
echo "DEBUG: Managed Identity Type: $MANAGED_IDENTITY_TYPE"
echo "=================================================="

# Change the current directory to the script's directory
cd "$CURRENT_DIR" || exit

Expand Down
11 changes: 10 additions & 1 deletion samples/web-app-sql-database/python/bicep/deploy.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/bin/bash

# Enable verbose debugging
set -x

# Variables
PREFIX='local'
SUFFIX='test'
TEMPLATE="main.bicep"
PARAMETERS="main.bicepparam"
RESOURCE_GROUP_NAME="$PREFIX-rg"
RESOURCE_GROUP_NAME="$PREFIX-webapp-sql-rg"
LOCATION="westeurope"
VALIDATE_TEMPLATE=1
USE_WHAT_IF=0
Expand All @@ -19,6 +22,12 @@ ZIPFILE="planner_website.zip"
ENVIRONMENT=$(az account show --query environmentName --output tsv)
DEPLOY_APP=1

echo "=================================================="
echo "DEBUG: Starting bicep deployment for web-app-sql-database"
echo "DEBUG: Resource Group: $RESOURCE_GROUP_NAME"
echo "DEBUG: Environment: $ENVIRONMENT"
echo "=================================================="

# Change the current directory to the script's directory
cd "$CURRENT_DIR" || exit

Expand Down