Skip to content

Terraform Destroy

Terraform Destroy #1

Workflow file for this run

name: Terraform Destroy
on:
workflow_dispatch:
inputs:
environment:
description: "Environment to destroy"
required: true
type: choice
options:
- staging
- prod
env:
TF_WORKING_DIR: terraform/
jobs:
destroy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.5.6
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Terraform Init
working-directory: ${{ env.TF_WORKING_DIR }}
run: terraform init -input=false
- name: Terraform Destroy
working-directory: ${{ env.TF_WORKING_DIR }}
run: |
if [ "${{ github.event.inputs.environment }}" = "staging" ]; then
terraform destroy -var-file="staging.tfvars" -auto-approve
else
terraform destroy -var-file="prod.tfvars" -auto-approve
fi