Skip to content

Commit 8f6e8d4

Browse files
committed
workspace env
1 parent 7e6624a commit 8f6e8d4

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

azure/azure-pr-teardown-pipeline.yml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,28 @@ jobs:
4747
export AWS_PROFILE=apim-dev
4848
account_id="$(aws sts get-caller-identity --query Account --output text)"
4949
50-
export ENVIRONMENT="internal-dev"
51-
export BUCKET_NAME="immunisation-internal-dev-terraform-state-files"
50+
export environment="internal-dev"
51+
export sub_environment="$(WORKSPACE)"
52+
53+
echo "Checking if bucket immunisation-${sub_environment}-terraform-state-files exists..."
54+
BUCKET_NAME="immunisation-${sub_environment}-terraform-state-files"
55+
FALLBACK_BUCKET_NAME="immunisation-internal-dev-terraform-state-files"
56+
57+
if ! aws s3api head-bucket --bucket "$BUCKET_NAME" 2>/dev/null; then
58+
echo "Bucket $BUCKET_NAME does NOT exist. Falling back to internal-dev for init only..."
59+
export ENVIRONMENT="internal-dev"
60+
export BUCKET_NAME="$FALLBACK_BUCKET_NAME"
61+
else
62+
export ENVIRONMENT="$environment"
63+
export BUCKET_NAME="$BUCKET_NAME"
64+
cd terraform
5265
make init
5366
54-
55-
export ENVIRONMENT="pr-703"
56-
export BUCKET_NAME="immunisation-pr-703-terraform-state-files"
67+
export ENVIRONMENT="$sub_environment"
68+
export BUCKET_NAME="immunisation-${sub_environment}-terraform-state-files"
5769
5870
cd terraform
59-
terraform workspace select $(WORKSPACE)
60-
make destroy aws_account_no=${account_id} environment=$(WORKSPACE)
71+
make workspace sub_environment=$sub_environment
72+
make destroy sub_environment=$sub_environment aws_account_no=${account_id}
6173
displayName: Destroy terraform PR workspace and linked resources
6274
retryCountOnTaskFailure: 2

terraform/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ lock-provider:
2020
$(tf_cmd) providers lock -platform=darwin_arm64 -platform=darwin_amd64 -platform=linux_amd64 -platform=windows_amd64
2121

2222
workspace:
23-
ifndef sub_environment
24-
$(error sub_environment is not set. Use 'make workspace sub_environment=your-env')
25-
endif
2623
$(tf_cmd) workspace new $(sub_environment) || $(tf_cmd) workspace select $(sub_environment) && echo "Switched to workspace/environment: $(sub_environment)"
2724

2825
init:

0 commit comments

Comments
 (0)