Skip to content

Commit 4e83c0b

Browse files
authored
Azure: Bicep test (#34)
* added preliminary bicep tests only * renamed all resourced groups to be unique * run all tests with corrected web app-sql test for bicep * run onyl bicep tests * added logging for failing tests * revert changes * run all tests without failing bicep sql test
1 parent 2cf46f6 commit 4e83c0b

7 files changed

Lines changed: 65 additions & 8 deletions

File tree

.github/workflows/run-samples.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ name: Samples CI
66
# 1. Parallel Testing: Splits the sample suite into shards to reduce execution time.
77
# 2. Standardized Tooling: Uses a Makefile for environment setup and test orchestration.
88
# 3. Cloud Emulation: Configures the Azure CLI to target the LocalStack emulator.
9+
# 4. IaC Coverage: Tests bash scripts, Terraform deployments, and Bicep deployments.
910

1011
concurrency:
1112
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
@@ -122,6 +123,7 @@ jobs:
122123
123124
- name: Run Test Scripts
124125
# Executes the sharded test suite. Each shard runs a subset of samples in parallel.
126+
# This includes bash scripts, Terraform deployments, and Bicep deployments.
125127
run: make test SHARD=${{ matrix.shard }} SPLITS=${{ matrix.splits }}
126128
env:
127129
LOCALSTACK_AUTH_TOKEN: ${{ secrets.TEST_LOCALSTACK_AUTH_TOKEN }}

run-samples.sh

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,18 @@ TERRAFORM_SAMPLES=(
9292
"samples/web-app-sql-database/python/terraform|bash deploy.sh"
9393
)
9494

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+
95104
# 4. Calculate Shard
96-
# Combine both script-based and Terraform samples into one array
97-
ALL_SAMPLES=("${SAMPLES[@]}" "${TERRAFORM_SAMPLES[@]}")
105+
# Combine script-based, Terraform, and Bicep samples into one array
106+
ALL_SAMPLES=("${SAMPLES[@]}" "${TERRAFORM_SAMPLES[@]}" "${BICEP_SAMPLES[@]}")
98107
TOTAL=${#ALL_SAMPLES[@]}
99108
SHARD=${1:-1}
100109
SPLITS=${2:-1}
@@ -107,7 +116,7 @@ if [ "$SHARD" -eq "$SPLITS" ]; then
107116
fi
108117

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

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

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+
136172
popd > /dev/null
137173
echo "Completed: $path"
138174

samples/function-app-managed-identity/python/bicep/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PREFIX='local'
55
SUFFIX='test'
66
TEMPLATE="main.bicep"
77
PARAMETERS="main.bicepparam"
8-
RESOURCE_GROUP_NAME="$PREFIX-rg"
8+
RESOURCE_GROUP_NAME="$PREFIX-func-mi-rg"
99
LOCATION="westeurope"
1010
MANAGED_IDENTITY_TYPE='UserAssigned' # SystemAssigned or UserAssigned
1111
VALIDATE_TEMPLATE=1

samples/function-app-storage-http/dotnet/bicep/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Variables
44
TEMPLATE="main.bicep"
55
PARAMETERS="main.bicepparam"
6-
RESOURCE_GROUP_NAME="bingo-rg"
6+
RESOURCE_GROUP_NAME="local-func-storage-rg"
77
LOCATION="westeurope"
88
VALIDATE_TEMPLATE=1
99
USE_WHAT_IF=0

samples/web-app-cosmosdb-mongodb-api/python/bicep/deploy.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PREFIX='local'
55
SUFFIX='test'
66
TEMPLATE="main.bicep"
77
PARAMETERS="main.bicepparam"
8-
RESOURCE_GROUP_NAME="${PREFIX}-rg"
8+
RESOURCE_GROUP_NAME="${PREFIX}-webapp-cosmos-rg"
99
LOCATION="westeurope"
1010
VALIDATE_TEMPLATE=1
1111
USE_WHAT_IF=0

samples/web-app-managed-identity/python/bicep/deploy.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/bin/bash
22

3+
# Enable verbose debugging
4+
set -x
5+
36
# Variables
47
PREFIX='local'
58
SUFFIX='test'
69
TEMPLATE="main.bicep"
710
PARAMETERS="main.bicepparam"
8-
RESOURCE_GROUP_NAME="$PREFIX-rg"
11+
RESOURCE_GROUP_NAME="$PREFIX-webapp-mi-rg"
912
LOCATION="westeurope"
1013
VALIDATE_TEMPLATE=1
1114
USE_WHAT_IF=0
@@ -15,6 +18,13 @@ ZIPFILE="webapp_app.zip"
1518
MANAGED_IDENTITY_TYPE="UserAssigned" # SystemAssigned or UserAssigned
1619
ENVIRONMENT=$(az account show --query environmentName --output tsv)
1720

21+
echo "=================================================="
22+
echo "DEBUG: Starting bicep deployment for web-app-managed-identity"
23+
echo "DEBUG: Resource Group: $RESOURCE_GROUP_NAME"
24+
echo "DEBUG: Environment: $ENVIRONMENT"
25+
echo "DEBUG: Managed Identity Type: $MANAGED_IDENTITY_TYPE"
26+
echo "=================================================="
27+
1828
# Change the current directory to the script's directory
1929
cd "$CURRENT_DIR" || exit
2030

samples/web-app-sql-database/python/bicep/deploy.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
#!/bin/bash
22

3+
# Enable verbose debugging
4+
set -x
5+
36
# Variables
47
PREFIX='local'
58
SUFFIX='test'
69
TEMPLATE="main.bicep"
710
PARAMETERS="main.bicepparam"
8-
RESOURCE_GROUP_NAME="$PREFIX-rg"
11+
RESOURCE_GROUP_NAME="$PREFIX-webapp-sql-rg"
912
LOCATION="westeurope"
1013
VALIDATE_TEMPLATE=1
1114
USE_WHAT_IF=0
@@ -19,6 +22,12 @@ ZIPFILE="planner_website.zip"
1922
ENVIRONMENT=$(az account show --query environmentName --output tsv)
2023
DEPLOY_APP=1
2124

25+
echo "=================================================="
26+
echo "DEBUG: Starting bicep deployment for web-app-sql-database"
27+
echo "DEBUG: Resource Group: $RESOURCE_GROUP_NAME"
28+
echo "DEBUG: Environment: $ENVIRONMENT"
29+
echo "=================================================="
30+
2231
# Change the current directory to the script's directory
2332
cd "$CURRENT_DIR" || exit
2433

0 commit comments

Comments
 (0)