Skip to content

Destroy

Destroy #5

Workflow file for this run

name: Destroy
on:
workflow_run:
workflows: ["Deploy"]
types:
- completed
workflow_dispatch:
jobs:
destroy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'failure' || github.event_name == 'workflow_dispatch' }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
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: Set up Terraform
uses: hashicorp/setup-terraform@v3
- name: Empty S3 bucket
run: |
aws s3 rm s3://$BUCKET_NAME --recursive
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
- name: Destroy Terraform
working-directory: ./terraform
run: |
gpg --quiet --batch --yes --decrypt --passphrase="$SECRET_PASSPHRASE" --output variables.tfvars variables.tfvars.gpg
terraform init
terraform destroy -var-file=variables.tfvars -auto-approve
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
SECRET_PASSPHRASE: ${{ secrets.SECRET_PASSPHRASE }}