@@ -100,9 +100,40 @@ jobs:
100100 DB_SECRET_ARN : ${{ steps.get-db-secret-arn.outputs.DB_SECRET_ARN }}
101101 DOCKER_DIGEST : ${{ steps.get-docker-image-digest.outputs.DIGEST }}
102102
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+
103133 destroy :
104134 name : Destroy data replication infrastructure
105135 runs-on : ubuntu-latest
136+ needs : plan-destroy
106137 environment : ${{ inputs.environment }}
107138 permissions :
108139 id-token : write
@@ -118,13 +149,17 @@ jobs:
118149 uses : hashicorp/setup-terraform@v3
119150 with :
120151 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 }}
121157 - name : Terraform Destroy
122158 id : destroy
123159 run : |
124160 set -e
125161 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
128163
129164 plan :
130165 if : ${{ inputs.action == 'Recreate' }}
0 commit comments