@@ -100,9 +100,40 @@ jobs:
100
100
DB_SECRET_ARN : ${{ steps.get-db-secret-arn.outputs.DB_SECRET_ARN }}
101
101
DOCKER_DIGEST : ${{ steps.get-docker-image-digest.outputs.DIGEST }}
102
102
103
+ plan-destroy :
104
+ name : Plan destruction job
105
+ runs-on : ubuntu-latest
106
+ permissions :
107
+ id-token : write
108
+ steps :
109
+ - name : Checkout code
110
+ uses : actions/checkout@v4
111
+ - name : Configure AWS Credentials
112
+ uses : aws-actions/configure-aws-credentials@v4
113
+ with :
114
+ role-to-assume : ${{ env.aws_role }}
115
+ aws-region : eu-west-2
116
+ - name : Install terraform
117
+ uses : hashicorp/setup-terraform@v3
118
+ with :
119
+ terraform_version : 1.10.5
120
+ - name : Terraform Plan
121
+ run : |
122
+ set -e
123
+ terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
124
+ terraform plan -destroy -var-file="env/${{ inputs.environment }}.tfvars" -var="image_digest=filler_value" \
125
+ -var="db_secret_arn=filler_value" -var="imported_snapshot=filler_value" \
126
+ -out ${{ runner.temp }}/tfplan_destroy | tee ${{ runner.temp }}/tf_stdout
127
+ - name : Upload artifact
128
+ uses : actions/upload-artifact@v4
129
+ with :
130
+ name : tfplan_destroy_infrastructure-${{ inputs.environment }}
131
+ path : ${{ runner.temp }}/tfplan_destroy
132
+
103
133
destroy :
104
134
name : Destroy data replication infrastructure
105
135
runs-on : ubuntu-latest
136
+ needs : plan-destroy
106
137
environment : ${{ inputs.environment }}
107
138
permissions :
108
139
id-token : write
@@ -118,13 +149,17 @@ jobs:
118
149
uses : hashicorp/setup-terraform@v3
119
150
with :
120
151
terraform_version : 1.10.5
152
+ - name : Download artifact
153
+ uses : actions/download-artifact@v4
154
+ with :
155
+ name : tfplan_destroy_infrastructure-${{ inputs.environment }}
156
+ path : ${{ runner.temp }}
121
157
- name : Terraform Destroy
122
158
id : destroy
123
159
run : |
124
160
set -e
125
161
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
126
- terraform destroy -var-file="env/${{ inputs.environment }}.tfvars" -var="image_digest=filler_value" \
127
- -var="db_secret_arn=filler_value" -var="imported_snapshot=filler_value" -auto-approve
162
+ terraform apply ${{ runner.temp }}/tfplan_destroy
128
163
129
164
plan :
130
165
if : ${{ inputs.action == 'Recreate' }}
0 commit comments