From 1124438bbc39b6433bc5cf62dfbc8944cdb9ec3e Mon Sep 17 00:00:00 2001 From: Abby Artagame Date: Tue, 12 Nov 2024 10:47:06 +1100 Subject: [PATCH] Added tf destroy --- .github/workflows/tf-plan-apply.yml | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/.github/workflows/tf-plan-apply.yml b/.github/workflows/tf-plan-apply.yml index d737b1e..3a1a7f6 100644 --- a/.github/workflows/tf-plan-apply.yml +++ b/.github/workflows/tf-plan-apply.yml @@ -161,3 +161,44 @@ jobs: - name: Terraform Apply run: | terraform apply -auto-approve terraform.tfplan + + terraform-destroy: + name: 'Terraform Destroy' + if: github.ref == 'refs/heads/main' && needs.terraform-plan.outputs.tfplanExitCode == 2 + runs-on: ubuntu-latest + defaults: + run: + shell: bash + working-directory: ./tf + environment: DEV + needs: [terraform-plan] + + steps: + # Checkout the repository to the GitHub Actions runner + - name: Checkout + uses: actions/checkout@v4 + + # Install the latest version of Terraform CLI and configure the Terraform CLI configuration file with a Terraform Cloud user API token + - name: Setup Terraform + uses: hashicorp/setup-terraform@v3 + + # Initialize a new or existing Terraform working directory by creating initial files, loading any remote state, downloading modules, etc. + - name: Terraform Init + run: terraform init + + # Download saved plan from artifacts + - name: Download Terraform Plan + uses: actions/download-artifact@v4 + with: + path: tf + name: tfplan + + # Terraform Plan Destroy - Check what to destroy + - name: Terraform Plan Destroy + run: | + terraform plan -destroy -auto-approve terraform.tfplan + + # # Terraform Destroy + # - name: Terraform Destroy + # run: | + # terraform apply -auto-approve terraform.tfplan \ No newline at end of file