From 8b30f9e3340c68d64c5bc5e83d42b74cf5667f0b Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Thu, 29 Oct 2026 14:46:41 +0100 Subject: [PATCH 1/9] Give every sample its own name prefix in the samples runner run-samples.sh runs the samples one after another on one emulator, and after each sample it deletes every resource group with --no-wait. 60 of its 81 entries then reuse the previous entry's group (local-rg, local-aca-rg), so they write into a group that may still be being deleted: Azure refuses that with 409 ResourceGroupBeingDeleted, the emulator will too (SMF-998), and today the emulator accepts it and leaves the new resources behind once the group is gone (18 Terraform entries already fail on azurerm's existence check because of that). The runner now exports its own PREFIX for every entry: the letter l and four random lowercase letters, never the previous entry's, so every group and resource name differs from the previous sample's and nothing waits for a delete. The prefix has the length and characters of the default "local", so no name changes length. Every sample builds its names from PREFIX: the 27 scripts that hardcoded PREFIX='local' now read PREFIX="${PREFIX:-local}" like the other 89, and the five deploy scripts whose template took the prefix from its parameter file or variable default (url-shortener and eventhubs Bicep, eventhubs-eventgrid Bicep, eventhubs and eventhubs-eventgrid Terraform) pass it explicitly. Running a sample by hand still uses local. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FvNuJJpEr2yMWrV5cbJi2Z --- run-samples.sh | 25 +++++++++++++++++++ .../aci-blob-storage/python/bicep/deploy.sh | 2 +- .../python/scripts/cleanup.sh | 2 +- .../aci-blob-storage/python/scripts/deploy.sh | 2 +- .../python/scripts/validate.sh | 2 +- .../python/terraform/deploy.sh | 2 +- .../python/bicep/deploy.sh | 2 +- .../python/scripts/cleanup.sh | 2 +- .../python/scripts/deploy.sh | 2 +- .../python/scripts/validate.sh | 2 +- .../python/terraform/deploy.sh | 2 +- .../python/bicep/deploy.sh | 4 ++- .../python/scripts/cleanup.sh | 2 +- .../python/scripts/deploy.sh | 2 +- .../python/scripts/validate.sh | 2 +- .../python/terraform/deploy.sh | 9 ++++--- samples/eventhubs/python/bicep/deploy.sh | 4 ++- samples/eventhubs/python/scripts/cleanup.sh | 2 +- samples/eventhubs/python/scripts/deploy.sh | 2 +- samples/eventhubs/python/scripts/validate.sh | 2 +- samples/eventhubs/python/terraform/deploy.sh | 9 ++++--- samples/servicebus/java/bicep/deploy.sh | 2 +- samples/servicebus/java/scripts/deploy.sh | 2 +- samples/servicebus/java/scripts/validate.sh | 2 +- samples/servicebus/java/terraform/deploy.sh | 2 +- samples/url-shortener/python/bicep/deploy.sh | 4 ++- .../python/scripts/call-web-app.sh | 2 +- .../url-shortener/python/scripts/deploy.sh | 2 +- .../url-shortener/python/scripts/validate.sh | 2 +- .../url-shortener/python/terraform/deploy.sh | 2 +- 30 files changed, 70 insertions(+), 33 deletions(-) diff --git a/run-samples.sh b/run-samples.sh index 9031c74b..2164524f 100755 --- a/run-samples.sh +++ b/run-samples.sh @@ -209,6 +209,28 @@ host_arch() { esac } +# Set PREFIX, from which every sample builds its resource group and resource names ("local" by default), to the +# letter l and four random lowercase letters, never the previous sample's. The cleanup after each sample deletes +# every resource group with --no-wait, so a sample that reused the previous one's names could write into a group +# still being deleted: Azure refuses that with 409 ResourceGroupBeingDeleted, and an emulator that accepts it +# leaves the new resources behind once the group is gone. Giving every sample its own names avoids both without +# waiting for the deletes. The prefix keeps the length and the characters of "local", so no name changes length. +# $RANDOM in this shell rather than a pipeline from /dev/urandom: under pipefail, the SIGPIPE that head gives tr +# would end the script. +set_sample_name_prefix() { + local letters=abcdefghijklmnopqrstuvwxyz previous="${PREFIX:-}" i + while true; do + PREFIX=l + for (( i = 0; i < 4; i++ )); do + PREFIX+="${letters:RANDOM % 26:1}" + done + if [[ "$PREFIX" != "$previous" ]]; then + break + fi + done + export PREFIX +} + # 2. Handle --list flag: output JSON metadata for CI matrix generation (no tools required) # Each entry has: shard (1-based index), splits (total count), name, watch_folders, # and arches. CI uses watch_folders to detect which tests are affected by changed @@ -368,6 +390,9 @@ for (( i=START; i /dev/null # Deploy a Terraform sample from empty state. A failed run skips the cleanup below and leaves diff --git a/samples/aci-blob-storage/python/bicep/deploy.sh b/samples/aci-blob-storage/python/bicep/deploy.sh index d9d616b7..ffec1885 100644 --- a/samples/aci-blob-storage/python/bicep/deploy.sh +++ b/samples/aci-blob-storage/python/bicep/deploy.sh @@ -4,7 +4,7 @@ set -x # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' TEMPLATE="main.bicep" PARAMETERS="main.bicepparam" diff --git a/samples/aci-blob-storage/python/scripts/cleanup.sh b/samples/aci-blob-storage/python/scripts/cleanup.sh index 24f22987..8a1533d8 100644 --- a/samples/aci-blob-storage/python/scripts/cleanup.sh +++ b/samples/aci-blob-storage/python/scripts/cleanup.sh @@ -8,7 +8,7 @@ # ============================================================================= # Variables (must match deploy.sh) -PREFIX='local' +PREFIX="${PREFIX:-local}" RESOURCE_GROUP_NAME="${PREFIX}-aci-rg" ACI_GROUP_NAME="${PREFIX}-aci-planner" ACI_GROUP_ADVANCED="${PREFIX}-aci-planner-advanced" diff --git a/samples/aci-blob-storage/python/scripts/deploy.sh b/samples/aci-blob-storage/python/scripts/deploy.sh index a53ef402..f84e95fc 100644 --- a/samples/aci-blob-storage/python/scripts/deploy.sh +++ b/samples/aci-blob-storage/python/scripts/deploy.sh @@ -11,7 +11,7 @@ # ============================================================================= # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" LOCATION='eastus' RESOURCE_GROUP_NAME="${PREFIX}-aci-rg" STORAGE_ACCOUNT_NAME="${PREFIX}acistorage" diff --git a/samples/aci-blob-storage/python/scripts/validate.sh b/samples/aci-blob-storage/python/scripts/validate.sh index 93d89e4c..3e087282 100644 --- a/samples/aci-blob-storage/python/scripts/validate.sh +++ b/samples/aci-blob-storage/python/scripts/validate.sh @@ -8,7 +8,7 @@ # ============================================================================= # Variables (must match deploy.sh) -PREFIX='local' +PREFIX="${PREFIX:-local}" LOCATION='eastus' RESOURCE_GROUP_NAME="${PREFIX}-aci-rg" STORAGE_ACCOUNT_NAME="${PREFIX}acistorage" diff --git a/samples/aci-blob-storage/python/terraform/deploy.sh b/samples/aci-blob-storage/python/terraform/deploy.sh index e1fcf95e..8e48e46e 100644 --- a/samples/aci-blob-storage/python/terraform/deploy.sh +++ b/samples/aci-blob-storage/python/terraform/deploy.sh @@ -1,7 +1,7 @@ #!/bin/bash # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' LOCATION='eastus' IMAGE_NAME='vacation-planner' diff --git a/samples/container-apps-blob-storage/python/bicep/deploy.sh b/samples/container-apps-blob-storage/python/bicep/deploy.sh index 73267c38..92e055ef 100644 --- a/samples/container-apps-blob-storage/python/bicep/deploy.sh +++ b/samples/container-apps-blob-storage/python/bicep/deploy.sh @@ -4,7 +4,7 @@ set -x # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' TEMPLATE="main.bicep" PARAMETERS="main.bicepparam" diff --git a/samples/container-apps-blob-storage/python/scripts/cleanup.sh b/samples/container-apps-blob-storage/python/scripts/cleanup.sh index e79eab2d..69c6ff88 100644 --- a/samples/container-apps-blob-storage/python/scripts/cleanup.sh +++ b/samples/container-apps-blob-storage/python/scripts/cleanup.sh @@ -8,7 +8,7 @@ # ============================================================================= # Variables (must match deploy.sh) -PREFIX='local' +PREFIX="${PREFIX:-local}" RESOURCE_GROUP_NAME="${PREFIX}-aca-rg" ACA_APP_NAME="${PREFIX}-aca-guestbook" ACA_ENV_NAME="${PREFIX}-aca-env" diff --git a/samples/container-apps-blob-storage/python/scripts/deploy.sh b/samples/container-apps-blob-storage/python/scripts/deploy.sh index 48426ac7..726880b1 100644 --- a/samples/container-apps-blob-storage/python/scripts/deploy.sh +++ b/samples/container-apps-blob-storage/python/scripts/deploy.sh @@ -17,7 +17,7 @@ # ============================================================================= # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" LOCATION='eastus' RESOURCE_GROUP_NAME="${PREFIX}-aca-rg" STORAGE_ACCOUNT_NAME="${PREFIX}acastorage" diff --git a/samples/container-apps-blob-storage/python/scripts/validate.sh b/samples/container-apps-blob-storage/python/scripts/validate.sh index edfc3114..6cc25903 100644 --- a/samples/container-apps-blob-storage/python/scripts/validate.sh +++ b/samples/container-apps-blob-storage/python/scripts/validate.sh @@ -20,7 +20,7 @@ null_device() { } # Variables (must match deploy.sh) -PREFIX='local' +PREFIX="${PREFIX:-local}" LOCATION='eastus' RESOURCE_GROUP_NAME="${PREFIX}-aca-rg" STORAGE_ACCOUNT_NAME="${PREFIX}acastorage" diff --git a/samples/container-apps-blob-storage/python/terraform/deploy.sh b/samples/container-apps-blob-storage/python/terraform/deploy.sh index fff2931c..65b6faab 100644 --- a/samples/container-apps-blob-storage/python/terraform/deploy.sh +++ b/samples/container-apps-blob-storage/python/terraform/deploy.sh @@ -1,7 +1,7 @@ #!/bin/bash # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' LOCATION='eastus' IMAGE_NAME='guestbook' diff --git a/samples/eventhubs-eventgrid/python/bicep/deploy.sh b/samples/eventhubs-eventgrid/python/bicep/deploy.sh index 33f6d68c..beb76166 100644 --- a/samples/eventhubs-eventgrid/python/bicep/deploy.sh +++ b/samples/eventhubs-eventgrid/python/bicep/deploy.sh @@ -6,7 +6,7 @@ # in the other samples. # ============================================================================= -PREFIX='local' +PREFIX="${PREFIX:-local}" LOCATION='westeurope' RESOURCE_GROUP_NAME="${PREFIX}-ehgrid-rg" DEPLOYMENT_NAME='eventhubs-eventgrid-coldpath' @@ -43,6 +43,7 @@ az deployment group validate \ --resource-group "$RESOURCE_GROUP_NAME" \ --template-file main.bicep \ --parameters main.bicepparam \ + --parameters prefix="$PREFIX" \ --only-show-errors 1>/dev/null || fail "the Bicep template did not pass validation" echo "" @@ -52,6 +53,7 @@ az deployment group create \ --resource-group "$RESOURCE_GROUP_NAME" \ --template-file main.bicep \ --parameters main.bicepparam \ + --parameters prefix="$PREFIX" \ --only-show-errors 1>/dev/null || fail "the Bicep deployment failed" echo "Template deployed." diff --git a/samples/eventhubs-eventgrid/python/scripts/cleanup.sh b/samples/eventhubs-eventgrid/python/scripts/cleanup.sh index 46b09140..b6f0210a 100644 --- a/samples/eventhubs-eventgrid/python/scripts/cleanup.sh +++ b/samples/eventhubs-eventgrid/python/scripts/cleanup.sh @@ -7,7 +7,7 @@ # system topic and the Function App all live inside it. # ============================================================================= -PREFIX='local' +PREFIX="${PREFIX:-local}" RESOURCE_GROUP_NAME="${PREFIX}-ehgrid-rg" CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)" diff --git a/samples/eventhubs-eventgrid/python/scripts/deploy.sh b/samples/eventhubs-eventgrid/python/scripts/deploy.sh index 34c87221..2f55b995 100644 --- a/samples/eventhubs-eventgrid/python/scripts/deploy.sh +++ b/samples/eventhubs-eventgrid/python/scripts/deploy.sh @@ -13,7 +13,7 @@ # Everything runs against the LocalStack Azure emulator. Run 'lstk az start-interception' first. # ============================================================================= -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='telemetry' LOCATION='westeurope' RESOURCE_GROUP_NAME="${PREFIX}-ehgrid-rg" diff --git a/samples/eventhubs-eventgrid/python/scripts/validate.sh b/samples/eventhubs-eventgrid/python/scripts/validate.sh index 3a8acb49..ecff3a66 100644 --- a/samples/eventhubs-eventgrid/python/scripts/validate.sh +++ b/samples/eventhubs-eventgrid/python/scripts/validate.sh @@ -6,7 +6,7 @@ # wiring that connects them, then the workloads and the data plane. # ============================================================================= -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='telemetry' RESOURCE_GROUP_NAME="${PREFIX}-ehgrid-rg" EVENTHUB_NAMESPACE_NAME="${PREFIX}-ehns-${SUFFIX}" diff --git a/samples/eventhubs-eventgrid/python/terraform/deploy.sh b/samples/eventhubs-eventgrid/python/terraform/deploy.sh index 46d702da..66670751 100644 --- a/samples/eventhubs-eventgrid/python/terraform/deploy.sh +++ b/samples/eventhubs-eventgrid/python/terraform/deploy.sh @@ -28,6 +28,9 @@ fail() { exit 1 } +# Name prefix of every resource (the configuration's prefix variable) +PREFIX="${PREFIX:-local}" + echo "=== Initializing Terraform ===" terraform init -input=false || fail "terraform init failed" @@ -37,7 +40,7 @@ terraform validate || fail "terraform validate failed" echo "" echo "=== Planning ===" -terraform plan -input=false -out=tfplan || fail "terraform plan failed" +terraform plan -input=false -var "prefix=$PREFIX" -out=tfplan || fail "terraform plan failed" echo "" echo "=== Applying ===" @@ -45,14 +48,14 @@ terraform apply -input=false -auto-approve tfplan || fail "terraform apply faile echo "" echo "=== Re-applying (the configuration must converge without errors) ===" -terraform apply -input=false -auto-approve || fail "the second apply failed" +terraform apply -input=false -auto-approve -var "prefix=$PREFIX" || fail "the second apply failed" # A perfectly idempotent second apply reports "No changes". Against the emulator a few resources # still report drift because some properties are accepted on create but not echoed back on read, # so the provider re-sends them every run. That is an emulator parity gap rather than a problem # with this configuration: the re-apply converges and changes nothing observable. DRIFT=$( - terraform plan -input=false -detailed-exitcode >/dev/null 2>&1 + terraform plan -input=false -var "prefix=$PREFIX" -detailed-exitcode >/dev/null 2>&1 echo $? ) if [[ "$DRIFT" == "0" ]]; then diff --git a/samples/eventhubs/python/bicep/deploy.sh b/samples/eventhubs/python/bicep/deploy.sh index 84567f19..babab96b 100644 --- a/samples/eventhubs/python/bicep/deploy.sh +++ b/samples/eventhubs/python/bicep/deploy.sh @@ -6,7 +6,7 @@ # packages are pushed with the Azure CLI, as in the other samples). # ============================================================================= -PREFIX='local' +PREFIX="${PREFIX:-local}" LOCATION='westeurope' RESOURCE_GROUP_NAME="${PREFIX}-eventhubs-rg" DEPLOYMENT_NAME="eventhubs-fraud-detection" @@ -47,6 +47,7 @@ az deployment group validate \ --resource-group "$RESOURCE_GROUP_NAME" \ --template-file main.bicep \ --parameters main.bicepparam \ + --parameters prefix="$PREFIX" \ --only-show-errors 1>/dev/null || fail "the Bicep template did not pass validation" echo "" @@ -56,6 +57,7 @@ az deployment group create \ --resource-group "$RESOURCE_GROUP_NAME" \ --template-file main.bicep \ --parameters main.bicepparam \ + --parameters prefix="$PREFIX" \ --only-show-errors 1>/dev/null || fail "the Bicep deployment failed" echo "Template deployed." diff --git a/samples/eventhubs/python/scripts/cleanup.sh b/samples/eventhubs/python/scripts/cleanup.sh index d77e42cc..29b6748c 100644 --- a/samples/eventhubs/python/scripts/cleanup.sh +++ b/samples/eventhubs/python/scripts/cleanup.sh @@ -7,7 +7,7 @@ # Function App and the Web App are all inside it. # ============================================================================= -PREFIX='local' +PREFIX="${PREFIX:-local}" RESOURCE_GROUP_NAME="${PREFIX}-eventhubs-rg" CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)" diff --git a/samples/eventhubs/python/scripts/deploy.sh b/samples/eventhubs/python/scripts/deploy.sh index fe4d3dc4..285d9d0b 100644 --- a/samples/eventhubs/python/scripts/deploy.sh +++ b/samples/eventhubs/python/scripts/deploy.sh @@ -21,7 +21,7 @@ # ============================================================================= # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='payments' LOCATION='westeurope' RESOURCE_GROUP_NAME="${PREFIX}-eventhubs-rg" diff --git a/samples/eventhubs/python/scripts/validate.sh b/samples/eventhubs/python/scripts/validate.sh index bce103b3..86507d32 100644 --- a/samples/eventhubs/python/scripts/validate.sh +++ b/samples/eventhubs/python/scripts/validate.sh @@ -10,7 +10,7 @@ # ============================================================================= # Variables (must match deploy.sh) -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='payments' LOCATION='westeurope' RESOURCE_GROUP_NAME="${PREFIX}-eventhubs-rg" diff --git a/samples/eventhubs/python/terraform/deploy.sh b/samples/eventhubs/python/terraform/deploy.sh index 9c033ebe..813f4c7d 100644 --- a/samples/eventhubs/python/terraform/deploy.sh +++ b/samples/eventhubs/python/terraform/deploy.sh @@ -29,6 +29,9 @@ fail() { exit 1 } +# Name prefix of every resource (the configuration's prefix variable) +PREFIX="${PREFIX:-local}" + echo "=== Initializing Terraform ===" terraform init -input=false || fail "terraform init failed" @@ -38,7 +41,7 @@ terraform validate || fail "terraform validate failed" echo "" echo "=== Planning ===" -terraform plan -input=false -out=tfplan || fail "terraform plan failed" +terraform plan -input=false -var "prefix=$PREFIX" -out=tfplan || fail "terraform plan failed" echo "" echo "=== Applying ===" @@ -46,7 +49,7 @@ terraform apply -input=false -auto-approve tfplan || fail "terraform apply faile echo "" echo "=== Re-applying (the configuration must converge without errors) ===" -terraform apply -input=false -auto-approve || fail "the second apply failed" +terraform apply -input=false -auto-approve -var "prefix=$PREFIX" || fail "the second apply failed" # A perfectly idempotent second apply reports "No changes". Against the emulator a few # resources still report drift because some properties are accepted on create but not @@ -54,7 +57,7 @@ terraform apply -input=false -auto-approve || fail "the second apply failed" # Key Vault tags, and similar), so the provider re-sends them every run. That is an # emulator parity gap rather than a problem with this configuration: the re-apply is # clean, converges, and changes nothing observable. -DRIFT=$(terraform plan -input=false -detailed-exitcode >/dev/null 2>&1; echo $?) +DRIFT=$(terraform plan -input=false -var "prefix=$PREFIX" -detailed-exitcode >/dev/null 2>&1; echo $?) if [[ "$DRIFT" == "0" ]]; then echo "Second apply is fully idempotent (no changes)." else diff --git a/samples/servicebus/java/bicep/deploy.sh b/samples/servicebus/java/bicep/deploy.sh index bc8335df..a431ad75 100755 --- a/samples/servicebus/java/bicep/deploy.sh +++ b/samples/servicebus/java/bicep/deploy.sh @@ -1,7 +1,7 @@ #!/bin/bash # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' TEMPLATE="main.bicep" PARAMETERS="main.bicepparam" diff --git a/samples/servicebus/java/scripts/deploy.sh b/samples/servicebus/java/scripts/deploy.sh index 7697b055..474f09e3 100755 --- a/samples/servicebus/java/scripts/deploy.sh +++ b/samples/servicebus/java/scripts/deploy.sh @@ -1,7 +1,7 @@ #!/bin/bash # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' LOCATION='westeurope' RESOURCE_GROUP_NAME="${PREFIX}-rg" diff --git a/samples/servicebus/java/scripts/validate.sh b/samples/servicebus/java/scripts/validate.sh index 1a76af4f..8f2121e3 100755 --- a/samples/servicebus/java/scripts/validate.sh +++ b/samples/servicebus/java/scripts/validate.sh @@ -1,7 +1,7 @@ #!/bin/bash # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' RESOURCE_GROUP_NAME="${PREFIX}-rg" SERVICEBUS_NAMESPACE_NAME="${PREFIX}-sb-ns-${SUFFIX}" diff --git a/samples/servicebus/java/terraform/deploy.sh b/samples/servicebus/java/terraform/deploy.sh index 4c9875aa..9d80eb5b 100755 --- a/samples/servicebus/java/terraform/deploy.sh +++ b/samples/servicebus/java/terraform/deploy.sh @@ -1,7 +1,7 @@ #!/bin/bash # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' LOCATION='westeurope' SERVICEBUS_QUEUE_NAME="myqueue" # Queue name is hardcoded in the application properties diff --git a/samples/url-shortener/python/bicep/deploy.sh b/samples/url-shortener/python/bicep/deploy.sh index e8b9132b..62558782 100755 --- a/samples/url-shortener/python/bicep/deploy.sh +++ b/samples/url-shortener/python/bicep/deploy.sh @@ -1,7 +1,7 @@ #!/bin/bash # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' LOCATION='westeurope' RESOURCE_GROUP_NAME="${PREFIX}-rg" @@ -49,6 +49,7 @@ az deployment group validate \ --resource-group $RESOURCE_GROUP_NAME \ --template-file $TEMPLATE \ --parameters $PARAMETERS \ + --parameters prefix=$PREFIX \ --output none if [[ $? == 0 ]]; then @@ -65,6 +66,7 @@ DEPLOYMENT_OUTPUTS=$(az deployment group create \ --resource-group $RESOURCE_GROUP_NAME \ --template-file $TEMPLATE \ --parameters $PARAMETERS \ + --parameters prefix=$PREFIX \ --query properties.outputs) if [[ $? == 0 ]]; then diff --git a/samples/url-shortener/python/scripts/call-web-app.sh b/samples/url-shortener/python/scripts/call-web-app.sh index bc4e3938..3c201e6c 100755 --- a/samples/url-shortener/python/scripts/call-web-app.sh +++ b/samples/url-shortener/python/scripts/call-web-app.sh @@ -12,7 +12,7 @@ null_device() { } # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' RESOURCE_GROUP_NAME="${PREFIX}-rg" WEB_APP_NAME="${PREFIX}-urlshort-webapp-${SUFFIX}" diff --git a/samples/url-shortener/python/scripts/deploy.sh b/samples/url-shortener/python/scripts/deploy.sh index 36b2045d..d6201d12 100755 --- a/samples/url-shortener/python/scripts/deploy.sh +++ b/samples/url-shortener/python/scripts/deploy.sh @@ -1,7 +1,7 @@ #!/bin/bash # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' LOCATION='westeurope' RESOURCE_GROUP_NAME="${PREFIX}-rg" diff --git a/samples/url-shortener/python/scripts/validate.sh b/samples/url-shortener/python/scripts/validate.sh index eda8689a..57424ba7 100755 --- a/samples/url-shortener/python/scripts/validate.sh +++ b/samples/url-shortener/python/scripts/validate.sh @@ -1,7 +1,7 @@ #!/bin/bash # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' RESOURCE_GROUP_NAME="${PREFIX}-rg" STORAGE_ACCOUNT_NAME="${PREFIX}urlshortstorage${SUFFIX}" diff --git a/samples/url-shortener/python/terraform/deploy.sh b/samples/url-shortener/python/terraform/deploy.sh index 8d61fa1d..a863be89 100755 --- a/samples/url-shortener/python/terraform/deploy.sh +++ b/samples/url-shortener/python/terraform/deploy.sh @@ -1,7 +1,7 @@ #!/bin/bash # Variables -PREFIX='local' +PREFIX="${PREFIX:-local}" SUFFIX='test' LOCATION='westeurope' CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)" From cddbe730931748e2d5210eb1e9d6ed305e2a9667 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Thu, 29 Oct 2026 14:46:56 +0100 Subject: [PATCH 2/9] Make the sample scripts exit with an error when a step fails The samples runner and the samples CI trust each entry's exit status, but several scripts could end with status 0 after a failed step: - 146 failure branches in 39 scripts ended with a bare exit, which returns the status of the echo before it, 0. They now exit 1. - web-app-cosmosdb-nosql-api (Python and .NET) checked none of its writes after the resource group, and its two export VAR=$(az ...) lines hid any failure of the command. Every az call, the zip and the deploy now stop the script with a message naming the failed step. - container-apps-blob-storage (Terraform and Bicep) did not check the registry create, its login server and admin credentials, the image tag or the docker login; the Terraform deploy also ignored the resource group create, terraform init, terraform plan and its outputs, and swallowed every failure of the resource group import with || true. Each now stops the script with a message; the import is skipped when the group is already in the state (a re-run), which is the only failure the || true meant to tolerate. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FvNuJJpEr2yMWrV5cbJi2Z --- .../aci-blob-storage/python/bicep/deploy.sh | 6 +- .../python/bicep/deploy.sh | 44 +++++--- .../python/terraform/deploy.sh | 102 +++++++++++++----- .../python/bicep/deploy.sh | 6 +- .../python/scripts/system-managed-identity.sh | 6 +- .../python/scripts/user-managed-identity.sh | 6 +- .../dotnet/bicep/deploy.sh | 6 +- .../dotnet/scripts/deploy.sh | 34 +++--- .../dotnet/bicep/deploy.sh | 6 +- samples/servicebus/java/bicep/deploy.sh | 6 +- .../dotnet/bicep/deploy.sh | 6 +- .../dotnet/scripts/deploy.sh | 14 +-- .../python/bicep/deploy.sh | 6 +- .../python/scripts/deploy.sh | 14 +-- .../dotnet/scripts/deploy.sh | 70 ++++++++---- .../python/scripts/deploy.sh | 70 ++++++++---- .../dotnet/bicep/deploy.sh | 10 +- .../dotnet/scripts/deploy.sh | 10 +- .../python/bicep/deploy.sh | 10 +- .../python/scripts/deploy.sh | 10 +- .../dotnet/bicep/deploy.sh | 6 +- .../dotnet/scripts/api.sh | 2 +- .../dotnet/scripts/cli.sh | 2 +- .../dotnet/scripts/system-assigned.sh | 4 +- .../dotnet/scripts/user-assigned.sh | 4 +- .../python/bicep/deploy.sh | 6 +- .../python/scripts/api.sh | 2 +- .../python/scripts/cli.sh | 2 +- .../python/scripts/system-assigned.sh | 4 +- .../python/scripts/user-assigned.sh | 4 +- .../dotnet/bicep/deploy.sh | 6 +- .../dotnet/scripts/deploy.sh | 14 +-- .../python/bicep/deploy.sh | 6 +- .../python/scripts/deploy.sh | 14 +-- .../dotnet/bicep/deploy.sh | 6 +- .../dotnet/scripts/deploy.sh | 14 +-- .../python/bicep/deploy.sh | 6 +- .../python/scripts/deploy.sh | 14 +-- .../dotnet/bicep/deploy.sh | 6 +- .../dotnet/scripts/deploy.sh | 2 +- .../python/bicep/deploy.sh | 6 +- .../python/scripts/deploy.sh | 2 +- 42 files changed, 355 insertions(+), 219 deletions(-) diff --git a/samples/aci-blob-storage/python/bicep/deploy.sh b/samples/aci-blob-storage/python/bicep/deploy.sh index ffec1885..1781b0ba 100644 --- a/samples/aci-blob-storage/python/bicep/deploy.sh +++ b/samples/aci-blob-storage/python/bicep/deploy.sh @@ -42,7 +42,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -131,7 +131,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -150,7 +150,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/container-apps-blob-storage/python/bicep/deploy.sh b/samples/container-apps-blob-storage/python/bicep/deploy.sh index 92e055ef..ae4365fa 100644 --- a/samples/container-apps-blob-storage/python/bicep/deploy.sh +++ b/samples/container-apps-blob-storage/python/bicep/deploy.sh @@ -43,7 +43,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -57,34 +57,46 @@ fi # Create ACR first so we can push the image ACR_NAME="${PREFIX}acaacr${SUFFIX}" echo "Creating ACR [$ACR_NAME] for image push..." -az acr create \ +if ! az acr create \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --location "$LOCATION" \ --sku Basic \ --admin-enabled true \ - --only-show-errors 1>/dev/null + --only-show-errors 1>/dev/null; then + echo "Failed to create ACR [$ACR_NAME]." + exit 1 +fi -LOGIN_SERVER=$(az acr show \ +if ! LOGIN_SERVER=$(az acr show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --query "loginServer" \ --output tsv \ - --only-show-errors) + --only-show-errors); then + echo "Failed to retrieve the login server of ACR [$ACR_NAME]." + exit 1 +fi -ACR_USERNAME=$(az acr credential show \ +if ! ACR_USERNAME=$(az acr credential show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --query "username" \ --output tsv \ - --only-show-errors) + --only-show-errors); then + echo "Failed to retrieve the admin username of ACR [$ACR_NAME]." + exit 1 +fi -ACR_PASSWORD=$(az acr credential show \ +if ! ACR_PASSWORD=$(az acr credential show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --query "passwords[0].value" \ --output tsv \ - --only-show-errors) + --only-show-errors); then + echo "Failed to retrieve the admin password of ACR [$ACR_NAME]." + exit 1 +fi FULL_IMAGE="${LOGIN_SERVER}/${IMAGE_NAME}:${IMAGE_TAG}" @@ -96,10 +108,16 @@ if [[ $? != 0 ]]; then exit 1 fi -docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "$FULL_IMAGE" +if ! docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "$FULL_IMAGE"; then + echo "Failed to tag Docker image [$IMAGE_NAME:$IMAGE_TAG] as [$FULL_IMAGE]." + exit 1 +fi echo "Logging in to ACR [$LOGIN_SERVER]..." -echo "$ACR_PASSWORD" | docker login "$LOGIN_SERVER" --username "$ACR_USERNAME" --password-stdin 2>/dev/null +if ! echo "$ACR_PASSWORD" | docker login "$LOGIN_SERVER" --username "$ACR_USERNAME" --password-stdin 2>/dev/null; then + echo "Failed to log in to ACR [$LOGIN_SERVER]." + exit 1 +fi echo "Pushing image [$FULL_IMAGE]..." docker push "$FULL_IMAGE" 2>/dev/null @@ -133,7 +151,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -153,7 +171,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/container-apps-blob-storage/python/terraform/deploy.sh b/samples/container-apps-blob-storage/python/terraform/deploy.sh index 65b6faab..38b48940 100644 --- a/samples/container-apps-blob-storage/python/terraform/deploy.sh +++ b/samples/container-apps-blob-storage/python/terraform/deploy.sh @@ -22,40 +22,55 @@ RESOURCE_GROUP_NAME="${PREFIX}-aca-rg" ACR_NAME="${PREFIX}acaacr${SUFFIX}" echo "Creating resource group [$RESOURCE_GROUP_NAME]..." -az group create \ +if ! az group create \ --name "$RESOURCE_GROUP_NAME" \ --location "$LOCATION" \ - --only-show-errors 1>/dev/null + --only-show-errors 1>/dev/null; then + echo "Failed to create resource group [$RESOURCE_GROUP_NAME]." + exit 1 +fi echo "Creating ACR [$ACR_NAME] for image push..." -az acr create \ +if ! az acr create \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --location "$LOCATION" \ --sku Basic \ --admin-enabled true \ - --only-show-errors 1>/dev/null + --only-show-errors 1>/dev/null; then + echo "Failed to create ACR [$ACR_NAME]." + exit 1 +fi -LOGIN_SERVER=$(az acr show \ +if ! LOGIN_SERVER=$(az acr show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --query "loginServer" \ --output tsv \ - --only-show-errors) + --only-show-errors); then + echo "Failed to retrieve the login server of ACR [$ACR_NAME]." + exit 1 +fi -ACR_USERNAME=$(az acr credential show \ +if ! ACR_USERNAME=$(az acr credential show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --query "username" \ --output tsv \ - --only-show-errors) + --only-show-errors); then + echo "Failed to retrieve the admin username of ACR [$ACR_NAME]." + exit 1 +fi -ACR_PASSWORD=$(az acr credential show \ +if ! ACR_PASSWORD=$(az acr credential show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --query "passwords[0].value" \ --output tsv \ - --only-show-errors) + --only-show-errors); then + echo "Failed to retrieve the admin password of ACR [$ACR_NAME]." + exit 1 +fi FULL_IMAGE="${LOGIN_SERVER}/${IMAGE_NAME}:${IMAGE_TAG}" @@ -67,10 +82,16 @@ if [[ $? != 0 ]]; then exit 1 fi -docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "$FULL_IMAGE" +if ! docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "$FULL_IMAGE"; then + echo "Failed to tag Docker image [$IMAGE_NAME:$IMAGE_TAG] as [$FULL_IMAGE]." + exit 1 +fi echo "Logging in to ACR [$LOGIN_SERVER]..." -echo "$ACR_PASSWORD" | docker login "$LOGIN_SERVER" --username "$ACR_USERNAME" --password-stdin 2>/dev/null +if ! echo "$ACR_PASSWORD" | docker login "$LOGIN_SERVER" --username "$ACR_USERNAME" --password-stdin 2>/dev/null; then + echo "Failed to log in to ACR [$LOGIN_SERVER]." + exit 1 +fi echo "Pushing image [$FULL_IMAGE]..." docker push "$FULL_IMAGE" 2>/dev/null @@ -86,11 +107,17 @@ echo "Image pushed to ACR successfully." # ============================================================================= echo "Initializing Terraform..." -terraform init -upgrade +if ! terraform init -upgrade; then + echo "Failed to initialize Terraform." + exit 1 +fi # Import the resource group that was pre-created for the image push echo "Importing pre-created resource group into Terraform state..." -terraform import \ +# A re-run finds the group in the state already, and import refuses it; every other failure stops the deploy. +if terraform state show azurerm_resource_group.example >/dev/null 2>&1; then + echo "Resource group [$RESOURCE_GROUP_NAME] is already in the Terraform state." +elif ! terraform import \ -var "prefix=$PREFIX" \ -var "suffix=$SUFFIX" \ -var "location=$LOCATION" \ @@ -98,17 +125,23 @@ terraform import \ -var "image_tag=$IMAGE_TAG" \ -var "managed_identity_type=$MANAGED_IDENTITY_TYPE" \ azurerm_resource_group.example \ - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/${RESOURCE_GROUP_NAME}" 2>/dev/null || true + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/${RESOURCE_GROUP_NAME}"; then + echo "Failed to import resource group [$RESOURCE_GROUP_NAME] into the Terraform state." + exit 1 +fi # Run terraform plan and check for errors echo "Planning Terraform deployment..." -terraform plan -out=tfplan \ +if ! terraform plan -out=tfplan \ -var "prefix=$PREFIX" \ -var "suffix=$SUFFIX" \ -var "location=$LOCATION" \ -var "image_name=$IMAGE_NAME" \ -var "image_tag=$IMAGE_TAG" \ - -var "managed_identity_type=$MANAGED_IDENTITY_TYPE" + -var "managed_identity_type=$MANAGED_IDENTITY_TYPE"; then + echo "Terraform plan failed. Exiting." + exit 1 +fi # Apply the Terraform configuration echo "Applying Terraform configuration..." @@ -120,13 +153,34 @@ if [[ $? != 0 ]]; then fi # Get the output values -RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name) -STORAGE_ACCOUNT_NAME=$(terraform output -raw storage_account_name) -ACR_NAME=$(terraform output -raw acr_name) -ENVIRONMENT_NAME=$(terraform output -raw environment_name) -APP_NAME=$(terraform output -raw app_name) -FQDN=$(terraform output -raw fqdn) -PRINCIPAL_ID=$(terraform output -raw principal_id) +if ! RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name); then + echo "Failed to read the Terraform output [resource_group_name]." + exit 1 +fi +if ! STORAGE_ACCOUNT_NAME=$(terraform output -raw storage_account_name); then + echo "Failed to read the Terraform output [storage_account_name]." + exit 1 +fi +if ! ACR_NAME=$(terraform output -raw acr_name); then + echo "Failed to read the Terraform output [acr_name]." + exit 1 +fi +if ! ENVIRONMENT_NAME=$(terraform output -raw environment_name); then + echo "Failed to read the Terraform output [environment_name]." + exit 1 +fi +if ! APP_NAME=$(terraform output -raw app_name); then + echo "Failed to read the Terraform output [app_name]." + exit 1 +fi +if ! FQDN=$(terraform output -raw fqdn); then + echo "Failed to read the Terraform output [fqdn]." + exit 1 +fi +if ! PRINCIPAL_ID=$(terraform output -raw principal_id); then + echo "Failed to read the Terraform output [principal_id]." + exit 1 +fi echo "" echo "============================================================" diff --git a/samples/function-app-managed-identity/python/bicep/deploy.sh b/samples/function-app-managed-identity/python/bicep/deploy.sh index d1ca5da9..ac48c57c 100755 --- a/samples/function-app-managed-identity/python/bicep/deploy.sh +++ b/samples/function-app-managed-identity/python/bicep/deploy.sh @@ -35,7 +35,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -60,7 +60,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -80,7 +80,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/function-app-managed-identity/python/scripts/system-managed-identity.sh b/samples/function-app-managed-identity/python/scripts/system-managed-identity.sh index 43925aaf..fa5889e4 100755 --- a/samples/function-app-managed-identity/python/scripts/system-managed-identity.sh +++ b/samples/function-app-managed-identity/python/scripts/system-managed-identity.sh @@ -37,7 +37,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -236,7 +236,7 @@ else echo "Successfully assigned [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" else echo "Failed to assign [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" - exit + exit 1 fi fi @@ -277,7 +277,7 @@ else echo "Successfully assigned [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" else echo "Failed to assign [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" - exit + exit 1 fi fi diff --git a/samples/function-app-managed-identity/python/scripts/user-managed-identity.sh b/samples/function-app-managed-identity/python/scripts/user-managed-identity.sh index 06015f16..77e240cf 100755 --- a/samples/function-app-managed-identity/python/scripts/user-managed-identity.sh +++ b/samples/function-app-managed-identity/python/scripts/user-managed-identity.sh @@ -39,7 +39,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -297,7 +297,7 @@ else echo "Successfully assigned [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" else echo "Failed to assign [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" - exit + exit 1 fi fi @@ -338,7 +338,7 @@ else echo "Successfully assigned [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" else echo "Failed to assign [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" - exit + exit 1 fi fi diff --git a/samples/function-app-service-bus/dotnet/bicep/deploy.sh b/samples/function-app-service-bus/dotnet/bicep/deploy.sh index 9a03d5ae..4dbcfc0e 100755 --- a/samples/function-app-service-bus/dotnet/bicep/deploy.sh +++ b/samples/function-app-service-bus/dotnet/bicep/deploy.sh @@ -34,7 +34,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -58,7 +58,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -77,7 +77,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/function-app-service-bus/dotnet/scripts/deploy.sh b/samples/function-app-service-bus/dotnet/scripts/deploy.sh index 420add43..f00c9d23 100755 --- a/samples/function-app-service-bus/dotnet/scripts/deploy.sh +++ b/samples/function-app-service-bus/dotnet/scripts/deploy.sh @@ -88,7 +88,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -114,7 +114,7 @@ if [[ $? != 0 ]]; then echo "[$SERVICE_BUS_NAMESPACE] service bus namespace successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$SERVICE_BUS_NAMESPACE] service bus namespace in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "[$SERVICE_BUS_NAMESPACE] service bus namespace already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -140,7 +140,7 @@ if [[ $? != 0 ]]; then echo "[$INPUT_QUEUE_NAME] service bus queue successfully created in the [$SERVICE_BUS_NAMESPACE] service bus namespace" else echo "Failed to create [$INPUT_QUEUE_NAME] service bus queue in the [$SERVICE_BUS_NAMESPACE] service bus namespace" - exit + exit 1 fi else echo "[$INPUT_QUEUE_NAME] service bus queue already exists in the [$SERVICE_BUS_NAMESPACE] service bus namespace" @@ -166,7 +166,7 @@ if [[ $? != 0 ]]; then echo "[$OUTPUT_QUEUE_NAME] service bus queue successfully created in the [$SERVICE_BUS_NAMESPACE] service bus namespace" else echo "Failed to create [$OUTPUT_QUEUE_NAME] service bus queue in the [$SERVICE_BUS_NAMESPACE] service bus namespace" - exit + exit 1 fi else echo "[$OUTPUT_QUEUE_NAME] service bus queue already exists in the [$SERVICE_BUS_NAMESPACE] service bus namespace" @@ -446,7 +446,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$VIRTUAL_NETWORK_NAME] virtual network in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Update the function app subnet to associate it with the NAT Gateway and the NSG @@ -498,7 +498,7 @@ if [[ $? != 0 ]]; then echo "[$PE_SUBNET_NAME] subnet successfully created in the [$VIRTUAL_NETWORK_NAME] virtual network" else echo "Failed to create [$PE_SUBNET_NAME] subnet in the [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$PE_SUBNET_NAME] subnet already exists in the [$VIRTUAL_NETWORK_NAME] virtual network" @@ -517,7 +517,7 @@ if [[ -n $VIRTUAL_NETWORK_ID ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network resource id retrieved successfully: $VIRTUAL_NETWORK_ID" else echo "Failed to retrieve [$VIRTUAL_NETWORK_NAME] virtual network resource id in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Create private DNS zones and virtual network links @@ -544,7 +544,7 @@ for DNS_ZONE_NAME in "${PRIVATE_DNS_ZONE_NAMES[@]}"; do echo "[$DNS_ZONE_NAME] private DNS zone successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$DNS_ZONE_NAME] private DNS zone in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "[$DNS_ZONE_NAME] private DNS zone already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -575,7 +575,7 @@ for DNS_ZONE_NAME in "${PRIVATE_DNS_ZONE_NAMES[@]}"; do echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network successfully created" else echo "Failed to create [$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network already exists" @@ -683,7 +683,7 @@ for i in "${!PE_NAMES[@]}"; do echo "Private endpoint [$PE_NAME] successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create private endpoint [$PE_NAME] in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "Private endpoint [$PE_NAME] already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -716,7 +716,7 @@ for i in "${!PE_NAMES[@]}"; do echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PE_NAME] private endpoint successfully created" else echo "Failed to create private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PE_NAME] private endpoint" - exit + exit 1 fi else echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PE_NAME] private endpoint already exists" @@ -812,7 +812,7 @@ else echo "Successfully assigned [$ROLE] role to [$MANAGED_IDENTITY_NAME] managed identity on the Service Bus namespace [$SERVICE_BUS_NAMESPACE]" else echo "Failed to assign [$ROLE] role to [$MANAGED_IDENTITY_NAME] managed identity on the Service Bus namespace [$SERVICE_BUS_NAMESPACE]" - exit + exit 1 fi fi @@ -870,7 +870,7 @@ else echo "Successfully assigned [$ROLE] role to [$MANAGED_IDENTITY_NAME] managed identity on the storage account [$STORAGE_ACCOUNT_NAME]" else echo "Failed to assign [$ROLE] role to [$MANAGED_IDENTITY_NAME] managed identity on the storage account [$STORAGE_ACCOUNT_NAME]" - exit + exit 1 fi fi @@ -912,7 +912,7 @@ else echo "Successfully assigned [$ROLE] role to [$MANAGED_IDENTITY_NAME] managed identity on the storage account [$STORAGE_ACCOUNT_NAME]" else echo "Failed to assign [$ROLE] role to [$MANAGED_IDENTITY_NAME] managed identity on the storage account [$STORAGE_ACCOUNT_NAME]" - exit + exit 1 fi fi @@ -954,7 +954,7 @@ else echo "Successfully assigned [$ROLE] role to [$MANAGED_IDENTITY_NAME] managed identity on the storage account [$STORAGE_ACCOUNT_NAME]" else echo "Failed to assign [$ROLE] role to [$MANAGED_IDENTITY_NAME] managed identity on the storage account [$STORAGE_ACCOUNT_NAME]" - exit + exit 1 fi fi @@ -996,7 +996,7 @@ else echo "Successfully assigned [$ROLE] role to [$MANAGED_IDENTITY_NAME] managed identity on the storage account [$STORAGE_ACCOUNT_NAME]" else echo "Failed to assign [$ROLE] role to [$MANAGED_IDENTITY_NAME] managed identity on the storage account [$STORAGE_ACCOUNT_NAME]" - exit + exit 1 fi fi @@ -1038,7 +1038,7 @@ else echo "Successfully assigned [$ROLE] role to [$MANAGED_IDENTITY_NAME] managed identity on the Application Insights [$APPLICATION_INSIGHTS_NAME]" else echo "Failed to assign [$ROLE] role to [$MANAGED_IDENTITY_NAME] managed identity on the Application Insights [$APPLICATION_INSIGHTS_NAME]" - exit + exit 1 fi fi diff --git a/samples/function-app-storage-http/dotnet/bicep/deploy.sh b/samples/function-app-storage-http/dotnet/bicep/deploy.sh index 14407925..113b339a 100755 --- a/samples/function-app-storage-http/dotnet/bicep/deploy.sh +++ b/samples/function-app-storage-http/dotnet/bicep/deploy.sh @@ -31,7 +31,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -53,7 +53,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -70,7 +70,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/servicebus/java/bicep/deploy.sh b/samples/servicebus/java/bicep/deploy.sh index a431ad75..539fc231 100755 --- a/samples/servicebus/java/bicep/deploy.sh +++ b/samples/servicebus/java/bicep/deploy.sh @@ -34,7 +34,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -59,7 +59,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -79,7 +79,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-cosmosdb-mongodb-api/dotnet/bicep/deploy.sh b/samples/web-app-cosmosdb-mongodb-api/dotnet/bicep/deploy.sh index b3681de7..11a28e94 100755 --- a/samples/web-app-cosmosdb-mongodb-api/dotnet/bicep/deploy.sh +++ b/samples/web-app-cosmosdb-mongodb-api/dotnet/bicep/deploy.sh @@ -34,7 +34,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -58,7 +58,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -77,7 +77,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-cosmosdb-mongodb-api/dotnet/scripts/deploy.sh b/samples/web-app-cosmosdb-mongodb-api/dotnet/scripts/deploy.sh index 921f5b79..b9773632 100755 --- a/samples/web-app-cosmosdb-mongodb-api/dotnet/scripts/deploy.sh +++ b/samples/web-app-cosmosdb-mongodb-api/dotnet/scripts/deploy.sh @@ -369,7 +369,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$VIRTUAL_NETWORK_NAME] virtual network in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Update the web app subnet to associate it with the NAT Gateway and the NSG @@ -421,7 +421,7 @@ if [[ $? != 0 ]]; then echo "[$PE_SUBNET_NAME] subnet successfully created in the [$VIRTUAL_NETWORK_NAME] virtual network" else echo "Failed to create [$PE_SUBNET_NAME] subnet in the [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$PE_SUBNET_NAME] subnet already exists in the [$VIRTUAL_NETWORK_NAME] virtual network" @@ -440,7 +440,7 @@ if [[ -n $VIRTUAL_NETWORK_ID ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network resource id retrieved successfully: $VIRTUAL_NETWORK_ID" else echo "Failed to retrieve [$VIRTUAL_NETWORK_NAME] virtual network resource id in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Check if the private DNS Zone already exists @@ -464,7 +464,7 @@ if [[ $? != 0 ]]; then echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$PRIVATE_DNS_ZONE_NAME] private DNS zone in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -496,7 +496,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network successfully created" else echo "Failed to create [$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network already exists" @@ -530,7 +530,7 @@ if [[ -z $privateEndpointId ]]; then echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] successfully created for the [$COSMOSDB_ACCOUNT_NAME] CosmosDB account in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create a private endpoint for the [$COSMOSDB_ACCOUNT_NAME] CosmosDB account in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -563,7 +563,7 @@ if [[ -z $NAME ]]; then echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint successfully created" else echo "Failed to create private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint" - exit + exit 1 fi else echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint already exists" diff --git a/samples/web-app-cosmosdb-mongodb-api/python/bicep/deploy.sh b/samples/web-app-cosmosdb-mongodb-api/python/bicep/deploy.sh index ba06a3b1..6c24d74b 100755 --- a/samples/web-app-cosmosdb-mongodb-api/python/bicep/deploy.sh +++ b/samples/web-app-cosmosdb-mongodb-api/python/bicep/deploy.sh @@ -34,7 +34,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -58,7 +58,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -77,7 +77,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-cosmosdb-mongodb-api/python/scripts/deploy.sh b/samples/web-app-cosmosdb-mongodb-api/python/scripts/deploy.sh index 832f603c..e7ceb628 100755 --- a/samples/web-app-cosmosdb-mongodb-api/python/scripts/deploy.sh +++ b/samples/web-app-cosmosdb-mongodb-api/python/scripts/deploy.sh @@ -369,7 +369,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$VIRTUAL_NETWORK_NAME] virtual network in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Update the web app subnet to associate it with the NAT Gateway and the NSG @@ -421,7 +421,7 @@ if [[ $? != 0 ]]; then echo "[$PE_SUBNET_NAME] subnet successfully created in the [$VIRTUAL_NETWORK_NAME] virtual network" else echo "Failed to create [$PE_SUBNET_NAME] subnet in the [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$PE_SUBNET_NAME] subnet already exists in the [$VIRTUAL_NETWORK_NAME] virtual network" @@ -440,7 +440,7 @@ if [[ -n $VIRTUAL_NETWORK_ID ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network resource id retrieved successfully: $VIRTUAL_NETWORK_ID" else echo "Failed to retrieve [$VIRTUAL_NETWORK_NAME] virtual network resource id in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Check if the private DNS Zone already exists @@ -464,7 +464,7 @@ if [[ $? != 0 ]]; then echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$PRIVATE_DNS_ZONE_NAME] private DNS zone in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -496,7 +496,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network successfully created" else echo "Failed to create [$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network already exists" @@ -530,7 +530,7 @@ if [[ -z $privateEndpointId ]]; then echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] successfully created for the [$COSMOSDB_ACCOUNT_NAME] CosmosDB account in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create a private endpoint for the [$COSMOSDB_ACCOUNT_NAME] CosmosDB account in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -563,7 +563,7 @@ if [[ -z $NAME ]]; then echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint successfully created" else echo "Failed to create private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint" - exit + exit 1 fi else echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint already exists" diff --git a/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/deploy.sh b/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/deploy.sh index ef3049fe..f923c7b4 100755 --- a/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/deploy.sh +++ b/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/deploy.sh @@ -40,71 +40,97 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created." else echo "Failed to create resource group [$RESOURCE_GROUP_NAME]." - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists." fi echo "Create CosmosDB NoSQL Account" - export AZURECOSMOSDB_ENDPOINT=$(az cosmosdb create \ +if ! AZURECOSMOSDB_ENDPOINT=$(az cosmosdb create \ --resource-group $RESOURCE_GROUP_NAME \ --name $WEB_APP_NAME \ --locations regionName=$LOCATION \ --query "documentEndpoint" \ - --output tsv) + --output tsv); then + echo "Failed to create the [$WEB_APP_NAME] Cosmos DB account" + exit 1 +fi +export AZURECOSMOSDB_ENDPOINT echo "Account created" echo "AZURECOSMOSDB_ENDPOINT set to $AZURECOSMOSDB_ENDPOINT" echo "Create CosmosDB NoSQL Database" -az cosmosdb sql database create \ +if ! az cosmosdb sql database create \ --resource-group $RESOURCE_GROUP_NAME \ --name $AZURECOSMOSDB_DATABASENAME \ - --account-name $WEB_APP_NAME + --account-name $WEB_APP_NAME; then + echo "Failed to create the [$AZURECOSMOSDB_DATABASENAME] database in the [$WEB_APP_NAME] Cosmos DB account" + exit 1 +fi echo "Create CosmosDB NoSQL Container" -az cosmosdb sql container create \ +if ! az cosmosdb sql container create \ --resource-group $RESOURCE_GROUP_NAME \ --account-name $WEB_APP_NAME \ --database-name $AZURECOSMOSDB_DATABASENAME \ --name $AZURECOSMOSDB_CONTAINERNAME \ --partition-key-path $AURECOSMOSDB_PARTITION_KEY \ - --throughput 400 + --throughput 400; then + echo "Failed to create the [$AZURECOSMOSDB_CONTAINERNAME] container in the [$AZURECOSMOSDB_DATABASENAME] database" + exit 1 +fi echo "Fetching DB Account primary master key" -export AZURECOSMOSDB_PRIMARY_KEY=$(az cosmosdb keys list \ +if ! AZURECOSMOSDB_PRIMARY_KEY=$(az cosmosdb keys list \ --resource-group $RESOURCE_GROUP_NAME \ --name $WEB_APP_NAME \ --query "primaryMasterKey" \ - --output tsv) + --output tsv); then + echo "Failed to retrieve the primary key of the [$WEB_APP_NAME] Cosmos DB account" + exit 1 +fi +export AZURECOSMOSDB_PRIMARY_KEY echo "Primary master key is $AZURECOSMOSDB_PRIMARY_KEY" echo "Creating App service" -az appservice plan create --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME --sku B1 --is-linux +if ! az appservice plan create --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME --sku B1 --is-linux; then + echo "Failed to create the [$WEB_APP_NAME] App Service plan" + exit 1 +fi echo "App service created" echo "Creating Web App" -az webapp create --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME --plan $WEB_APP_NAME --runtime DOTNETCORE:10.0 +if ! az webapp create --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME --plan $WEB_APP_NAME --runtime DOTNETCORE:10.0; then + echo "Failed to create the [$WEB_APP_NAME] web app" + exit 1 +fi echo "Web App created" echo "Configure appsettings environment variables" -az webapp config appsettings set \ +if ! az webapp config appsettings set \ --resource-group $RESOURCE_GROUP_NAME \ --name $WEB_APP_NAME \ --settings AZURECOSMOSDB_ENDPOINT=$AZURECOSMOSDB_ENDPOINT \ AZURECOSMOSDB_DATABASENAME=$AZURECOSMOSDB_DATABASENAME \ AZURECOSMOSDB_CONTAINERNAME=$AZURECOSMOSDB_CONTAINERNAME \ - AZURECOSMOSDB_PRIMARY_KEY=$AZURECOSMOSDB_PRIMARY_KEY + AZURECOSMOSDB_PRIMARY_KEY=$AZURECOSMOSDB_PRIMARY_KEY; then + echo "Failed to set the application settings of the [$WEB_APP_NAME] web app" + exit 1 +fi # Print the application settings of the web app echo "Retrieving application settings for web app [$WEB_APP_NAME]..." -az webapp config appsettings list \ +if ! az webapp config appsettings list \ --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME + --name $WEB_APP_NAME; then + echo "Failed to retrieve the application settings of the [$WEB_APP_NAME] web app" + exit 1 +fi # Change current directory to source folder -cd "../src" || exit +cd "../src" || exit 1 # Remove any existing zip package of the web app if [ -f "$ZIPFILE" ]; then @@ -113,17 +139,23 @@ fi # Create the zip package of the web app echo "Creating zip package of the web app..." -zip -r "$ZIPFILE" . -x "bin/*" "obj/*" "publish/*" "*.zip" +if ! zip -r "$ZIPFILE" . -x "bin/*" "obj/*" "publish/*" "*.zip"; then + echo "Failed to create the [$ZIPFILE] zip package of the web app" + exit 1 +fi # Deploy the web app echo "Deploying web app [$WEB_APP_NAME] with zip file [$ZIPFILE]..." echo "Using az webapp deploy command for LocalStack emulator environment." -az webapp deploy \ +if ! az webapp deploy \ --resource-group $RESOURCE_GROUP_NAME \ --name $WEB_APP_NAME \ --src-path ${ZIPFILE} \ --type zip \ - --async true + --async true; then + echo "Failed to deploy the [$ZIPFILE] package to the [$WEB_APP_NAME] web app" + exit 1 +fi # Remove the zip package of the web app if [ -f "$ZIPFILE" ]; then diff --git a/samples/web-app-cosmosdb-nosql-api/python/scripts/deploy.sh b/samples/web-app-cosmosdb-nosql-api/python/scripts/deploy.sh index d21700ce..53fa0e1e 100755 --- a/samples/web-app-cosmosdb-nosql-api/python/scripts/deploy.sh +++ b/samples/web-app-cosmosdb-nosql-api/python/scripts/deploy.sh @@ -40,71 +40,97 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created." else echo "Failed to create resource group [$RESOURCE_GROUP_NAME]." - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists." fi echo "Create CosmosDB NoSQL Account" - export AZURECOSMOSDB_ENDPOINT=$(az cosmosdb create \ +if ! AZURECOSMOSDB_ENDPOINT=$(az cosmosdb create \ --resource-group $RESOURCE_GROUP_NAME \ --name $WEB_APP_NAME \ --locations regionName=$LOCATION \ --query "documentEndpoint" \ - --output tsv) + --output tsv); then + echo "Failed to create the [$WEB_APP_NAME] Cosmos DB account" + exit 1 +fi +export AZURECOSMOSDB_ENDPOINT echo "Account created" echo "AZURECOSMOSDB_ENDPOINT set to $AZURECOSMOSDB_ENDPOINT" echo "Create CosmosDB NoSQL Database" -az cosmosdb sql database create \ +if ! az cosmosdb sql database create \ --resource-group $RESOURCE_GROUP_NAME \ --name $AZURECOSMOSDB_DATABASENAME \ - --account-name $WEB_APP_NAME + --account-name $WEB_APP_NAME; then + echo "Failed to create the [$AZURECOSMOSDB_DATABASENAME] database in the [$WEB_APP_NAME] Cosmos DB account" + exit 1 +fi echo "Create CosmosDB NoSQL Container" -az cosmosdb sql container create \ +if ! az cosmosdb sql container create \ --resource-group $RESOURCE_GROUP_NAME \ --account-name $WEB_APP_NAME \ --database-name $AZURECOSMOSDB_DATABASENAME \ --name $AZURECOSMOSDB_CONTAINERNAME \ --partition-key-path $AURECOSMOSDB_PARTITION_KEY \ - --throughput 400 + --throughput 400; then + echo "Failed to create the [$AZURECOSMOSDB_CONTAINERNAME] container in the [$AZURECOSMOSDB_DATABASENAME] database" + exit 1 +fi echo "Fetching DB Account primary master key" -export AZURECOSMOSDB_PRIMARY_KEY=$(az cosmosdb keys list \ +if ! AZURECOSMOSDB_PRIMARY_KEY=$(az cosmosdb keys list \ --resource-group $RESOURCE_GROUP_NAME \ --name $WEB_APP_NAME \ --query "primaryMasterKey" \ - --output tsv) + --output tsv); then + echo "Failed to retrieve the primary key of the [$WEB_APP_NAME] Cosmos DB account" + exit 1 +fi +export AZURECOSMOSDB_PRIMARY_KEY echo "Primary master key is $AZURECOSMOSDB_PRIMARY_KEY" echo "Creating App service" -az appservice plan create --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME --sku B1 --is-linux +if ! az appservice plan create --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME --sku B1 --is-linux; then + echo "Failed to create the [$WEB_APP_NAME] App Service plan" + exit 1 +fi echo "App service created" echo "Creating Web App" -az webapp create --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME --plan $WEB_APP_NAME --runtime PYTHON:3.13 +if ! az webapp create --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME --plan $WEB_APP_NAME --runtime PYTHON:3.13; then + echo "Failed to create the [$WEB_APP_NAME] web app" + exit 1 +fi echo "Web App created" echo "Configure appsettings environment variables" -az webapp config appsettings set \ +if ! az webapp config appsettings set \ --resource-group $RESOURCE_GROUP_NAME \ --name $WEB_APP_NAME \ --settings AZURECOSMOSDB_ENDPOINT=$AZURECOSMOSDB_ENDPOINT \ AZURECOSMOSDB_DATABASENAME=$AZURECOSMOSDB_DATABASENAME \ AZURECOSMOSDB_CONTAINERNAME=$AZURECOSMOSDB_CONTAINERNAME \ - AZURECOSMOSDB_PRIMARY_KEY=$AZURECOSMOSDB_PRIMARY_KEY + AZURECOSMOSDB_PRIMARY_KEY=$AZURECOSMOSDB_PRIMARY_KEY; then + echo "Failed to set the application settings of the [$WEB_APP_NAME] web app" + exit 1 +fi # Print the application settings of the web app echo "Retrieving application settings for web app [$WEB_APP_NAME]..." -az webapp config appsettings list \ +if ! az webapp config appsettings list \ --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME + --name $WEB_APP_NAME; then + echo "Failed to retrieve the application settings of the [$WEB_APP_NAME] web app" + exit 1 +fi # Change current directory to source folder -cd "../src" || exit +cd "../src" || exit 1 # Remove any existing zip package of the web app if [ -f "$ZIPFILE" ]; then @@ -113,17 +139,23 @@ fi # Create the zip package of the web app echo "Creating zip package of the web app..." -zip -r "$ZIPFILE" app.py cosmosdb_client.py gunicorn.conf.py static templates requirements.txt +if ! zip -r "$ZIPFILE" app.py cosmosdb_client.py gunicorn.conf.py static templates requirements.txt; then + echo "Failed to create the [$ZIPFILE] zip package of the web app" + exit 1 +fi # Deploy the web app echo "Deploying web app [$WEB_APP_NAME] with zip file [$ZIPFILE]..." echo "Using az webapp deploy command for LocalStack emulator environment." -az webapp deploy \ +if ! az webapp deploy \ --resource-group $RESOURCE_GROUP_NAME \ --name $WEB_APP_NAME \ --src-path ${ZIPFILE} \ --type zip \ - --async true + --async true; then + echo "Failed to deploy the [$ZIPFILE] package to the [$WEB_APP_NAME] web app" + exit 1 +fi # Remove the zip package of the web app if [ -f "$ZIPFILE" ]; then diff --git a/samples/web-app-custom-image/dotnet/bicep/deploy.sh b/samples/web-app-custom-image/dotnet/bicep/deploy.sh index e90e37b9..423497e1 100755 --- a/samples/web-app-custom-image/dotnet/bicep/deploy.sh +++ b/samples/web-app-custom-image/dotnet/bicep/deploy.sh @@ -38,7 +38,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -64,7 +64,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$ACR_TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$ACR_TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -83,7 +83,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$ACR_TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi @@ -186,7 +186,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$MAIN_TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$MAIN_TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -209,7 +209,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$MAIN_TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-custom-image/dotnet/scripts/deploy.sh b/samples/web-app-custom-image/dotnet/scripts/deploy.sh index afa6a034..41aed4e2 100755 --- a/samples/web-app-custom-image/dotnet/scripts/deploy.sh +++ b/samples/web-app-custom-image/dotnet/scripts/deploy.sh @@ -488,7 +488,7 @@ if [[ $? != 0 ]]; then echo "[$PE_SUBNET_NAME] subnet successfully created in the [$VIRTUAL_NETWORK_NAME] virtual network" else echo "Failed to create [$PE_SUBNET_NAME] subnet in the [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$PE_SUBNET_NAME] subnet already exists in the [$VIRTUAL_NETWORK_NAME] virtual network" @@ -531,7 +531,7 @@ if [[ $? != 0 ]]; then echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$PRIVATE_DNS_ZONE_NAME] private DNS zone in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -563,7 +563,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network successfully created" else echo "Failed to create [$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network already exists" @@ -597,7 +597,7 @@ if [[ -z $privateEndpointId ]]; then echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] successfully created for the [$ACR_NAME] Azure Container Registry in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create a private endpoint for the [$ACR_NAME] Azure Container Registry in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -630,7 +630,7 @@ if [[ -z $NAME ]]; then echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint successfully created" else echo "Failed to create private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint" - exit + exit 1 fi else echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint already exists" diff --git a/samples/web-app-custom-image/python/bicep/deploy.sh b/samples/web-app-custom-image/python/bicep/deploy.sh index e90e37b9..423497e1 100755 --- a/samples/web-app-custom-image/python/bicep/deploy.sh +++ b/samples/web-app-custom-image/python/bicep/deploy.sh @@ -38,7 +38,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -64,7 +64,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$ACR_TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$ACR_TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -83,7 +83,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$ACR_TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi @@ -186,7 +186,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$MAIN_TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$MAIN_TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -209,7 +209,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$MAIN_TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-custom-image/python/scripts/deploy.sh b/samples/web-app-custom-image/python/scripts/deploy.sh index afa6a034..41aed4e2 100755 --- a/samples/web-app-custom-image/python/scripts/deploy.sh +++ b/samples/web-app-custom-image/python/scripts/deploy.sh @@ -488,7 +488,7 @@ if [[ $? != 0 ]]; then echo "[$PE_SUBNET_NAME] subnet successfully created in the [$VIRTUAL_NETWORK_NAME] virtual network" else echo "Failed to create [$PE_SUBNET_NAME] subnet in the [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$PE_SUBNET_NAME] subnet already exists in the [$VIRTUAL_NETWORK_NAME] virtual network" @@ -531,7 +531,7 @@ if [[ $? != 0 ]]; then echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$PRIVATE_DNS_ZONE_NAME] private DNS zone in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -563,7 +563,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network successfully created" else echo "Failed to create [$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network already exists" @@ -597,7 +597,7 @@ if [[ -z $privateEndpointId ]]; then echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] successfully created for the [$ACR_NAME] Azure Container Registry in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create a private endpoint for the [$ACR_NAME] Azure Container Registry in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -630,7 +630,7 @@ if [[ -z $NAME ]]; then echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint successfully created" else echo "Failed to create private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint" - exit + exit 1 fi else echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint already exists" diff --git a/samples/web-app-managed-identity/dotnet/bicep/deploy.sh b/samples/web-app-managed-identity/dotnet/bicep/deploy.sh index d4cc1981..05d54100 100755 --- a/samples/web-app-managed-identity/dotnet/bicep/deploy.sh +++ b/samples/web-app-managed-identity/dotnet/bicep/deploy.sh @@ -35,7 +35,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -60,7 +60,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -80,7 +80,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-managed-identity/dotnet/scripts/api.sh b/samples/web-app-managed-identity/dotnet/scripts/api.sh index c11db535..3106622b 100755 --- a/samples/web-app-managed-identity/dotnet/scripts/api.sh +++ b/samples/web-app-managed-identity/dotnet/scripts/api.sh @@ -41,7 +41,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" diff --git a/samples/web-app-managed-identity/dotnet/scripts/cli.sh b/samples/web-app-managed-identity/dotnet/scripts/cli.sh index af19a3f0..2052c6ea 100755 --- a/samples/web-app-managed-identity/dotnet/scripts/cli.sh +++ b/samples/web-app-managed-identity/dotnet/scripts/cli.sh @@ -27,7 +27,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" diff --git a/samples/web-app-managed-identity/dotnet/scripts/system-assigned.sh b/samples/web-app-managed-identity/dotnet/scripts/system-assigned.sh index eec215f2..b15d8e8e 100755 --- a/samples/web-app-managed-identity/dotnet/scripts/system-assigned.sh +++ b/samples/web-app-managed-identity/dotnet/scripts/system-assigned.sh @@ -39,7 +39,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -215,7 +215,7 @@ else echo "Successfully assigned [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" else echo "Failed to assign [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" - exit + exit 1 fi fi diff --git a/samples/web-app-managed-identity/dotnet/scripts/user-assigned.sh b/samples/web-app-managed-identity/dotnet/scripts/user-assigned.sh index 014aad18..23d24e57 100755 --- a/samples/web-app-managed-identity/dotnet/scripts/user-assigned.sh +++ b/samples/web-app-managed-identity/dotnet/scripts/user-assigned.sh @@ -41,7 +41,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -298,7 +298,7 @@ else echo "Successfully assigned [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" else echo "Failed to assign [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" - exit + exit 1 fi fi diff --git a/samples/web-app-managed-identity/python/bicep/deploy.sh b/samples/web-app-managed-identity/python/bicep/deploy.sh index cc9020f7..9d5ee5d6 100755 --- a/samples/web-app-managed-identity/python/bicep/deploy.sh +++ b/samples/web-app-managed-identity/python/bicep/deploy.sh @@ -35,7 +35,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -60,7 +60,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -80,7 +80,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-managed-identity/python/scripts/api.sh b/samples/web-app-managed-identity/python/scripts/api.sh index c11db535..3106622b 100755 --- a/samples/web-app-managed-identity/python/scripts/api.sh +++ b/samples/web-app-managed-identity/python/scripts/api.sh @@ -41,7 +41,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" diff --git a/samples/web-app-managed-identity/python/scripts/cli.sh b/samples/web-app-managed-identity/python/scripts/cli.sh index af19a3f0..2052c6ea 100755 --- a/samples/web-app-managed-identity/python/scripts/cli.sh +++ b/samples/web-app-managed-identity/python/scripts/cli.sh @@ -27,7 +27,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" diff --git a/samples/web-app-managed-identity/python/scripts/system-assigned.sh b/samples/web-app-managed-identity/python/scripts/system-assigned.sh index ca2facde..587c8699 100755 --- a/samples/web-app-managed-identity/python/scripts/system-assigned.sh +++ b/samples/web-app-managed-identity/python/scripts/system-assigned.sh @@ -39,7 +39,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -215,7 +215,7 @@ else echo "Successfully assigned [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" else echo "Failed to assign [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" - exit + exit 1 fi fi diff --git a/samples/web-app-managed-identity/python/scripts/user-assigned.sh b/samples/web-app-managed-identity/python/scripts/user-assigned.sh index b50054dd..d9ed8a21 100755 --- a/samples/web-app-managed-identity/python/scripts/user-assigned.sh +++ b/samples/web-app-managed-identity/python/scripts/user-assigned.sh @@ -41,7 +41,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -298,7 +298,7 @@ else echo "Successfully assigned [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" else echo "Failed to assign [$ROLE] role to managed identity on storage account [$STORAGE_ACCOUNT_NAME]" - exit + exit 1 fi fi diff --git a/samples/web-app-mysql-flexible-server/dotnet/bicep/deploy.sh b/samples/web-app-mysql-flexible-server/dotnet/bicep/deploy.sh index 48ba9a19..57bd2df9 100755 --- a/samples/web-app-mysql-flexible-server/dotnet/bicep/deploy.sh +++ b/samples/web-app-mysql-flexible-server/dotnet/bicep/deploy.sh @@ -49,7 +49,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -74,7 +74,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -94,7 +94,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-mysql-flexible-server/dotnet/scripts/deploy.sh b/samples/web-app-mysql-flexible-server/dotnet/scripts/deploy.sh index 6ec74f49..6f5f4ca1 100755 --- a/samples/web-app-mysql-flexible-server/dotnet/scripts/deploy.sh +++ b/samples/web-app-mysql-flexible-server/dotnet/scripts/deploy.sh @@ -407,7 +407,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$VIRTUAL_NETWORK_NAME] virtual network in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Update the web app subnet to associate it with the NAT Gateway and the NSG @@ -459,7 +459,7 @@ if [[ $? != 0 ]]; then echo "[$PE_SUBNET_NAME] subnet successfully created in the [$VIRTUAL_NETWORK_NAME] virtual network" else echo "Failed to create [$PE_SUBNET_NAME] subnet in the [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$PE_SUBNET_NAME] subnet already exists in the [$VIRTUAL_NETWORK_NAME] virtual network" @@ -478,7 +478,7 @@ if [[ -n $VIRTUAL_NETWORK_ID ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network resource id retrieved successfully: $VIRTUAL_NETWORK_ID" else echo "Failed to retrieve [$VIRTUAL_NETWORK_NAME] virtual network resource id in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Check if the private DNS Zone already exists @@ -503,7 +503,7 @@ if [[ $? != 0 ]]; then echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$PRIVATE_DNS_ZONE_NAME] private DNS zone in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -535,7 +535,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network successfully created" else echo "Failed to create [$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network already exists" @@ -570,7 +570,7 @@ if [[ -z $privateEndpointId ]]; then echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] successfully created for the [$MYSQL_SERVER_NAME] MySQL flexible server in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create a private endpoint for the [$MYSQL_SERVER_NAME] MySQL flexible server in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -603,7 +603,7 @@ if [[ -z $NAME ]]; then echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint successfully created" else echo "Failed to create private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint" - exit + exit 1 fi else echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint already exists" diff --git a/samples/web-app-mysql-flexible-server/python/bicep/deploy.sh b/samples/web-app-mysql-flexible-server/python/bicep/deploy.sh index 556c63b2..47bcb2f0 100755 --- a/samples/web-app-mysql-flexible-server/python/bicep/deploy.sh +++ b/samples/web-app-mysql-flexible-server/python/bicep/deploy.sh @@ -49,7 +49,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -74,7 +74,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -94,7 +94,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-mysql-flexible-server/python/scripts/deploy.sh b/samples/web-app-mysql-flexible-server/python/scripts/deploy.sh index f4c35e73..2203f96e 100755 --- a/samples/web-app-mysql-flexible-server/python/scripts/deploy.sh +++ b/samples/web-app-mysql-flexible-server/python/scripts/deploy.sh @@ -407,7 +407,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$VIRTUAL_NETWORK_NAME] virtual network in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Update the web app subnet to associate it with the NAT Gateway and the NSG @@ -459,7 +459,7 @@ if [[ $? != 0 ]]; then echo "[$PE_SUBNET_NAME] subnet successfully created in the [$VIRTUAL_NETWORK_NAME] virtual network" else echo "Failed to create [$PE_SUBNET_NAME] subnet in the [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$PE_SUBNET_NAME] subnet already exists in the [$VIRTUAL_NETWORK_NAME] virtual network" @@ -478,7 +478,7 @@ if [[ -n $VIRTUAL_NETWORK_ID ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network resource id retrieved successfully: $VIRTUAL_NETWORK_ID" else echo "Failed to retrieve [$VIRTUAL_NETWORK_NAME] virtual network resource id in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Check if the private DNS Zone already exists @@ -503,7 +503,7 @@ if [[ $? != 0 ]]; then echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$PRIVATE_DNS_ZONE_NAME] private DNS zone in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -535,7 +535,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network successfully created" else echo "Failed to create [$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network already exists" @@ -570,7 +570,7 @@ if [[ -z $privateEndpointId ]]; then echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] successfully created for the [$MYSQL_SERVER_NAME] MySQL flexible server in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create a private endpoint for the [$MYSQL_SERVER_NAME] MySQL flexible server in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -603,7 +603,7 @@ if [[ -z $NAME ]]; then echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint successfully created" else echo "Failed to create private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint" - exit + exit 1 fi else echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint already exists" diff --git a/samples/web-app-postgresql-flexible-server/dotnet/bicep/deploy.sh b/samples/web-app-postgresql-flexible-server/dotnet/bicep/deploy.sh index 6391c139..ff9750b8 100755 --- a/samples/web-app-postgresql-flexible-server/dotnet/bicep/deploy.sh +++ b/samples/web-app-postgresql-flexible-server/dotnet/bicep/deploy.sh @@ -38,7 +38,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -63,7 +63,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -83,7 +83,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-postgresql-flexible-server/dotnet/scripts/deploy.sh b/samples/web-app-postgresql-flexible-server/dotnet/scripts/deploy.sh index 275044e4..62040045 100755 --- a/samples/web-app-postgresql-flexible-server/dotnet/scripts/deploy.sh +++ b/samples/web-app-postgresql-flexible-server/dotnet/scripts/deploy.sh @@ -396,7 +396,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$VIRTUAL_NETWORK_NAME] virtual network in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Update the web app subnet to associate it with the NAT Gateway and the NSG @@ -448,7 +448,7 @@ if [[ $? != 0 ]]; then echo "[$PE_SUBNET_NAME] subnet successfully created in the [$VIRTUAL_NETWORK_NAME] virtual network" else echo "Failed to create [$PE_SUBNET_NAME] subnet in the [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$PE_SUBNET_NAME] subnet already exists in the [$VIRTUAL_NETWORK_NAME] virtual network" @@ -467,7 +467,7 @@ if [[ -n $VIRTUAL_NETWORK_ID ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network resource id retrieved successfully: $VIRTUAL_NETWORK_ID" else echo "Failed to retrieve [$VIRTUAL_NETWORK_NAME] virtual network resource id in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Check if the private DNS Zone already exists @@ -492,7 +492,7 @@ if [[ $? != 0 ]]; then echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$PRIVATE_DNS_ZONE_NAME] private DNS zone in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -524,7 +524,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network successfully created" else echo "Failed to create [$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network already exists" @@ -559,7 +559,7 @@ if [[ -z $privateEndpointId ]]; then echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] successfully created for the [$POSTGRES_SERVER_NAME] PostgreSQL flexible server in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create a private endpoint for the [$POSTGRES_SERVER_NAME] PostgreSQL flexible server in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -592,7 +592,7 @@ if [[ -z $NAME ]]; then echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint successfully created" else echo "Failed to create private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint" - exit + exit 1 fi else echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint already exists" diff --git a/samples/web-app-postgresql-flexible-server/python/bicep/deploy.sh b/samples/web-app-postgresql-flexible-server/python/bicep/deploy.sh index 84146aa3..fedd6e13 100755 --- a/samples/web-app-postgresql-flexible-server/python/bicep/deploy.sh +++ b/samples/web-app-postgresql-flexible-server/python/bicep/deploy.sh @@ -38,7 +38,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -63,7 +63,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -83,7 +83,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-postgresql-flexible-server/python/scripts/deploy.sh b/samples/web-app-postgresql-flexible-server/python/scripts/deploy.sh index 01a75117..e3fe497e 100755 --- a/samples/web-app-postgresql-flexible-server/python/scripts/deploy.sh +++ b/samples/web-app-postgresql-flexible-server/python/scripts/deploy.sh @@ -396,7 +396,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$VIRTUAL_NETWORK_NAME] virtual network in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Update the web app subnet to associate it with the NAT Gateway and the NSG @@ -448,7 +448,7 @@ if [[ $? != 0 ]]; then echo "[$PE_SUBNET_NAME] subnet successfully created in the [$VIRTUAL_NETWORK_NAME] virtual network" else echo "Failed to create [$PE_SUBNET_NAME] subnet in the [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$PE_SUBNET_NAME] subnet already exists in the [$VIRTUAL_NETWORK_NAME] virtual network" @@ -467,7 +467,7 @@ if [[ -n $VIRTUAL_NETWORK_ID ]]; then echo "[$VIRTUAL_NETWORK_NAME] virtual network resource id retrieved successfully: $VIRTUAL_NETWORK_ID" else echo "Failed to retrieve [$VIRTUAL_NETWORK_NAME] virtual network resource id in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi # Check if the private DNS Zone already exists @@ -492,7 +492,7 @@ if [[ $? != 0 ]]; then echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$PRIVATE_DNS_ZONE_NAME] private DNS zone in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "[$PRIVATE_DNS_ZONE_NAME] private DNS zone already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -524,7 +524,7 @@ if [[ $? != 0 ]]; then echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network successfully created" else echo "Failed to create [$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network" - exit + exit 1 fi else echo "[$VIRTUAL_NETWORK_LINK_NAME] virtual network link between [$PRIVATE_DNS_ZONE_NAME] private DNS zone and [$VIRTUAL_NETWORK_NAME] virtual network already exists" @@ -559,7 +559,7 @@ if [[ -z $privateEndpointId ]]; then echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] successfully created for the [$POSTGRES_SERVER_NAME] PostgreSQL flexible server in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create a private endpoint for the [$POSTGRES_SERVER_NAME] PostgreSQL flexible server in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi else echo "Private endpoint [$PRIVATE_ENDPOINT_NAME] already exists in the [$RESOURCE_GROUP_NAME] resource group" @@ -592,7 +592,7 @@ if [[ -z $NAME ]]; then echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint successfully created" else echo "Failed to create private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint" - exit + exit 1 fi else echo "Private DNS zone group [$PRIVATE_DNS_ZONE_GROUP_NAME] for the [$PRIVATE_ENDPOINT_NAME] private endpoint already exists" diff --git a/samples/web-app-sql-database/dotnet/bicep/deploy.sh b/samples/web-app-sql-database/dotnet/bicep/deploy.sh index 2ae5eac9..162dc1b0 100755 --- a/samples/web-app-sql-database/dotnet/bicep/deploy.sh +++ b/samples/web-app-sql-database/dotnet/bicep/deploy.sh @@ -38,7 +38,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -66,7 +66,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -89,7 +89,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-sql-database/dotnet/scripts/deploy.sh b/samples/web-app-sql-database/dotnet/scripts/deploy.sh index 4e3d4408..2f033e33 100755 --- a/samples/web-app-sql-database/dotnet/scripts/deploy.sh +++ b/samples/web-app-sql-database/dotnet/scripts/deploy.sh @@ -105,7 +105,7 @@ else echo "[$SQL_SERVER_NAME] sql server successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$SQL_SERVER_NAME] sql server in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi fi diff --git a/samples/web-app-sql-database/python/bicep/deploy.sh b/samples/web-app-sql-database/python/bicep/deploy.sh index f3b6de11..6f582545 100755 --- a/samples/web-app-sql-database/python/bicep/deploy.sh +++ b/samples/web-app-sql-database/python/bicep/deploy.sh @@ -38,7 +38,7 @@ if [[ $? != 0 ]]; then echo "Resource group [$RESOURCE_GROUP_NAME] successfully created in the subscription [$SUBSCRIPTION_NAME]" else echo "Failed to create resource group [$RESOURCE_GROUP_NAME] in the subscription [$SUBSCRIPTION_NAME]" - exit + exit 1 fi else echo "Resource group [$RESOURCE_GROUP_NAME] already exists in the subscription [$SUBSCRIPTION_NAME]" @@ -66,7 +66,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then echo "Bicep template [$TEMPLATE] validation succeeded" else echo "Failed to validate Bicep template [$TEMPLATE]" - exit + exit 1 fi else # Validate the Bicep template @@ -89,7 +89,7 @@ if [[ $VALIDATE_TEMPLATE == 1 ]]; then else echo "Failed to validate Bicep template [$TEMPLATE]" echo "$output" - exit + exit 1 fi fi fi diff --git a/samples/web-app-sql-database/python/scripts/deploy.sh b/samples/web-app-sql-database/python/scripts/deploy.sh index 35e080b9..62e7c442 100755 --- a/samples/web-app-sql-database/python/scripts/deploy.sh +++ b/samples/web-app-sql-database/python/scripts/deploy.sh @@ -105,7 +105,7 @@ else echo "[$SQL_SERVER_NAME] sql server successfully created in the [$RESOURCE_GROUP_NAME] resource group" else echo "Failed to create [$SQL_SERVER_NAME] sql server in the [$RESOURCE_GROUP_NAME] resource group" - exit + exit 1 fi fi From 7f686b62559bf42b9642c78bc183871fb54105aa Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Thu, 29 Oct 2026 14:55:23 +0100 Subject: [PATCH 3/9] Write the new checks in the samples' own style The checks added to the Cosmos DB NoSQL and Container Apps scripts used a pattern these scripts do not use (if ! cmd). They now follow the samples' own: the command, then if [[ $? == 0 ]] with a success message, else a "Failed to ..." message naming the resource in brackets and exit 1; a captured value is tested with if [[ -n $VAR ]], and a Docker or Terraform step with if [[ $? != 0 ]] as the same file already tests its build and apply. The Terraform outputs are read as before: the apply that produces them is checked, and principal_id is empty by design without a managed identity. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FvNuJJpEr2yMWrV5cbJi2Z --- .../python/bicep/deploy.sh | 52 ++++-- .../python/terraform/deploy.sh | 146 ++++++++------- .../dotnet/scripts/deploy.sh | 174 +++++++++++------- .../python/scripts/deploy.sh | 174 +++++++++++------- 4 files changed, 332 insertions(+), 214 deletions(-) diff --git a/samples/container-apps-blob-storage/python/bicep/deploy.sh b/samples/container-apps-blob-storage/python/bicep/deploy.sh index ae4365fa..e2b8a7d7 100644 --- a/samples/container-apps-blob-storage/python/bicep/deploy.sh +++ b/samples/container-apps-blob-storage/python/bicep/deploy.sh @@ -57,44 +57,60 @@ fi # Create ACR first so we can push the image ACR_NAME="${PREFIX}acaacr${SUFFIX}" echo "Creating ACR [$ACR_NAME] for image push..." -if ! az acr create \ +az acr create \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --location "$LOCATION" \ --sku Basic \ --admin-enabled true \ - --only-show-errors 1>/dev/null; then - echo "Failed to create ACR [$ACR_NAME]." + --only-show-errors 1>/dev/null + +if [[ $? == 0 ]]; then + echo "[$ACR_NAME] container registry successfully created in the [$RESOURCE_GROUP_NAME] resource group" +else + echo "Failed to create [$ACR_NAME] container registry in the [$RESOURCE_GROUP_NAME] resource group" exit 1 fi -if ! LOGIN_SERVER=$(az acr show \ +LOGIN_SERVER=$(az acr show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --query "loginServer" \ --output tsv \ - --only-show-errors); then - echo "Failed to retrieve the login server of ACR [$ACR_NAME]." + --only-show-errors) + +if [[ -n $LOGIN_SERVER ]]; then + echo "Successfully retrieved the login server of the [$ACR_NAME] container registry" +else + echo "Failed to retrieve the login server of the [$ACR_NAME] container registry" exit 1 fi -if ! ACR_USERNAME=$(az acr credential show \ +ACR_USERNAME=$(az acr credential show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --query "username" \ --output tsv \ - --only-show-errors); then - echo "Failed to retrieve the admin username of ACR [$ACR_NAME]." + --only-show-errors) + +if [[ -n $ACR_USERNAME ]]; then + echo "Successfully retrieved the admin username of the [$ACR_NAME] container registry" +else + echo "Failed to retrieve the admin username of the [$ACR_NAME] container registry" exit 1 fi -if ! ACR_PASSWORD=$(az acr credential show \ +ACR_PASSWORD=$(az acr credential show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --query "passwords[0].value" \ --output tsv \ - --only-show-errors); then - echo "Failed to retrieve the admin password of ACR [$ACR_NAME]." + --only-show-errors) + +if [[ -n $ACR_PASSWORD ]]; then + echo "Successfully retrieved the admin password of the [$ACR_NAME] container registry" +else + echo "Failed to retrieve the admin password of the [$ACR_NAME] container registry" exit 1 fi @@ -108,14 +124,18 @@ if [[ $? != 0 ]]; then exit 1 fi -if ! docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "$FULL_IMAGE"; then - echo "Failed to tag Docker image [$IMAGE_NAME:$IMAGE_TAG] as [$FULL_IMAGE]." +docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "$FULL_IMAGE" + +if [[ $? != 0 ]]; then + echo "Failed to tag Docker image." exit 1 fi echo "Logging in to ACR [$LOGIN_SERVER]..." -if ! echo "$ACR_PASSWORD" | docker login "$LOGIN_SERVER" --username "$ACR_USERNAME" --password-stdin 2>/dev/null; then - echo "Failed to log in to ACR [$LOGIN_SERVER]." +echo "$ACR_PASSWORD" | docker login "$LOGIN_SERVER" --username "$ACR_USERNAME" --password-stdin 2>/dev/null + +if [[ $? != 0 ]]; then + echo "Failed to log in to ACR." exit 1 fi diff --git a/samples/container-apps-blob-storage/python/terraform/deploy.sh b/samples/container-apps-blob-storage/python/terraform/deploy.sh index 38b48940..f2a89c8a 100644 --- a/samples/container-apps-blob-storage/python/terraform/deploy.sh +++ b/samples/container-apps-blob-storage/python/terraform/deploy.sh @@ -22,53 +22,73 @@ RESOURCE_GROUP_NAME="${PREFIX}-aca-rg" ACR_NAME="${PREFIX}acaacr${SUFFIX}" echo "Creating resource group [$RESOURCE_GROUP_NAME]..." -if ! az group create \ +az group create \ --name "$RESOURCE_GROUP_NAME" \ --location "$LOCATION" \ - --only-show-errors 1>/dev/null; then - echo "Failed to create resource group [$RESOURCE_GROUP_NAME]." + --only-show-errors 1>/dev/null + +if [[ $? == 0 ]]; then + echo "[$RESOURCE_GROUP_NAME] resource group successfully created" +else + echo "Failed to create [$RESOURCE_GROUP_NAME] resource group" exit 1 fi echo "Creating ACR [$ACR_NAME] for image push..." -if ! az acr create \ +az acr create \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --location "$LOCATION" \ --sku Basic \ --admin-enabled true \ - --only-show-errors 1>/dev/null; then - echo "Failed to create ACR [$ACR_NAME]." + --only-show-errors 1>/dev/null + +if [[ $? == 0 ]]; then + echo "[$ACR_NAME] container registry successfully created in the [$RESOURCE_GROUP_NAME] resource group" +else + echo "Failed to create [$ACR_NAME] container registry in the [$RESOURCE_GROUP_NAME] resource group" exit 1 fi -if ! LOGIN_SERVER=$(az acr show \ +LOGIN_SERVER=$(az acr show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --query "loginServer" \ --output tsv \ - --only-show-errors); then - echo "Failed to retrieve the login server of ACR [$ACR_NAME]." + --only-show-errors) + +if [[ -n $LOGIN_SERVER ]]; then + echo "Successfully retrieved the login server of the [$ACR_NAME] container registry" +else + echo "Failed to retrieve the login server of the [$ACR_NAME] container registry" exit 1 fi -if ! ACR_USERNAME=$(az acr credential show \ +ACR_USERNAME=$(az acr credential show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --query "username" \ --output tsv \ - --only-show-errors); then - echo "Failed to retrieve the admin username of ACR [$ACR_NAME]." + --only-show-errors) + +if [[ -n $ACR_USERNAME ]]; then + echo "Successfully retrieved the admin username of the [$ACR_NAME] container registry" +else + echo "Failed to retrieve the admin username of the [$ACR_NAME] container registry" exit 1 fi -if ! ACR_PASSWORD=$(az acr credential show \ +ACR_PASSWORD=$(az acr credential show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ --query "passwords[0].value" \ --output tsv \ - --only-show-errors); then - echo "Failed to retrieve the admin password of ACR [$ACR_NAME]." + --only-show-errors) + +if [[ -n $ACR_PASSWORD ]]; then + echo "Successfully retrieved the admin password of the [$ACR_NAME] container registry" +else + echo "Failed to retrieve the admin password of the [$ACR_NAME] container registry" exit 1 fi @@ -82,14 +102,18 @@ if [[ $? != 0 ]]; then exit 1 fi -if ! docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "$FULL_IMAGE"; then - echo "Failed to tag Docker image [$IMAGE_NAME:$IMAGE_TAG] as [$FULL_IMAGE]." +docker tag "${IMAGE_NAME}:${IMAGE_TAG}" "$FULL_IMAGE" + +if [[ $? != 0 ]]; then + echo "Failed to tag Docker image." exit 1 fi echo "Logging in to ACR [$LOGIN_SERVER]..." -if ! echo "$ACR_PASSWORD" | docker login "$LOGIN_SERVER" --username "$ACR_USERNAME" --password-stdin 2>/dev/null; then - echo "Failed to log in to ACR [$LOGIN_SERVER]." +echo "$ACR_PASSWORD" | docker login "$LOGIN_SERVER" --username "$ACR_USERNAME" --password-stdin 2>/dev/null + +if [[ $? != 0 ]]; then + echo "Failed to log in to ACR." exit 1 fi @@ -107,38 +131,49 @@ echo "Image pushed to ACR successfully." # ============================================================================= echo "Initializing Terraform..." -if ! terraform init -upgrade; then - echo "Failed to initialize Terraform." +terraform init -upgrade + +if [[ $? != 0 ]]; then + echo "Terraform init failed. Exiting." exit 1 fi -# Import the resource group that was pre-created for the image push +# Import the resource group that was pre-created for the image push, unless a previous run already did echo "Importing pre-created resource group into Terraform state..." -# A re-run finds the group in the state already, and import refuses it; every other failure stops the deploy. -if terraform state show azurerm_resource_group.example >/dev/null 2>&1; then - echo "Resource group [$RESOURCE_GROUP_NAME] is already in the Terraform state." -elif ! terraform import \ - -var "prefix=$PREFIX" \ - -var "suffix=$SUFFIX" \ - -var "location=$LOCATION" \ - -var "image_name=$IMAGE_NAME" \ - -var "image_tag=$IMAGE_TAG" \ - -var "managed_identity_type=$MANAGED_IDENTITY_TYPE" \ - azurerm_resource_group.example \ - "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/${RESOURCE_GROUP_NAME}"; then - echo "Failed to import resource group [$RESOURCE_GROUP_NAME] into the Terraform state." - exit 1 +terraform state show azurerm_resource_group.example &>/dev/null + +if [[ $? == 0 ]]; then + echo "[$RESOURCE_GROUP_NAME] resource group already exists in the Terraform state" +else + terraform import \ + -var "prefix=$PREFIX" \ + -var "suffix=$SUFFIX" \ + -var "location=$LOCATION" \ + -var "image_name=$IMAGE_NAME" \ + -var "image_tag=$IMAGE_TAG" \ + -var "managed_identity_type=$MANAGED_IDENTITY_TYPE" \ + azurerm_resource_group.example \ + "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/${RESOURCE_GROUP_NAME}" + + if [[ $? == 0 ]]; then + echo "[$RESOURCE_GROUP_NAME] resource group successfully imported into the Terraform state" + else + echo "Failed to import [$RESOURCE_GROUP_NAME] resource group into the Terraform state" + exit 1 + fi fi # Run terraform plan and check for errors echo "Planning Terraform deployment..." -if ! terraform plan -out=tfplan \ +terraform plan -out=tfplan \ -var "prefix=$PREFIX" \ -var "suffix=$SUFFIX" \ -var "location=$LOCATION" \ -var "image_name=$IMAGE_NAME" \ -var "image_tag=$IMAGE_TAG" \ - -var "managed_identity_type=$MANAGED_IDENTITY_TYPE"; then + -var "managed_identity_type=$MANAGED_IDENTITY_TYPE" + +if [[ $? != 0 ]]; then echo "Terraform plan failed. Exiting." exit 1 fi @@ -153,34 +188,13 @@ if [[ $? != 0 ]]; then fi # Get the output values -if ! RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name); then - echo "Failed to read the Terraform output [resource_group_name]." - exit 1 -fi -if ! STORAGE_ACCOUNT_NAME=$(terraform output -raw storage_account_name); then - echo "Failed to read the Terraform output [storage_account_name]." - exit 1 -fi -if ! ACR_NAME=$(terraform output -raw acr_name); then - echo "Failed to read the Terraform output [acr_name]." - exit 1 -fi -if ! ENVIRONMENT_NAME=$(terraform output -raw environment_name); then - echo "Failed to read the Terraform output [environment_name]." - exit 1 -fi -if ! APP_NAME=$(terraform output -raw app_name); then - echo "Failed to read the Terraform output [app_name]." - exit 1 -fi -if ! FQDN=$(terraform output -raw fqdn); then - echo "Failed to read the Terraform output [fqdn]." - exit 1 -fi -if ! PRINCIPAL_ID=$(terraform output -raw principal_id); then - echo "Failed to read the Terraform output [principal_id]." - exit 1 -fi +RESOURCE_GROUP_NAME=$(terraform output -raw resource_group_name) +STORAGE_ACCOUNT_NAME=$(terraform output -raw storage_account_name) +ACR_NAME=$(terraform output -raw acr_name) +ENVIRONMENT_NAME=$(terraform output -raw environment_name) +APP_NAME=$(terraform output -raw app_name) +FQDN=$(terraform output -raw fqdn) +PRINCIPAL_ID=$(terraform output -raw principal_id) echo "" echo "============================================================" diff --git a/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/deploy.sh b/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/deploy.sh index f923c7b4..e6823026 100755 --- a/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/deploy.sh +++ b/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/deploy.sh @@ -46,91 +46,132 @@ else echo "Resource group [$RESOURCE_GROUP_NAME] already exists." fi -echo "Create CosmosDB NoSQL Account" -if ! AZURECOSMOSDB_ENDPOINT=$(az cosmosdb create \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --locations regionName=$LOCATION \ - --query "documentEndpoint" \ - --output tsv); then - echo "Failed to create the [$WEB_APP_NAME] Cosmos DB account" +# Create the Cosmos DB account +echo "Creating [$WEB_APP_NAME] Cosmos DB account in the [$RESOURCE_GROUP_NAME] resource group..." +AZURECOSMOSDB_ENDPOINT=$(az cosmosdb create \ + --resource-group $RESOURCE_GROUP_NAME \ + --name $WEB_APP_NAME \ + --locations regionName=$LOCATION \ + --query "documentEndpoint" \ + --output tsv) + +if [[ -n $AZURECOSMOSDB_ENDPOINT ]]; then + echo "[$WEB_APP_NAME] Cosmos DB account successfully created in the [$RESOURCE_GROUP_NAME] resource group" + echo "AZURECOSMOSDB_ENDPOINT set to $AZURECOSMOSDB_ENDPOINT" +else + echo "Failed to create [$WEB_APP_NAME] Cosmos DB account in the [$RESOURCE_GROUP_NAME] resource group" exit 1 fi export AZURECOSMOSDB_ENDPOINT -echo "Account created" -echo "AZURECOSMOSDB_ENDPOINT set to $AZURECOSMOSDB_ENDPOINT" +# Create the Cosmos DB database +echo "Creating [$AZURECOSMOSDB_DATABASENAME] database in the [$WEB_APP_NAME] Cosmos DB account..." +az cosmosdb sql database create \ + --resource-group $RESOURCE_GROUP_NAME \ + --name $AZURECOSMOSDB_DATABASENAME \ + --account-name $WEB_APP_NAME \ + --only-show-errors 1>/dev/null -echo "Create CosmosDB NoSQL Database" -if ! az cosmosdb sql database create \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $AZURECOSMOSDB_DATABASENAME \ - --account-name $WEB_APP_NAME; then - echo "Failed to create the [$AZURECOSMOSDB_DATABASENAME] database in the [$WEB_APP_NAME] Cosmos DB account" +if [[ $? == 0 ]]; then + echo "[$AZURECOSMOSDB_DATABASENAME] database successfully created in the [$WEB_APP_NAME] Cosmos DB account" +else + echo "Failed to create [$AZURECOSMOSDB_DATABASENAME] database in the [$WEB_APP_NAME] Cosmos DB account" exit 1 fi -echo "Create CosmosDB NoSQL Container" -if ! az cosmosdb sql container create \ - --resource-group $RESOURCE_GROUP_NAME \ - --account-name $WEB_APP_NAME \ - --database-name $AZURECOSMOSDB_DATABASENAME \ - --name $AZURECOSMOSDB_CONTAINERNAME \ - --partition-key-path $AURECOSMOSDB_PARTITION_KEY \ - --throughput 400; then - echo "Failed to create the [$AZURECOSMOSDB_CONTAINERNAME] container in the [$AZURECOSMOSDB_DATABASENAME] database" +# Create the Cosmos DB container +echo "Creating [$AZURECOSMOSDB_CONTAINERNAME] container in the [$AZURECOSMOSDB_DATABASENAME] database..." +az cosmosdb sql container create \ + --resource-group $RESOURCE_GROUP_NAME \ + --account-name $WEB_APP_NAME \ + --database-name $AZURECOSMOSDB_DATABASENAME \ + --name $AZURECOSMOSDB_CONTAINERNAME \ + --partition-key-path $AURECOSMOSDB_PARTITION_KEY \ + --throughput 400 \ + --only-show-errors 1>/dev/null + +if [[ $? == 0 ]]; then + echo "[$AZURECOSMOSDB_CONTAINERNAME] container successfully created in the [$AZURECOSMOSDB_DATABASENAME] database" +else + echo "Failed to create [$AZURECOSMOSDB_CONTAINERNAME] container in the [$AZURECOSMOSDB_DATABASENAME] database" exit 1 fi -echo "Fetching DB Account primary master key" -if ! AZURECOSMOSDB_PRIMARY_KEY=$(az cosmosdb keys list \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --query "primaryMasterKey" \ - --output tsv); then +# Retrieve the primary key of the Cosmos DB account +echo "Retrieving the primary key of the [$WEB_APP_NAME] Cosmos DB account..." +AZURECOSMOSDB_PRIMARY_KEY=$(az cosmosdb keys list \ + --resource-group $RESOURCE_GROUP_NAME \ + --name $WEB_APP_NAME \ + --query "primaryMasterKey" \ + --output tsv) + +if [[ -n $AZURECOSMOSDB_PRIMARY_KEY ]]; then + echo "Successfully retrieved the primary key of the [$WEB_APP_NAME] Cosmos DB account" + echo "Primary master key is $AZURECOSMOSDB_PRIMARY_KEY" +else echo "Failed to retrieve the primary key of the [$WEB_APP_NAME] Cosmos DB account" exit 1 fi export AZURECOSMOSDB_PRIMARY_KEY -echo "Primary master key is $AZURECOSMOSDB_PRIMARY_KEY" -echo "Creating App service" -if ! az appservice plan create --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME --sku B1 --is-linux; then - echo "Failed to create the [$WEB_APP_NAME] App Service plan" +# Create the App Service plan +echo "Creating [$WEB_APP_NAME] App Service plan in the [$RESOURCE_GROUP_NAME] resource group..." +az appservice plan create \ + --name $WEB_APP_NAME \ + --resource-group $RESOURCE_GROUP_NAME \ + --sku B1 \ + --is-linux \ + --only-show-errors 1>/dev/null + +if [[ $? == 0 ]]; then + echo "[$WEB_APP_NAME] App Service plan successfully created in the [$RESOURCE_GROUP_NAME] resource group" +else + echo "Failed to create [$WEB_APP_NAME] App Service plan in the [$RESOURCE_GROUP_NAME] resource group" exit 1 fi -echo "App service created" -echo "Creating Web App" -if ! az webapp create --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME --plan $WEB_APP_NAME --runtime DOTNETCORE:10.0; then - echo "Failed to create the [$WEB_APP_NAME] web app" +# Create the web app +echo "Creating [$WEB_APP_NAME] web app in the [$RESOURCE_GROUP_NAME] resource group..." +az webapp create \ + --name $WEB_APP_NAME \ + --resource-group $RESOURCE_GROUP_NAME \ + --plan $WEB_APP_NAME \ + --runtime DOTNETCORE:10.0 \ + --only-show-errors 1>/dev/null + +if [[ $? == 0 ]]; then + echo "[$WEB_APP_NAME] web app successfully created in the [$RESOURCE_GROUP_NAME] resource group" +else + echo "Failed to create [$WEB_APP_NAME] web app in the [$RESOURCE_GROUP_NAME] resource group" exit 1 fi -echo "Web App created" - -echo "Configure appsettings environment variables" -if ! az webapp config appsettings set \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --settings AZURECOSMOSDB_ENDPOINT=$AZURECOSMOSDB_ENDPOINT \ - AZURECOSMOSDB_DATABASENAME=$AZURECOSMOSDB_DATABASENAME \ - AZURECOSMOSDB_CONTAINERNAME=$AZURECOSMOSDB_CONTAINERNAME \ - AZURECOSMOSDB_PRIMARY_KEY=$AZURECOSMOSDB_PRIMARY_KEY; then + +# Set the application settings of the web app +echo "Setting the application settings of the [$WEB_APP_NAME] web app..." +az webapp config appsettings set \ + --resource-group $RESOURCE_GROUP_NAME \ + --name $WEB_APP_NAME \ + --settings AZURECOSMOSDB_ENDPOINT=$AZURECOSMOSDB_ENDPOINT \ + AZURECOSMOSDB_DATABASENAME=$AZURECOSMOSDB_DATABASENAME \ + AZURECOSMOSDB_CONTAINERNAME=$AZURECOSMOSDB_CONTAINERNAME \ + AZURECOSMOSDB_PRIMARY_KEY=$AZURECOSMOSDB_PRIMARY_KEY \ + --only-show-errors 1>/dev/null + +if [[ $? == 0 ]]; then + echo "Application settings of the [$WEB_APP_NAME] web app successfully set" +else echo "Failed to set the application settings of the [$WEB_APP_NAME] web app" exit 1 fi # Print the application settings of the web app echo "Retrieving application settings for web app [$WEB_APP_NAME]..." -if ! az webapp config appsettings list \ +az webapp config appsettings list \ --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME; then - echo "Failed to retrieve the application settings of the [$WEB_APP_NAME] web app" - exit 1 -fi + --name $WEB_APP_NAME # Change current directory to source folder -cd "../src" || exit 1 +cd "../src" || exit # Remove any existing zip package of the web app if [ -f "$ZIPFILE" ]; then @@ -139,21 +180,22 @@ fi # Create the zip package of the web app echo "Creating zip package of the web app..." -if ! zip -r "$ZIPFILE" . -x "bin/*" "obj/*" "publish/*" "*.zip"; then - echo "Failed to create the [$ZIPFILE] zip package of the web app" - exit 1 -fi +zip -r "$ZIPFILE" . -x "bin/*" "obj/*" "publish/*" "*.zip" # Deploy the web app echo "Deploying web app [$WEB_APP_NAME] with zip file [$ZIPFILE]..." echo "Using az webapp deploy command for LocalStack emulator environment." -if ! az webapp deploy \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --src-path ${ZIPFILE} \ - --type zip \ - --async true; then - echo "Failed to deploy the [$ZIPFILE] package to the [$WEB_APP_NAME] web app" +az webapp deploy \ + --resource-group $RESOURCE_GROUP_NAME \ + --name $WEB_APP_NAME \ + --src-path ${ZIPFILE} \ + --type zip \ + --async true + +if [[ $? == 0 ]]; then + echo "[$ZIPFILE] zip package successfully deployed to the [$WEB_APP_NAME] web app" +else + echo "Failed to deploy [$ZIPFILE] zip package to the [$WEB_APP_NAME] web app" exit 1 fi diff --git a/samples/web-app-cosmosdb-nosql-api/python/scripts/deploy.sh b/samples/web-app-cosmosdb-nosql-api/python/scripts/deploy.sh index 53fa0e1e..befa6973 100755 --- a/samples/web-app-cosmosdb-nosql-api/python/scripts/deploy.sh +++ b/samples/web-app-cosmosdb-nosql-api/python/scripts/deploy.sh @@ -46,91 +46,132 @@ else echo "Resource group [$RESOURCE_GROUP_NAME] already exists." fi -echo "Create CosmosDB NoSQL Account" -if ! AZURECOSMOSDB_ENDPOINT=$(az cosmosdb create \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --locations regionName=$LOCATION \ - --query "documentEndpoint" \ - --output tsv); then - echo "Failed to create the [$WEB_APP_NAME] Cosmos DB account" +# Create the Cosmos DB account +echo "Creating [$WEB_APP_NAME] Cosmos DB account in the [$RESOURCE_GROUP_NAME] resource group..." +AZURECOSMOSDB_ENDPOINT=$(az cosmosdb create \ + --resource-group $RESOURCE_GROUP_NAME \ + --name $WEB_APP_NAME \ + --locations regionName=$LOCATION \ + --query "documentEndpoint" \ + --output tsv) + +if [[ -n $AZURECOSMOSDB_ENDPOINT ]]; then + echo "[$WEB_APP_NAME] Cosmos DB account successfully created in the [$RESOURCE_GROUP_NAME] resource group" + echo "AZURECOSMOSDB_ENDPOINT set to $AZURECOSMOSDB_ENDPOINT" +else + echo "Failed to create [$WEB_APP_NAME] Cosmos DB account in the [$RESOURCE_GROUP_NAME] resource group" exit 1 fi export AZURECOSMOSDB_ENDPOINT -echo "Account created" -echo "AZURECOSMOSDB_ENDPOINT set to $AZURECOSMOSDB_ENDPOINT" +# Create the Cosmos DB database +echo "Creating [$AZURECOSMOSDB_DATABASENAME] database in the [$WEB_APP_NAME] Cosmos DB account..." +az cosmosdb sql database create \ + --resource-group $RESOURCE_GROUP_NAME \ + --name $AZURECOSMOSDB_DATABASENAME \ + --account-name $WEB_APP_NAME \ + --only-show-errors 1>/dev/null -echo "Create CosmosDB NoSQL Database" -if ! az cosmosdb sql database create \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $AZURECOSMOSDB_DATABASENAME \ - --account-name $WEB_APP_NAME; then - echo "Failed to create the [$AZURECOSMOSDB_DATABASENAME] database in the [$WEB_APP_NAME] Cosmos DB account" +if [[ $? == 0 ]]; then + echo "[$AZURECOSMOSDB_DATABASENAME] database successfully created in the [$WEB_APP_NAME] Cosmos DB account" +else + echo "Failed to create [$AZURECOSMOSDB_DATABASENAME] database in the [$WEB_APP_NAME] Cosmos DB account" exit 1 fi -echo "Create CosmosDB NoSQL Container" -if ! az cosmosdb sql container create \ - --resource-group $RESOURCE_GROUP_NAME \ - --account-name $WEB_APP_NAME \ - --database-name $AZURECOSMOSDB_DATABASENAME \ - --name $AZURECOSMOSDB_CONTAINERNAME \ - --partition-key-path $AURECOSMOSDB_PARTITION_KEY \ - --throughput 400; then - echo "Failed to create the [$AZURECOSMOSDB_CONTAINERNAME] container in the [$AZURECOSMOSDB_DATABASENAME] database" +# Create the Cosmos DB container +echo "Creating [$AZURECOSMOSDB_CONTAINERNAME] container in the [$AZURECOSMOSDB_DATABASENAME] database..." +az cosmosdb sql container create \ + --resource-group $RESOURCE_GROUP_NAME \ + --account-name $WEB_APP_NAME \ + --database-name $AZURECOSMOSDB_DATABASENAME \ + --name $AZURECOSMOSDB_CONTAINERNAME \ + --partition-key-path $AURECOSMOSDB_PARTITION_KEY \ + --throughput 400 \ + --only-show-errors 1>/dev/null + +if [[ $? == 0 ]]; then + echo "[$AZURECOSMOSDB_CONTAINERNAME] container successfully created in the [$AZURECOSMOSDB_DATABASENAME] database" +else + echo "Failed to create [$AZURECOSMOSDB_CONTAINERNAME] container in the [$AZURECOSMOSDB_DATABASENAME] database" exit 1 fi -echo "Fetching DB Account primary master key" -if ! AZURECOSMOSDB_PRIMARY_KEY=$(az cosmosdb keys list \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --query "primaryMasterKey" \ - --output tsv); then +# Retrieve the primary key of the Cosmos DB account +echo "Retrieving the primary key of the [$WEB_APP_NAME] Cosmos DB account..." +AZURECOSMOSDB_PRIMARY_KEY=$(az cosmosdb keys list \ + --resource-group $RESOURCE_GROUP_NAME \ + --name $WEB_APP_NAME \ + --query "primaryMasterKey" \ + --output tsv) + +if [[ -n $AZURECOSMOSDB_PRIMARY_KEY ]]; then + echo "Successfully retrieved the primary key of the [$WEB_APP_NAME] Cosmos DB account" + echo "Primary master key is $AZURECOSMOSDB_PRIMARY_KEY" +else echo "Failed to retrieve the primary key of the [$WEB_APP_NAME] Cosmos DB account" exit 1 fi export AZURECOSMOSDB_PRIMARY_KEY -echo "Primary master key is $AZURECOSMOSDB_PRIMARY_KEY" -echo "Creating App service" -if ! az appservice plan create --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME --sku B1 --is-linux; then - echo "Failed to create the [$WEB_APP_NAME] App Service plan" +# Create the App Service plan +echo "Creating [$WEB_APP_NAME] App Service plan in the [$RESOURCE_GROUP_NAME] resource group..." +az appservice plan create \ + --name $WEB_APP_NAME \ + --resource-group $RESOURCE_GROUP_NAME \ + --sku B1 \ + --is-linux \ + --only-show-errors 1>/dev/null + +if [[ $? == 0 ]]; then + echo "[$WEB_APP_NAME] App Service plan successfully created in the [$RESOURCE_GROUP_NAME] resource group" +else + echo "Failed to create [$WEB_APP_NAME] App Service plan in the [$RESOURCE_GROUP_NAME] resource group" exit 1 fi -echo "App service created" -echo "Creating Web App" -if ! az webapp create --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP_NAME --plan $WEB_APP_NAME --runtime PYTHON:3.13; then - echo "Failed to create the [$WEB_APP_NAME] web app" +# Create the web app +echo "Creating [$WEB_APP_NAME] web app in the [$RESOURCE_GROUP_NAME] resource group..." +az webapp create \ + --name $WEB_APP_NAME \ + --resource-group $RESOURCE_GROUP_NAME \ + --plan $WEB_APP_NAME \ + --runtime PYTHON:3.13 \ + --only-show-errors 1>/dev/null + +if [[ $? == 0 ]]; then + echo "[$WEB_APP_NAME] web app successfully created in the [$RESOURCE_GROUP_NAME] resource group" +else + echo "Failed to create [$WEB_APP_NAME] web app in the [$RESOURCE_GROUP_NAME] resource group" exit 1 fi -echo "Web App created" - -echo "Configure appsettings environment variables" -if ! az webapp config appsettings set \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --settings AZURECOSMOSDB_ENDPOINT=$AZURECOSMOSDB_ENDPOINT \ - AZURECOSMOSDB_DATABASENAME=$AZURECOSMOSDB_DATABASENAME \ - AZURECOSMOSDB_CONTAINERNAME=$AZURECOSMOSDB_CONTAINERNAME \ - AZURECOSMOSDB_PRIMARY_KEY=$AZURECOSMOSDB_PRIMARY_KEY; then + +# Set the application settings of the web app +echo "Setting the application settings of the [$WEB_APP_NAME] web app..." +az webapp config appsettings set \ + --resource-group $RESOURCE_GROUP_NAME \ + --name $WEB_APP_NAME \ + --settings AZURECOSMOSDB_ENDPOINT=$AZURECOSMOSDB_ENDPOINT \ + AZURECOSMOSDB_DATABASENAME=$AZURECOSMOSDB_DATABASENAME \ + AZURECOSMOSDB_CONTAINERNAME=$AZURECOSMOSDB_CONTAINERNAME \ + AZURECOSMOSDB_PRIMARY_KEY=$AZURECOSMOSDB_PRIMARY_KEY \ + --only-show-errors 1>/dev/null + +if [[ $? == 0 ]]; then + echo "Application settings of the [$WEB_APP_NAME] web app successfully set" +else echo "Failed to set the application settings of the [$WEB_APP_NAME] web app" exit 1 fi # Print the application settings of the web app echo "Retrieving application settings for web app [$WEB_APP_NAME]..." -if ! az webapp config appsettings list \ +az webapp config appsettings list \ --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME; then - echo "Failed to retrieve the application settings of the [$WEB_APP_NAME] web app" - exit 1 -fi + --name $WEB_APP_NAME # Change current directory to source folder -cd "../src" || exit 1 +cd "../src" || exit # Remove any existing zip package of the web app if [ -f "$ZIPFILE" ]; then @@ -139,21 +180,22 @@ fi # Create the zip package of the web app echo "Creating zip package of the web app..." -if ! zip -r "$ZIPFILE" app.py cosmosdb_client.py gunicorn.conf.py static templates requirements.txt; then - echo "Failed to create the [$ZIPFILE] zip package of the web app" - exit 1 -fi +zip -r "$ZIPFILE" app.py cosmosdb_client.py gunicorn.conf.py static templates requirements.txt # Deploy the web app echo "Deploying web app [$WEB_APP_NAME] with zip file [$ZIPFILE]..." echo "Using az webapp deploy command for LocalStack emulator environment." -if ! az webapp deploy \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --src-path ${ZIPFILE} \ - --type zip \ - --async true; then - echo "Failed to deploy the [$ZIPFILE] package to the [$WEB_APP_NAME] web app" +az webapp deploy \ + --resource-group $RESOURCE_GROUP_NAME \ + --name $WEB_APP_NAME \ + --src-path ${ZIPFILE} \ + --type zip \ + --async true + +if [[ $? == 0 ]]; then + echo "[$ZIPFILE] zip package successfully deployed to the [$WEB_APP_NAME] web app" +else + echo "Failed to deploy [$ZIPFILE] zip package to the [$WEB_APP_NAME] web app" exit 1 fi From 539fe5fc6abb35105177fe38dac9ef3af03efa78 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Thu, 29 Oct 2026 15:10:26 +0100 Subject: [PATCH 4/9] Read the names from PREFIX in the function-app-storage-http validate script samples/function-app-storage-http/dotnet/scripts/validate.sh wrote local-rg, local-func-test and localstoragetest out literally, so with the runner's per-sample prefix it checked resources that do not exist (the CI run of this PR failed there). It now builds them from PREFIX and SUFFIX as deploy.sh does. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FvNuJJpEr2yMWrV5cbJi2Z --- .../dotnet/scripts/validate.sh | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/samples/function-app-storage-http/dotnet/scripts/validate.sh b/samples/function-app-storage-http/dotnet/scripts/validate.sh index 6e0c2542..d51574a3 100644 --- a/samples/function-app-storage-http/dotnet/scripts/validate.sh +++ b/samples/function-app-storage-http/dotnet/scripts/validate.sh @@ -1,42 +1,48 @@ #!/bin/bash # Variables +PREFIX="${PREFIX:-local}" +SUFFIX="${SUFFIX:-test}" +FUNCTION_APP_NAME="${PREFIX}-func-${SUFFIX}" +STORAGE_ACCOUNT_NAME="${PREFIX}storage${SUFFIX}" +RESOURCE_GROUP_NAME="${PREFIX}-rg" + # Check resource group az group show \ - --name local-rg \ + --name $RESOURCE_GROUP_NAME \ --output table # List resources az resource list \ - --resource-group local-rg \ + --resource-group $RESOURCE_GROUP_NAME \ --output table # Check function app status az functionapp show \ - --name local-func-test \ - --resource-group local-rg \ + --name $FUNCTION_APP_NAME \ + --resource-group $RESOURCE_GROUP_NAME \ --output table # Check storage account properties az storage account show \ - --name localstoragetest \ - --resource-group local-rg \ + --name $STORAGE_ACCOUNT_NAME \ + --resource-group $RESOURCE_GROUP_NAME \ --output table # List storage containers az storage container list \ - --account-name localstoragetest \ + --account-name $STORAGE_ACCOUNT_NAME \ --output table \ --only-show-errors # List storage queues az storage queue list \ - --account-name localstoragetest \ + --account-name $STORAGE_ACCOUNT_NAME \ --output table \ --only-show-errors # List storage tables az storage table list \ - --account-name localstoragetest \ + --account-name $STORAGE_ACCOUNT_NAME \ --output table \ --only-show-errors \ No newline at end of file From ad0cdcd266366353d3c4ba54d901b074360e665a Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Thu, 29 Oct 2026 16:16:06 +0100 Subject: [PATCH 5/9] Look for the app to call in the sample's own resource group when PREFIX is set The runner gives every sample its own prefix and deletes the groups of the sample before without waiting, so the only web or function app in the subscription can be two for a while. With PREFIX set, the call scripts now count and pick the apps of ${PREFIX}-rg, the group every one of these samples deploys into; without it they look in the whole subscription, as before. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FvNuJJpEr2yMWrV5cbJi2Z --- .../dotnet/scripts/call-http-trigger.sh | 17 +++++++++++++---- .../dotnet/scripts/call-http-triggers.sh | 17 +++++++++++++---- .../dotnet/scripts/call-web-app.sh | 17 +++++++++++++---- .../python/scripts/call-web-app.sh | 17 +++++++++++++---- .../dotnet/scripts/call-web-app.sh | 17 +++++++++++++---- .../python/scripts/call-web-app.sh | 17 +++++++++++++---- .../dotnet/scripts/call-web-app.sh | 17 +++++++++++++---- .../python/scripts/call-web-app.sh | 17 +++++++++++++---- .../dotnet/scripts/call-web-app.sh | 17 +++++++++++++---- .../python/scripts/call-web-app.sh | 17 +++++++++++++---- .../dotnet/scripts/call-web-app.sh | 17 +++++++++++++---- .../python/scripts/call-web-app.sh | 17 +++++++++++++---- .../dotnet/scripts/call-web-app.sh | 17 +++++++++++++---- .../python/scripts/call-web-app.sh | 17 +++++++++++++---- .../dotnet/scripts/call-web-app.sh | 17 +++++++++++++---- .../python/scripts/call-web-app.sh | 17 +++++++++++++---- 16 files changed, 208 insertions(+), 64 deletions(-) diff --git a/samples/function-app-service-bus/dotnet/scripts/call-http-trigger.sh b/samples/function-app-service-bus/dotnet/scripts/call-http-trigger.sh index a8384f27..2dd3afff 100755 --- a/samples/function-app-service-bus/dotnet/scripts/call-http-trigger.sh +++ b/samples/function-app-service-bus/dotnet/scripts/call-http-trigger.sh @@ -93,16 +93,25 @@ get_docker_container_app_port() { } call_http_trigger_function() { - # The function app to call: the one the caller named, else the only one in the subscription + # The function app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription function_app_name="$1" if [ -z "$function_app_name" ]; then - echo "Getting the name of the only function app in the subscription..." - function_app_count=$(az functionapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only function app in the [${PREFIX}-rg] resource group..." + function_app_count=$(az functionapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + function_app_name=$(az functionapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only function app in the subscription..." + function_app_count=$(az functionapp list --query "length(@)" --output tsv) + function_app_name=$(az functionapp list --query "[0].name" --output tsv) + fi if [ "$function_app_count" != "1" ]; then echo "Error: Found [${function_app_count:-0}] function apps; name the one to call: $0 " exit 1 fi - function_app_name=$(az functionapp list --query "[0].name" --output tsv) fi if [ -n "$function_app_name" ]; then diff --git a/samples/function-app-storage-http/dotnet/scripts/call-http-triggers.sh b/samples/function-app-storage-http/dotnet/scripts/call-http-triggers.sh index 73f819b2..4e0ee56f 100755 --- a/samples/function-app-storage-http/dotnet/scripts/call-http-triggers.sh +++ b/samples/function-app-storage-http/dotnet/scripts/call-http-triggers.sh @@ -93,16 +93,25 @@ get_docker_container_app_port() { } call_http_trigger_functions() { - # The function app to call: the one the caller named, else the only one in the subscription + # The function app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription function_app_name="$1" if [ -z "$function_app_name" ]; then - echo "Getting the name of the only function app in the subscription..." - function_app_count=$(az functionapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only function app in the [${PREFIX}-rg] resource group..." + function_app_count=$(az functionapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + function_app_name=$(az functionapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only function app in the subscription..." + function_app_count=$(az functionapp list --query "length(@)" --output tsv) + function_app_name=$(az functionapp list --query "[0].name" --output tsv) + fi if [ "$function_app_count" != "1" ]; then echo "Error: Found [${function_app_count:-0}] function apps; name the one to call: $0 " exit 1 fi - function_app_name=$(az functionapp list --query "[0].name" --output tsv) fi if [ -n "$function_app_name" ]; then diff --git a/samples/web-app-app-configuration/dotnet/scripts/call-web-app.sh b/samples/web-app-app-configuration/dotnet/scripts/call-web-app.sh index f98ceac3..73326a7e 100755 --- a/samples/web-app-app-configuration/dotnet/scripts/call-web-app.sh +++ b/samples/web-app-app-configuration/dotnet/scripts/call-web-app.sh @@ -96,16 +96,25 @@ call_web_app() { # Web app port local web_app_port - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-app-configuration/python/scripts/call-web-app.sh b/samples/web-app-app-configuration/python/scripts/call-web-app.sh index f98ceac3..73326a7e 100755 --- a/samples/web-app-app-configuration/python/scripts/call-web-app.sh +++ b/samples/web-app-app-configuration/python/scripts/call-web-app.sh @@ -96,16 +96,25 @@ call_web_app() { # Web app port local web_app_port - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-cosmosdb-mongodb-api/dotnet/scripts/call-web-app.sh b/samples/web-app-cosmosdb-mongodb-api/dotnet/scripts/call-web-app.sh index 6620a4c8..8944c249 100755 --- a/samples/web-app-cosmosdb-mongodb-api/dotnet/scripts/call-web-app.sh +++ b/samples/web-app-cosmosdb-mongodb-api/dotnet/scripts/call-web-app.sh @@ -93,16 +93,25 @@ get_docker_container_app_port() { } call_web_app() { - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-cosmosdb-mongodb-api/python/scripts/call-web-app.sh b/samples/web-app-cosmosdb-mongodb-api/python/scripts/call-web-app.sh index 6620a4c8..8944c249 100755 --- a/samples/web-app-cosmosdb-mongodb-api/python/scripts/call-web-app.sh +++ b/samples/web-app-cosmosdb-mongodb-api/python/scripts/call-web-app.sh @@ -93,16 +93,25 @@ get_docker_container_app_port() { } call_web_app() { - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/call-web-app.sh b/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/call-web-app.sh index 6f4db112..dc38dd71 100755 --- a/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/call-web-app.sh +++ b/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/call-web-app.sh @@ -93,16 +93,25 @@ get_docker_container_app_port() { } call_web_app() { - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-cosmosdb-nosql-api/python/scripts/call-web-app.sh b/samples/web-app-cosmosdb-nosql-api/python/scripts/call-web-app.sh index 6f4db112..dc38dd71 100755 --- a/samples/web-app-cosmosdb-nosql-api/python/scripts/call-web-app.sh +++ b/samples/web-app-cosmosdb-nosql-api/python/scripts/call-web-app.sh @@ -93,16 +93,25 @@ get_docker_container_app_port() { } call_web_app() { - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-managed-identity/dotnet/scripts/call-web-app.sh b/samples/web-app-managed-identity/dotnet/scripts/call-web-app.sh index 6f4db112..dc38dd71 100755 --- a/samples/web-app-managed-identity/dotnet/scripts/call-web-app.sh +++ b/samples/web-app-managed-identity/dotnet/scripts/call-web-app.sh @@ -93,16 +93,25 @@ get_docker_container_app_port() { } call_web_app() { - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-managed-identity/python/scripts/call-web-app.sh b/samples/web-app-managed-identity/python/scripts/call-web-app.sh index 6f4db112..dc38dd71 100755 --- a/samples/web-app-managed-identity/python/scripts/call-web-app.sh +++ b/samples/web-app-managed-identity/python/scripts/call-web-app.sh @@ -93,16 +93,25 @@ get_docker_container_app_port() { } call_web_app() { - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-mysql-flexible-server/dotnet/scripts/call-web-app.sh b/samples/web-app-mysql-flexible-server/dotnet/scripts/call-web-app.sh index f98ceac3..73326a7e 100755 --- a/samples/web-app-mysql-flexible-server/dotnet/scripts/call-web-app.sh +++ b/samples/web-app-mysql-flexible-server/dotnet/scripts/call-web-app.sh @@ -96,16 +96,25 @@ call_web_app() { # Web app port local web_app_port - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-mysql-flexible-server/python/scripts/call-web-app.sh b/samples/web-app-mysql-flexible-server/python/scripts/call-web-app.sh index f98ceac3..73326a7e 100755 --- a/samples/web-app-mysql-flexible-server/python/scripts/call-web-app.sh +++ b/samples/web-app-mysql-flexible-server/python/scripts/call-web-app.sh @@ -96,16 +96,25 @@ call_web_app() { # Web app port local web_app_port - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-postgresql-flexible-server/dotnet/scripts/call-web-app.sh b/samples/web-app-postgresql-flexible-server/dotnet/scripts/call-web-app.sh index f98ceac3..73326a7e 100755 --- a/samples/web-app-postgresql-flexible-server/dotnet/scripts/call-web-app.sh +++ b/samples/web-app-postgresql-flexible-server/dotnet/scripts/call-web-app.sh @@ -96,16 +96,25 @@ call_web_app() { # Web app port local web_app_port - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-postgresql-flexible-server/python/scripts/call-web-app.sh b/samples/web-app-postgresql-flexible-server/python/scripts/call-web-app.sh index f98ceac3..73326a7e 100755 --- a/samples/web-app-postgresql-flexible-server/python/scripts/call-web-app.sh +++ b/samples/web-app-postgresql-flexible-server/python/scripts/call-web-app.sh @@ -96,16 +96,25 @@ call_web_app() { # Web app port local web_app_port - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-sql-database/dotnet/scripts/call-web-app.sh b/samples/web-app-sql-database/dotnet/scripts/call-web-app.sh index 5daec1de..ca91e2bb 100755 --- a/samples/web-app-sql-database/dotnet/scripts/call-web-app.sh +++ b/samples/web-app-sql-database/dotnet/scripts/call-web-app.sh @@ -101,16 +101,25 @@ normalize_dn() { } call_web_app() { - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then diff --git a/samples/web-app-sql-database/python/scripts/call-web-app.sh b/samples/web-app-sql-database/python/scripts/call-web-app.sh index 9d7434fc..75000027 100755 --- a/samples/web-app-sql-database/python/scripts/call-web-app.sh +++ b/samples/web-app-sql-database/python/scripts/call-web-app.sh @@ -101,16 +101,25 @@ normalize_dn() { } call_web_app() { - # The web app to call: the one the caller named, else the only one in the subscription + # The web app to call: the one the caller named, else the only one in the sample's resource group or the + # subscription web_app_name="$1" if [ -z "$web_app_name" ]; then - echo "Getting the name of the only web app in the subscription..." - web_app_count=$(az webapp list --query "length(@)" --output tsv) + if [ -n "$PREFIX" ]; then + # The samples runner gives every sample its own PREFIX, while the resource group of the sample before + # can still be being deleted: look only in this sample's resource group + echo "Getting the name of the only web app in the [${PREFIX}-rg] resource group..." + web_app_count=$(az webapp list --resource-group "${PREFIX}-rg" --query "length(@)" --output tsv) + web_app_name=$(az webapp list --resource-group "${PREFIX}-rg" --query "[0].name" --output tsv) + else + echo "Getting the name of the only web app in the subscription..." + web_app_count=$(az webapp list --query "length(@)" --output tsv) + web_app_name=$(az webapp list --query "[0].name" --output tsv) + fi if [ "$web_app_count" != "1" ]; then echo "Error: Found [${web_app_count:-0}] web apps; name the one to call: $0 " exit 1 fi - web_app_name=$(az webapp list --query "[0].name" --output tsv) fi if [ -n "$web_app_name" ]; then From 11e79de37d5bd9c7387a330d759fced6a36afa60 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Thu, 29 Oct 2026 16:16:06 +0100 Subject: [PATCH 6/9] Pass the Terraform prefix variable of the Event Hubs samples only when PREFIX is set Defaulting PREFIX to local and always passing -var prefix overrode a prefix set in terraform.tfvars or TF_VAR_prefix, so a rerun could replace a customized deployment. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FvNuJJpEr2yMWrV5cbJi2Z --- .../eventhubs-eventgrid/python/terraform/deploy.sh | 14 +++++++++----- samples/eventhubs/python/terraform/deploy.sh | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/samples/eventhubs-eventgrid/python/terraform/deploy.sh b/samples/eventhubs-eventgrid/python/terraform/deploy.sh index 66670751..1cba7302 100644 --- a/samples/eventhubs-eventgrid/python/terraform/deploy.sh +++ b/samples/eventhubs-eventgrid/python/terraform/deploy.sh @@ -28,8 +28,12 @@ fail() { exit 1 } -# Name prefix of every resource (the configuration's prefix variable) -PREFIX="${PREFIX:-local}" +# The configuration's prefix variable, passed only when PREFIX is set: otherwise terraform.tfvars, TF_VAR_prefix +# or the variable's default decides it +PREFIX_VARIABLE=() +if [[ -n $PREFIX ]]; then + PREFIX_VARIABLE=(-var "prefix=$PREFIX") +fi echo "=== Initializing Terraform ===" terraform init -input=false || fail "terraform init failed" @@ -40,7 +44,7 @@ terraform validate || fail "terraform validate failed" echo "" echo "=== Planning ===" -terraform plan -input=false -var "prefix=$PREFIX" -out=tfplan || fail "terraform plan failed" +terraform plan -input=false "${PREFIX_VARIABLE[@]}" -out=tfplan || fail "terraform plan failed" echo "" echo "=== Applying ===" @@ -48,14 +52,14 @@ terraform apply -input=false -auto-approve tfplan || fail "terraform apply faile echo "" echo "=== Re-applying (the configuration must converge without errors) ===" -terraform apply -input=false -auto-approve -var "prefix=$PREFIX" || fail "the second apply failed" +terraform apply -input=false -auto-approve "${PREFIX_VARIABLE[@]}" || fail "the second apply failed" # A perfectly idempotent second apply reports "No changes". Against the emulator a few resources # still report drift because some properties are accepted on create but not echoed back on read, # so the provider re-sends them every run. That is an emulator parity gap rather than a problem # with this configuration: the re-apply converges and changes nothing observable. DRIFT=$( - terraform plan -input=false -var "prefix=$PREFIX" -detailed-exitcode >/dev/null 2>&1 + terraform plan -input=false "${PREFIX_VARIABLE[@]}" -detailed-exitcode >/dev/null 2>&1 echo $? ) if [[ "$DRIFT" == "0" ]]; then diff --git a/samples/eventhubs/python/terraform/deploy.sh b/samples/eventhubs/python/terraform/deploy.sh index 813f4c7d..3c77e7fc 100644 --- a/samples/eventhubs/python/terraform/deploy.sh +++ b/samples/eventhubs/python/terraform/deploy.sh @@ -29,8 +29,12 @@ fail() { exit 1 } -# Name prefix of every resource (the configuration's prefix variable) -PREFIX="${PREFIX:-local}" +# The configuration's prefix variable, passed only when PREFIX is set: otherwise terraform.tfvars, TF_VAR_prefix +# or the variable's default decides it +PREFIX_VARIABLE=() +if [[ -n $PREFIX ]]; then + PREFIX_VARIABLE=(-var "prefix=$PREFIX") +fi echo "=== Initializing Terraform ===" terraform init -input=false || fail "terraform init failed" @@ -41,7 +45,7 @@ terraform validate || fail "terraform validate failed" echo "" echo "=== Planning ===" -terraform plan -input=false -var "prefix=$PREFIX" -out=tfplan || fail "terraform plan failed" +terraform plan -input=false "${PREFIX_VARIABLE[@]}" -out=tfplan || fail "terraform plan failed" echo "" echo "=== Applying ===" @@ -49,7 +53,7 @@ terraform apply -input=false -auto-approve tfplan || fail "terraform apply faile echo "" echo "=== Re-applying (the configuration must converge without errors) ===" -terraform apply -input=false -auto-approve -var "prefix=$PREFIX" || fail "the second apply failed" +terraform apply -input=false -auto-approve "${PREFIX_VARIABLE[@]}" || fail "the second apply failed" # A perfectly idempotent second apply reports "No changes". Against the emulator a few # resources still report drift because some properties are accepted on create but not @@ -57,7 +61,7 @@ terraform apply -input=false -auto-approve -var "prefix=$PREFIX" || fail "the se # Key Vault tags, and similar), so the provider re-sends them every run. That is an # emulator parity gap rather than a problem with this configuration: the re-apply is # clean, converges, and changes nothing observable. -DRIFT=$(terraform plan -input=false -var "prefix=$PREFIX" -detailed-exitcode >/dev/null 2>&1; echo $?) +DRIFT=$(terraform plan -input=false "${PREFIX_VARIABLE[@]}" -detailed-exitcode >/dev/null 2>&1; echo $?) if [[ "$DRIFT" == "0" ]]; then echo "Second apply is fully idempotent (no changes)." else From e1fcb4cf419225ef0531feba4aaa04b6a73dff71 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Thu, 29 Oct 2026 16:16:06 +0100 Subject: [PATCH 7/9] Keep the URL shortener's deployment state in one file per prefix Deployments under different prefixes shared scripts/.last_deploy.env, so a rerun of one could read another's PostgreSQL password and host. The CLI, Bicep and Terraform deploy scripts and the validation script now use scripts/.last_deploy..env. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FvNuJJpEr2yMWrV5cbJi2Z --- samples/url-shortener/python/README.md | 6 +++--- samples/url-shortener/python/bicep/README.md | 2 +- samples/url-shortener/python/bicep/deploy.sh | 2 +- samples/url-shortener/python/scripts/README.md | 2 +- samples/url-shortener/python/scripts/deploy.sh | 2 +- samples/url-shortener/python/scripts/validate.sh | 2 +- samples/url-shortener/python/terraform/README.md | 2 +- samples/url-shortener/python/terraform/deploy.sh | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/samples/url-shortener/python/README.md b/samples/url-shortener/python/README.md index 0d3f9156..0dbacde9 100644 --- a/samples/url-shortener/python/README.md +++ b/samples/url-shortener/python/README.md @@ -110,7 +110,7 @@ az login --service-principal -u any-app -p any-pass --tenant any-tenant bash scripts/deploy.sh ``` -The script provisions all resources idempotently, deploys both applications from zip packages and persists the generated PostgreSQL credentials to `scripts/.last_deploy.env` for the validation script. +The script provisions all resources idempotently, deploys both applications from zip packages and persists the generated PostgreSQL credentials to `scripts/.last_deploy..env` (`.last_deploy.local.env` for the default prefix) for the validation script. ### Terraform @@ -119,7 +119,7 @@ cd terraform bash deploy.sh ``` -The Terraform variant provisions the same resources declaratively and then performs the two zip deployments with the Azure CLI. It also persists the generated PostgreSQL credentials to `scripts/.last_deploy.env` for the validation script. +The Terraform variant provisions the same resources declaratively and then performs the two zip deployments with the Azure CLI. It also persists the generated PostgreSQL credentials to `scripts/.last_deploy..env` (`.last_deploy.local.env` for the default prefix) for the validation script. ### Bicep @@ -128,7 +128,7 @@ cd bicep bash deploy.sh ``` -The Bicep variant validates and deploys `main.bicep` into the resource group and then performs the two zip deployments with the Azure CLI. It also persists the generated PostgreSQL credentials to `scripts/.last_deploy.env` for the validation script. +The Bicep variant validates and deploys `main.bicep` into the resource group and then performs the two zip deployments with the Azure CLI. It also persists the generated PostgreSQL credentials to `scripts/.last_deploy..env` (`.last_deploy.local.env` for the default prefix) for the validation script. ## Testing diff --git a/samples/url-shortener/python/bicep/README.md b/samples/url-shortener/python/bicep/README.md index 89d27b0c..a241b943 100644 --- a/samples/url-shortener/python/bicep/README.md +++ b/samples/url-shortener/python/bicep/README.md @@ -16,7 +16,7 @@ This directory contains the Bicep template for the sample. For details about the bash deploy.sh ``` -The script creates the resource group, validates and deploys `main.bicep` (generating the PostgreSQL password, the link-signing key and the internal API token per run), and then deploys the web app and the worker from zip packages with the Azure CLI. It persists the generated PostgreSQL credentials to `../scripts/.last_deploy.env` so `scripts/validate.sh` works after a Bicep deployment. +The script creates the resource group, validates and deploys `main.bicep` (generating the PostgreSQL password, the link-signing key and the internal API token per run), and then deploys the web app and the worker from zip packages with the Azure CLI. It persists the generated PostgreSQL credentials to `../scripts/.last_deploy..env` (`.last_deploy.local.env` for the default prefix) so `scripts/validate.sh` works after a Bicep deployment. ## Cleanup diff --git a/samples/url-shortener/python/bicep/deploy.sh b/samples/url-shortener/python/bicep/deploy.sh index 62558782..a3ae3a6d 100755 --- a/samples/url-shortener/python/bicep/deploy.sh +++ b/samples/url-shortener/python/bicep/deploy.sh @@ -89,7 +89,7 @@ fi # Persist the PostgreSQL credentials for scripts/validate.sh, matching the # contract of scripts/deploy.sh. -cat >"$CURRENT_DIR/../scripts/.last_deploy.env" <"$CURRENT_DIR/../scripts/.last_deploy.${PREFIX}.env" <.env` (`.last_deploy.local.env` for the default prefix). | | `validate.sh` | Walks the full causal chain end to end and exits non-zero on any failure. | | `call-web-app.sh` | Quick user-level smoke test: home page, shorten a URL, follow the redirect. | diff --git a/samples/url-shortener/python/scripts/deploy.sh b/samples/url-shortener/python/scripts/deploy.sh index d6201d12..2655b316 100755 --- a/samples/url-shortener/python/scripts/deploy.sh +++ b/samples/url-shortener/python/scripts/deploy.sh @@ -29,7 +29,7 @@ FUNCTIONS_VERSION='4' WEBAPP_ZIPFILE='linklet_webapp.zip' WORKER_ZIPFILE='linklet_worker.zip' CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)" -STATE_FILE="$CURRENT_DIR/.last_deploy.env" +STATE_FILE="$CURRENT_DIR/.last_deploy.${PREFIX}.env" # Get the current subscription SUBSCRIPTION_NAME=$(az account show --query name --output tsv) diff --git a/samples/url-shortener/python/scripts/validate.sh b/samples/url-shortener/python/scripts/validate.sh index 57424ba7..167150cc 100755 --- a/samples/url-shortener/python/scripts/validate.sh +++ b/samples/url-shortener/python/scripts/validate.sh @@ -10,7 +10,7 @@ WEB_APP_NAME="${PREFIX}-urlshort-webapp-${SUFFIX}" POSTGRES_ADMIN_USER='linkletadmin' POSTGRES_DB_NAME='clicks' CURRENT_DIR="$(cd "$(dirname "$0")" && pwd)" -STATE_FILE="$CURRENT_DIR/.last_deploy.env" +STATE_FILE="$CURRENT_DIR/.last_deploy.${PREFIX}.env" # On Windows, Git Bash and MSYS2 shells pass a path such as /tmp/... unconverted to Windows programs # (az, curl, jq, python, docker) when MSYS_NO_PATHCONV=1 is set, as the README asks. cygpath, which diff --git a/samples/url-shortener/python/terraform/README.md b/samples/url-shortener/python/terraform/README.md index cd9d618c..6f30b62d 100644 --- a/samples/url-shortener/python/terraform/README.md +++ b/samples/url-shortener/python/terraform/README.md @@ -16,7 +16,7 @@ This directory contains the Terraform configuration for the sample. For details bash deploy.sh ``` -The script runs `terraform init`, `plan` and `apply`, attaches the storage diagnostic settings to the Log Analytics workspace, and deploys the web app and the worker from zip packages with the Azure CLI. It persists the generated PostgreSQL credentials to `../scripts/.last_deploy.env` so `scripts/validate.sh` works after a Terraform deployment. Terraform state stays local, matching the sibling samples. +The script runs `terraform init`, `plan` and `apply`, attaches the storage diagnostic settings to the Log Analytics workspace, and deploys the web app and the worker from zip packages with the Azure CLI. It persists the generated PostgreSQL credentials to `../scripts/.last_deploy..env` (`.last_deploy.local.env` for the default prefix) so `scripts/validate.sh` works after a Terraform deployment. Terraform state stays local, matching the sibling samples. ## Cleanup diff --git a/samples/url-shortener/python/terraform/deploy.sh b/samples/url-shortener/python/terraform/deploy.sh index a863be89..822e89df 100755 --- a/samples/url-shortener/python/terraform/deploy.sh +++ b/samples/url-shortener/python/terraform/deploy.sh @@ -51,7 +51,7 @@ fi # Persist the PostgreSQL credentials for scripts/validate.sh, matching the # contract of scripts/deploy.sh. -cat >"$CURRENT_DIR/../scripts/.last_deploy.env" <"$CURRENT_DIR/../scripts/.last_deploy.${PREFIX}.env" < Date: Thu, 29 Oct 2026 16:16:06 +0100 Subject: [PATCH 8/9] Stop a Terraform deployment whose state tracks another run's resource group Run under another PREFIX next to the state of a previous run, the apply would replace that run's resource group and delete its resources. The two scripts that pre-create the group for the image push now stop first, naming the group the state tracks. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FvNuJJpEr2yMWrV5cbJi2Z --- samples/aci-blob-storage/python/terraform/deploy.sh | 10 ++++++++++ .../python/terraform/deploy.sh | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/samples/aci-blob-storage/python/terraform/deploy.sh b/samples/aci-blob-storage/python/terraform/deploy.sh index 8e48e46e..ad097a6d 100644 --- a/samples/aci-blob-storage/python/terraform/deploy.sh +++ b/samples/aci-blob-storage/python/terraform/deploy.sh @@ -16,6 +16,16 @@ cd "$CURRENT_DIR" || exit # (Terraform references the pre-created ACR as a data source) # ============================================================================= +# Stop if the Terraform state of a previous run tracks another resource group: run under another PREFIX, the +# apply would replace that run's resource group and delete its resources +echo "Checking that the Terraform state tracks no resource group other than [$RESOURCE_GROUP_NAME]..." +STATE_RESOURCE_GROUP_NAME=$(terraform state show -no-color azurerm_resource_group.example 2>/dev/null | awk '$1 == "name" { gsub(/"/, "", $3); print $3 }') + +if [[ -n $STATE_RESOURCE_GROUP_NAME && $STATE_RESOURCE_GROUP_NAME != "$RESOURCE_GROUP_NAME" ]]; then + echo "The Terraform state tracks the [$STATE_RESOURCE_GROUP_NAME] resource group of a previous run: delete its terraform.tfstate files, or run with the PREFIX of that run" + exit 1 +fi + # Create resource group and ACR first so we can push the image RESOURCE_GROUP_NAME="${PREFIX}-aci-rg" ACR_NAME="${PREFIX}aciacr${SUFFIX}" diff --git a/samples/container-apps-blob-storage/python/terraform/deploy.sh b/samples/container-apps-blob-storage/python/terraform/deploy.sh index f2a89c8a..23b05c7d 100644 --- a/samples/container-apps-blob-storage/python/terraform/deploy.sh +++ b/samples/container-apps-blob-storage/python/terraform/deploy.sh @@ -17,6 +17,16 @@ cd "$CURRENT_DIR" || exit # (Terraform references the pre-created ACR as a data source) # ============================================================================= +# Stop if the Terraform state of a previous run tracks another resource group: run under another PREFIX, the +# apply would replace that run's resource group and delete its resources +echo "Checking that the Terraform state tracks no resource group other than [$RESOURCE_GROUP_NAME]..." +STATE_RESOURCE_GROUP_NAME=$(terraform state show -no-color azurerm_resource_group.example 2>/dev/null | awk '$1 == "name" { gsub(/"/, "", $3); print $3 }') + +if [[ -n $STATE_RESOURCE_GROUP_NAME && $STATE_RESOURCE_GROUP_NAME != "$RESOURCE_GROUP_NAME" ]]; then + echo "The Terraform state tracks the [$STATE_RESOURCE_GROUP_NAME] resource group of a previous run: delete its terraform.tfstate files, or run with the PREFIX of that run" + exit 1 +fi + # Create resource group and ACR first so we can push the image RESOURCE_GROUP_NAME="${PREFIX}-aca-rg" ACR_NAME="${PREFIX}acaacr${SUFFIX}" From 3d7c2535ef7fcacb5c7cc96d895b388df5f08873 Mon Sep 17 00:00:00 2001 From: Paolo Salvatori Date: Thu, 29 Oct 2026 16:38:56 +0100 Subject: [PATCH 9/9] Check the Terraform state after the resource group name is set The check ran before RESOURCE_GROUP_NAME was assigned, so any state left by a previous run, under the same PREFIX too, stopped the deployment. It now runs right after the names are set, before anything is created. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01FvNuJJpEr2yMWrV5cbJi2Z --- samples/aci-blob-storage/python/terraform/deploy.sh | 8 ++++---- .../python/terraform/deploy.sh | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/samples/aci-blob-storage/python/terraform/deploy.sh b/samples/aci-blob-storage/python/terraform/deploy.sh index ad097a6d..4b0e317a 100644 --- a/samples/aci-blob-storage/python/terraform/deploy.sh +++ b/samples/aci-blob-storage/python/terraform/deploy.sh @@ -16,6 +16,10 @@ cd "$CURRENT_DIR" || exit # (Terraform references the pre-created ACR as a data source) # ============================================================================= +# Create resource group and ACR first so we can push the image +RESOURCE_GROUP_NAME="${PREFIX}-aci-rg" +ACR_NAME="${PREFIX}aciacr${SUFFIX}" + # Stop if the Terraform state of a previous run tracks another resource group: run under another PREFIX, the # apply would replace that run's resource group and delete its resources echo "Checking that the Terraform state tracks no resource group other than [$RESOURCE_GROUP_NAME]..." @@ -26,10 +30,6 @@ if [[ -n $STATE_RESOURCE_GROUP_NAME && $STATE_RESOURCE_GROUP_NAME != "$RESOURCE_ exit 1 fi -# Create resource group and ACR first so we can push the image -RESOURCE_GROUP_NAME="${PREFIX}-aci-rg" -ACR_NAME="${PREFIX}aciacr${SUFFIX}" - echo "Creating resource group [$RESOURCE_GROUP_NAME]..." az group create \ --name "$RESOURCE_GROUP_NAME" \ diff --git a/samples/container-apps-blob-storage/python/terraform/deploy.sh b/samples/container-apps-blob-storage/python/terraform/deploy.sh index 23b05c7d..6f5beef1 100644 --- a/samples/container-apps-blob-storage/python/terraform/deploy.sh +++ b/samples/container-apps-blob-storage/python/terraform/deploy.sh @@ -17,6 +17,10 @@ cd "$CURRENT_DIR" || exit # (Terraform references the pre-created ACR as a data source) # ============================================================================= +# Create resource group and ACR first so we can push the image +RESOURCE_GROUP_NAME="${PREFIX}-aca-rg" +ACR_NAME="${PREFIX}acaacr${SUFFIX}" + # Stop if the Terraform state of a previous run tracks another resource group: run under another PREFIX, the # apply would replace that run's resource group and delete its resources echo "Checking that the Terraform state tracks no resource group other than [$RESOURCE_GROUP_NAME]..." @@ -27,10 +31,6 @@ if [[ -n $STATE_RESOURCE_GROUP_NAME && $STATE_RESOURCE_GROUP_NAME != "$RESOURCE_ exit 1 fi -# Create resource group and ACR first so we can push the image -RESOURCE_GROUP_NAME="${PREFIX}-aca-rg" -ACR_NAME="${PREFIX}acaacr${SUFFIX}" - echo "Creating resource group [$RESOURCE_GROUP_NAME]..." az group create \ --name "$RESOURCE_GROUP_NAME" \