diff --git a/run-samples.sh b/run-samples.sh index 9031c74..2164524 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 d9d616b..1781b0b 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" @@ -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/aci-blob-storage/python/scripts/cleanup.sh b/samples/aci-blob-storage/python/scripts/cleanup.sh index 24f2298..8a1533d 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 a53ef40..f84e95f 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 93d89e4..3e08728 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 e1fcf95..4b0e317 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' @@ -20,6 +20,16 @@ cd "$CURRENT_DIR" || exit 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]..." +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 + echo "Creating resource group [$RESOURCE_GROUP_NAME]..." az group create \ --name "$RESOURCE_GROUP_NAME" \ diff --git a/samples/container-apps-blob-storage/python/bicep/deploy.sh b/samples/container-apps-blob-storage/python/bicep/deploy.sh index 73267c3..e2b8a7d 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" @@ -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]" @@ -65,6 +65,13 @@ az acr create \ --admin-enabled true \ --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 + LOGIN_SERVER=$(az acr show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ @@ -72,6 +79,13 @@ LOGIN_SERVER=$(az acr show \ --output tsv \ --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 + ACR_USERNAME=$(az acr credential show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ @@ -79,6 +93,13 @@ ACR_USERNAME=$(az acr credential show \ --output tsv \ --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 + ACR_PASSWORD=$(az acr credential show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ @@ -86,6 +107,13 @@ ACR_PASSWORD=$(az acr credential show \ --output tsv \ --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 + FULL_IMAGE="${LOGIN_SERVER}/${IMAGE_NAME}:${IMAGE_TAG}" echo "Building Docker image [$IMAGE_NAME:$IMAGE_TAG]..." @@ -98,9 +126,19 @@ fi 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]..." 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 + echo "Pushing image [$FULL_IMAGE]..." docker push "$FULL_IMAGE" 2>/dev/null @@ -133,7 +171,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 +191,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/scripts/cleanup.sh b/samples/container-apps-blob-storage/python/scripts/cleanup.sh index e79eab2..69c6ff8 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 48426ac..726880b 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 edfc311..6cc2590 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 fff2931..6f5beef 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' @@ -21,12 +21,29 @@ cd "$CURRENT_DIR" || exit 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]..." +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 + echo "Creating resource group [$RESOURCE_GROUP_NAME]..." az group create \ --name "$RESOURCE_GROUP_NAME" \ --location "$LOCATION" \ --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..." az acr create \ --name "$ACR_NAME" \ @@ -36,6 +53,13 @@ az acr create \ --admin-enabled true \ --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 + LOGIN_SERVER=$(az acr show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ @@ -43,6 +67,13 @@ LOGIN_SERVER=$(az acr show \ --output tsv \ --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 + ACR_USERNAME=$(az acr credential show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ @@ -50,6 +81,13 @@ ACR_USERNAME=$(az acr credential show \ --output tsv \ --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 + ACR_PASSWORD=$(az acr credential show \ --name "$ACR_NAME" \ --resource-group "$RESOURCE_GROUP_NAME" \ @@ -57,6 +95,13 @@ ACR_PASSWORD=$(az acr credential show \ --output tsv \ --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 + FULL_IMAGE="${LOGIN_SERVER}/${IMAGE_NAME}:${IMAGE_TAG}" echo "Building Docker image [$IMAGE_NAME:$IMAGE_TAG]..." @@ -69,9 +114,19 @@ fi 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]..." 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 + echo "Pushing image [$FULL_IMAGE]..." docker push "$FULL_IMAGE" 2>/dev/null @@ -88,17 +143,35 @@ echo "Image pushed to ACR successfully." echo "Initializing Terraform..." terraform init -upgrade -# Import the resource group that was pre-created for the image push +if [[ $? != 0 ]]; then + echo "Terraform init failed. Exiting." + exit 1 +fi + +# 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..." -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}" 2>/dev/null || true +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..." @@ -110,6 +183,11 @@ terraform plan -out=tfplan \ -var "image_tag=$IMAGE_TAG" \ -var "managed_identity_type=$MANAGED_IDENTITY_TYPE" +if [[ $? != 0 ]]; then + echo "Terraform plan failed. Exiting." + exit 1 +fi + # Apply the Terraform configuration echo "Applying Terraform configuration..." terraform apply -auto-approve tfplan diff --git a/samples/eventhubs-eventgrid/python/bicep/deploy.sh b/samples/eventhubs-eventgrid/python/bicep/deploy.sh index 33f6d68..beb7616 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 46b0914..b6f0210 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 34c8722..2f55b99 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 3a8acb4..ecff3a6 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 46d702d..1cba730 100644 --- a/samples/eventhubs-eventgrid/python/terraform/deploy.sh +++ b/samples/eventhubs-eventgrid/python/terraform/deploy.sh @@ -28,6 +28,13 @@ fail() { exit 1 } +# 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" @@ -37,7 +44,7 @@ terraform validate || fail "terraform validate failed" echo "" echo "=== Planning ===" -terraform plan -input=false -out=tfplan || fail "terraform plan failed" +terraform plan -input=false "${PREFIX_VARIABLE[@]}" -out=tfplan || fail "terraform plan failed" echo "" echo "=== Applying ===" @@ -45,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 || 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 -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/bicep/deploy.sh b/samples/eventhubs/python/bicep/deploy.sh index 84567f1..babab96 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 d77e42c..29b6748 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 fe4d3dc..285d9d0 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 bce103b..86507d3 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 9c033eb..3c77e7f 100644 --- a/samples/eventhubs/python/terraform/deploy.sh +++ b/samples/eventhubs/python/terraform/deploy.sh @@ -29,6 +29,13 @@ fail() { exit 1 } +# 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" @@ -38,7 +45,7 @@ terraform validate || fail "terraform validate failed" echo "" echo "=== Planning ===" -terraform plan -input=false -out=tfplan || fail "terraform plan failed" +terraform plan -input=false "${PREFIX_VARIABLE[@]}" -out=tfplan || fail "terraform plan failed" echo "" echo "=== Applying ===" @@ -46,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 || 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 @@ -54,7 +61,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 "${PREFIX_VARIABLE[@]}" -detailed-exitcode >/dev/null 2>&1; echo $?) if [[ "$DRIFT" == "0" ]]; then echo "Second apply is fully idempotent (no changes)." else diff --git a/samples/function-app-managed-identity/python/bicep/deploy.sh b/samples/function-app-managed-identity/python/bicep/deploy.sh index d1ca5da..ac48c57 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 43925aa..fa5889e 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 06015f1..77e240c 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 9a03d5a..4dbcfc0 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/call-http-trigger.sh b/samples/function-app-service-bus/dotnet/scripts/call-http-trigger.sh index a8384f2..2dd3aff 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-service-bus/dotnet/scripts/deploy.sh b/samples/function-app-service-bus/dotnet/scripts/deploy.sh index 420add4..f00c9d2 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 1440792..113b339 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/function-app-storage-http/dotnet/scripts/call-http-triggers.sh b/samples/function-app-storage-http/dotnet/scripts/call-http-triggers.sh index 73f819b..4e0ee56 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/function-app-storage-http/dotnet/scripts/validate.sh b/samples/function-app-storage-http/dotnet/scripts/validate.sh index 6e0c254..d51574a 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 diff --git a/samples/servicebus/java/bicep/deploy.sh b/samples/servicebus/java/bicep/deploy.sh index bc8335d..539fc23 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" @@ -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/servicebus/java/scripts/deploy.sh b/samples/servicebus/java/scripts/deploy.sh index 7697b05..474f09e 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 1a76af4..8f2121e 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 4c9875a..9d80eb5 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/README.md b/samples/url-shortener/python/README.md index 0d3f915..0dbacde 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 89d27b0..a241b94 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 e8b9132..a3ae3a6 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 @@ -87,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/call-web-app.sh b/samples/url-shortener/python/scripts/call-web-app.sh index bc4e393..3c201e6 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 36b2045..2655b31 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" @@ -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 eda8689..167150c 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}" @@ -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 cd9d618..6f30b62 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 8d61fa1..822e89d 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)" @@ -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" <" 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 f98ceac..73326a7 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/bicep/deploy.sh b/samples/web-app-cosmosdb-mongodb-api/dotnet/bicep/deploy.sh index b3681de..11a28e9 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/call-web-app.sh b/samples/web-app-cosmosdb-mongodb-api/dotnet/scripts/call-web-app.sh index 6620a4c..8944c24 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/dotnet/scripts/deploy.sh b/samples/web-app-cosmosdb-mongodb-api/dotnet/scripts/deploy.sh index 921f5b7..b977363 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 ba06a3b..6c24d74 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/call-web-app.sh b/samples/web-app-cosmosdb-mongodb-api/python/scripts/call-web-app.sh index 6620a4c..8944c24 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-mongodb-api/python/scripts/deploy.sh b/samples/web-app-cosmosdb-mongodb-api/python/scripts/deploy.sh index 832f603..e7ceb62 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/call-web-app.sh b/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/call-web-app.sh index 6f4db11..dc38dd7 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/dotnet/scripts/deploy.sh b/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/deploy.sh index ef3049f..e682302 100755 --- a/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/deploy.sh +++ b/samples/web-app-cosmosdb-nosql-api/dotnet/scripts/deploy.sh @@ -40,62 +40,129 @@ 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 \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --locations regionName=$LOCATION \ - --query "documentEndpoint" \ - --output tsv) - -echo "Account created" -echo "AZURECOSMOSDB_ENDPOINT set to $AZURECOSMOSDB_ENDPOINT" +# 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 "Create CosmosDB NoSQL Database" +# 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 + --resource-group $RESOURCE_GROUP_NAME \ + --name $AZURECOSMOSDB_DATABASENAME \ + --account-name $WEB_APP_NAME \ + --only-show-errors 1>/dev/null -echo "Create CosmosDB NoSQL Container" +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 + +# 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 - -echo "Fetching DB Account primary master key" -export AZURECOSMOSDB_PRIMARY_KEY=$(az cosmosdb keys list \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --query "primaryMasterKey" \ - --output tsv) -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 -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 -echo "Web App created" - -echo "Configure appsettings environment variables" + --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 + +# 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 + +# 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 + +# 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 + +# 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 + --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]..." @@ -119,11 +186,18 @@ zip -r "$ZIPFILE" . -x "bin/*" "obj/*" "publish/*" "*.zip" echo "Deploying web app [$WEB_APP_NAME] with zip file [$ZIPFILE]..." echo "Using az webapp deploy command for LocalStack emulator environment." az webapp deploy \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --src-path ${ZIPFILE} \ - --type zip \ - --async true + --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 # Remove the zip package of the web app if [ -f "$ZIPFILE" ]; 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 6f4db11..dc38dd7 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-cosmosdb-nosql-api/python/scripts/deploy.sh b/samples/web-app-cosmosdb-nosql-api/python/scripts/deploy.sh index d21700c..befa697 100755 --- a/samples/web-app-cosmosdb-nosql-api/python/scripts/deploy.sh +++ b/samples/web-app-cosmosdb-nosql-api/python/scripts/deploy.sh @@ -40,62 +40,129 @@ 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 \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --locations regionName=$LOCATION \ - --query "documentEndpoint" \ - --output tsv) - -echo "Account created" -echo "AZURECOSMOSDB_ENDPOINT set to $AZURECOSMOSDB_ENDPOINT" +# 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 "Create CosmosDB NoSQL Database" +# 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 + --resource-group $RESOURCE_GROUP_NAME \ + --name $AZURECOSMOSDB_DATABASENAME \ + --account-name $WEB_APP_NAME \ + --only-show-errors 1>/dev/null -echo "Create CosmosDB NoSQL Container" +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 + +# 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 - -echo "Fetching DB Account primary master key" -export AZURECOSMOSDB_PRIMARY_KEY=$(az cosmosdb keys list \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --query "primaryMasterKey" \ - --output tsv) -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 -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 -echo "Web App created" - -echo "Configure appsettings environment variables" + --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 + +# 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 + +# 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 + +# 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 + +# 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 + --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]..." @@ -119,11 +186,18 @@ zip -r "$ZIPFILE" app.py cosmosdb_client.py gunicorn.conf.py static templates re echo "Deploying web app [$WEB_APP_NAME] with zip file [$ZIPFILE]..." echo "Using az webapp deploy command for LocalStack emulator environment." az webapp deploy \ - --resource-group $RESOURCE_GROUP_NAME \ - --name $WEB_APP_NAME \ - --src-path ${ZIPFILE} \ - --type zip \ - --async true + --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 # 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 e90e37b..423497e 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 afa6a03..41aed4e 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 e90e37b..423497e 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 afa6a03..41aed4e 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 d4cc198..05d5410 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 c11db53..3106622 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/call-web-app.sh b/samples/web-app-managed-identity/dotnet/scripts/call-web-app.sh index 6f4db11..dc38dd7 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/dotnet/scripts/cli.sh b/samples/web-app-managed-identity/dotnet/scripts/cli.sh index af19a3f..2052c6e 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 eec215f..b15d8e8 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 014aad1..23d24e5 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 cc9020f..9d5ee5d 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 c11db53..3106622 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/call-web-app.sh b/samples/web-app-managed-identity/python/scripts/call-web-app.sh index 6f4db11..dc38dd7 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-managed-identity/python/scripts/cli.sh b/samples/web-app-managed-identity/python/scripts/cli.sh index af19a3f..2052c6e 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 ca2facd..587c869 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 b50054d..d9ed8a2 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 48ba9a1..57bd2df 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/call-web-app.sh b/samples/web-app-mysql-flexible-server/dotnet/scripts/call-web-app.sh index f98ceac..73326a7 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/dotnet/scripts/deploy.sh b/samples/web-app-mysql-flexible-server/dotnet/scripts/deploy.sh index 6ec74f4..6f5f4ca 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 556c63b..47bcb2f 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/call-web-app.sh b/samples/web-app-mysql-flexible-server/python/scripts/call-web-app.sh index f98ceac..73326a7 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-mysql-flexible-server/python/scripts/deploy.sh b/samples/web-app-mysql-flexible-server/python/scripts/deploy.sh index f4c35e7..2203f96 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 6391c13..ff9750b 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/call-web-app.sh b/samples/web-app-postgresql-flexible-server/dotnet/scripts/call-web-app.sh index f98ceac..73326a7 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/dotnet/scripts/deploy.sh b/samples/web-app-postgresql-flexible-server/dotnet/scripts/deploy.sh index 275044e..6204004 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 84146aa..fedd6e1 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/call-web-app.sh b/samples/web-app-postgresql-flexible-server/python/scripts/call-web-app.sh index f98ceac..73326a7 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-postgresql-flexible-server/python/scripts/deploy.sh b/samples/web-app-postgresql-flexible-server/python/scripts/deploy.sh index 01a7511..e3fe497 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 2ae5eac..162dc1b 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/call-web-app.sh b/samples/web-app-sql-database/dotnet/scripts/call-web-app.sh index 5daec1d..ca91e2b 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/dotnet/scripts/deploy.sh b/samples/web-app-sql-database/dotnet/scripts/deploy.sh index 4e3d440..2f033e3 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 f3b6de1..6f58254 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/call-web-app.sh b/samples/web-app-sql-database/python/scripts/call-web-app.sh index 9d7434f..7500002 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 diff --git a/samples/web-app-sql-database/python/scripts/deploy.sh b/samples/web-app-sql-database/python/scripts/deploy.sh index 35e080b..62e7c44 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