Skip to content

Destroy AWS Infrastructure #1

Destroy AWS Infrastructure

Destroy AWS Infrastructure #1

name: Terraform Destroy (manual)
on:
workflow_dispatch:
inputs:
auto_approve:
description: 'Se true, aplica o destroy automaticamente. Caso contrário, encerra após mostrar o plano.'
required: false
default: 'true'
jobs:
destroy:
name: Terraform destroy
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: '1.5.7'
- 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
env:
TF_IN_AUTOMATION: true
run: |
terraform init -input=false
- name: Terraform plan (destroy)
env:
TF_IN_AUTOMATION: true
run: |
terraform plan -destroy -out=destroy.tfplan -input=false
- name: Show plan
run: terraform show -no-color destroy.tfplan
- name: Terraform destroy (apply plan)
if: ${{ github.event.inputs.auto_approve == 'true' }}
env:
TF_IN_AUTOMATION: true
run: |
terraform apply -input=false -auto-approve destroy.tfplan
- name: Exit after showing plan (no auto-approve)
if: ${{ github.event.inputs.auto_approve != 'true' }}
run: |
echo "auto_approve is not 'true' — the destroy plan has been created as destroy.tfplan. To apply, re-run this workflow with auto_approve=true or run 'terraform apply destroy.tfplan' locally."