Skip to content

Commit 77d02a7

Browse files
committed
VED-507: change teardown pipeline
1 parent 52cd35a commit 77d02a7

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

azure/azure-pr-teardown-pipeline.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,25 @@ jobs:
4848
account_id="$(aws sts get-caller-identity --query Account --output text)"
4949
5050
cd terraform
51-
terraform workspace select $(WORKSPACE)
52-
export ENVIRONMENT=$(WORKSPACE)
51+
export WORKSPACE="pr-${ACTION_PR_NUMBER}"
52+
export ENVIRONMENT="$WORKSPACE"
53+
export BUCKET_NAME="immunisation-${WORKSPACE}-terraform-state-files"
54+
55+
# Check if PR state bucket exists
56+
echo "Checking for existence of: s3://${BUCKET_NAME}"
57+
if aws s3api head-bucket --bucket "$BUCKET_NAME" 2>/dev/null; then
58+
echo "Bucket exists. Proceeding with init..."
59+
make init
60+
else
61+
echo "Bucket does NOT exist. Using fallback environment 'internal-dev' for init only."
62+
export ENVIRONMENT="internal-dev"
63+
export BUCKET_NAME="immunisation-internal-dev-terraform-state-files"
64+
make init
65+
66+
# Restore ENVIRONMENT to PR
67+
export ENVIRONMENT="$WORKSPACE"
68+
export BUCKET_NAME="immunisation-${WORKSPACE}-terraform-state-files"
69+
fi
5370
make init-reconfigure && make destroy aws_account_no=${account_id} environment=$(WORKSPACE)
5471
displayName: Destroy terraform PR workspace and linked resources
5572
retryCountOnTaskFailure: 2

0 commit comments

Comments
 (0)