@@ -9,6 +9,7 @@ set -euo pipefail
99# - Node.js & npm
1010# - Azure CLI (az)
1111# - LocalStack CLI
12+ # - Terraform CLI
1213# - azlocal & terraform-local (pip install azlocal terraform-local)
1314# - funclocal (pip install funclocal)
1415# - Azure Functions Core Tools (func)
@@ -32,6 +33,7 @@ command -v az >/dev/null 2>&1 || { echo >&2 "az CLI is required but not installe
3233command -v azlocal > /dev/null 2>&1 || { echo >&2 " azlocal is required but not installed. Run 'pip install azlocal'. Aborting." ; exit 1; }
3334command -v funclocal > /dev/null 2>&1 || { echo >&2 " funclocal is required but not installed. Run 'pip install azlocal'. Aborting." ; exit 1; }
3435command -v tflocal > /dev/null 2>&1 || { echo >&2 " tflocal is required but not installed. Run 'pip install terraform-local'. Aborting." ; exit 1; }
36+ command -v terraform > /dev/null 2>&1 || { echo >&2 " terraform CLI is required but not installed. Aborting." ; exit 1; }
3537command -v func > /dev/null 2>&1 || { echo >&2 " Azure Functions Core Tools (func) is required but not installed. Aborting." ; exit 1; }
3638
3739if [ -z " ${LOCALSTACK_AUTH_TOKEN:- } " ]; then
@@ -55,10 +57,19 @@ if [ -n "${AZURE_CONFIG_DIR:-}" ]; then
5557fi
5658
5759if command -v azlocal > /dev/null 2>&1 ; then
60+ echo " [DEBUG] azlocal command found, attempting login..."
5861 azlocal login || true
62+ echo " [DEBUG] Starting azlocal interception..."
5963 azlocal start_interception
64+ echo " [DEBUG] Setting default subscription..."
65+ azlocal account set --subscription " 00000000-0000-0000-0000-000000000000" || true
66+ echo " [DEBUG] Checking azlocal account status..."
67+ azlocal account show --query " {Environment:environmentName, Subscription:id}" --output json 2>&1 || echo " [DEBUG] azlocal account show failed"
6068else
69+ echo " [DEBUG] azlocal not found, using standard az login with service principal..."
6170 az login --service-principal -u any-app -p any-pass --tenant any-tenant || true
71+ echo " [DEBUG] Checking az account status..."
72+ az account show --query " {Environment:environmentName, Subscription:id}" --output json 2>&1 || echo " [DEBUG] az account show failed"
6273fi
6374
6475
@@ -72,8 +83,28 @@ SAMPLES=(
7283 " samples/web-app-sql-database/python|bash scripts/deploy.sh|bash scripts/validate.sh && bash scripts/get-web-app-url.sh"
7384)
7485
86+ # 3a. Define Terraform Samples
87+ TERRAFORM_SAMPLES=(
88+ " samples/function-app-managed-identity/python/terraform|bash deploy.sh"
89+ " samples/function-app-storage-http/dotnet/terraform|bash deploy.sh"
90+ " samples/web-app-cosmosdb-mongodb-api/python/terraform|bash deploy.sh"
91+ " samples/web-app-managed-identity/python/terraform|bash deploy.sh"
92+ " samples/web-app-sql-database/python/terraform|bash deploy.sh"
93+ )
94+
95+ # 3b. Define Bicep Samples
96+ BICEP_SAMPLES=(
97+ # "samples/web-app-sql-database/python/bicep|bash deploy.sh"
98+ " samples/function-app-managed-identity/python/bicep|bash deploy.sh"
99+ " samples/function-app-storage-http/dotnet/bicep|bash deploy.sh"
100+ " samples/web-app-cosmosdb-mongodb-api/python/bicep|bash deploy.sh"
101+ " samples/web-app-managed-identity/python/bicep|bash deploy.sh"
102+ )
103+
75104# 4. Calculate Shard
76- TOTAL=${# SAMPLES[@]}
105+ # Combine script-based, Terraform, and Bicep samples into one array
106+ ALL_SAMPLES=(" ${SAMPLES[@]} " " ${TERRAFORM_SAMPLES[@]} " " ${BICEP_SAMPLES[@]} " )
107+ TOTAL=${# ALL_SAMPLES[@]}
77108SHARD=${1:- 1}
78109SPLITS=${2:- 1}
79110
@@ -85,28 +116,62 @@ if [ "$SHARD" -eq "$SPLITS" ]; then
85116fi
86117
87118echo " Running samples shard $SHARD of $SPLITS (index $START , count $COUNT )"
119+ echo " Total samples (scripts + terraform + bicep): $TOTAL "
88120
89121# 5. Run Samples
90122for (( i= START; i< START+ COUNT; i++ )) ; do
91- item=" ${SAMPLES [$i]} "
123+ item=" ${ALL_SAMPLES [$i]} "
92124 IFS=' |' read -r path deploy test <<< " $item"
93125 echo " ============================================================"
94126 echo " Testing Sample: $path "
95127 echo " ============================================================"
96-
128+
97129 pushd " $path " > /dev/null
98-
130+
99131 echo " Deploying..."
100132 eval " $deploy "
101-
133+
102134 if [ -n " $test " ]; then
103135 echo " Testing..."
104136 eval " $test "
105137 fi
106-
138+
139+ # Cleanup Terraform state for terraform tests
140+ if [[ " $path " == * " /terraform" ]]; then
141+ echo " Cleaning up Terraform state..."
142+ rm -rf .terraform terraform.tfstate terraform.tfstate.backup .terraform.lock.hcl tfplan || true
143+ fi
144+
145+ # Cleanup Bicep artifacts for bicep tests
146+ if [[ " $path " == * " /bicep" ]]; then
147+ echo " Cleaning up Bicep artifacts..."
148+ # Clean up zip files if any were created
149+ rm -f * .zip || true
150+
151+ # Clean up Azure resources to prevent state pollution between tests
152+ echo " Cleaning up Azure resources in LocalStack..."
153+ if command -v azlocal > /dev/null 2>&1 ; then
154+ echo " Deleting all resource groups..."
155+ # List and delete all resource groups
156+ RG_LIST=$( azlocal group list --query " [].name" -o tsv 2> /dev/null || echo " " )
157+ if [[ -n " $RG_LIST " ]]; then
158+ echo " $RG_LIST " | while read -r rg; do
159+ if [[ -n " $rg " ]]; then
160+ echo " - Deleting resource group: $rg "
161+ azlocal group delete --name " $rg " --yes --no-wait 2> /dev/null || true
162+ fi
163+ done
164+ # Wait a bit for deletions to process
165+ sleep 2
166+ else
167+ echo " No resource groups to clean up"
168+ fi
169+ fi
170+ fi
171+
107172 popd > /dev/null
108173 echo " Completed: $path "
109-
174+
110175 # Cleanup Docker resources after each test to free up disk space
111176 echo " Cleaning up Docker resources..."
112177 docker system prune -af --volumes || true
0 commit comments