File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments