terraform-github-actions

terraform-destroy action

This is one of a suite of Terraform related actions - find them at dflook/terraform-github-actions.

:warning: This action uses the terraform destroy command to immediately destroy all resources in a terraform workspace.

To generate a plan that can be reviewed you can instead use the dflook/terraform-plan and dflook/terraform-apply actions with the destroy input set to true.

Inputs

Outputs

Environment Variables

Example usage

This example destroys the resources in a workspace named after the git branch when the associated PR is closed.

name: Cleanup

on:
  pull_request:
    types: [closed] 

jobs:
  destroy_workspace:
    runs-on: ubuntu-latest
    name: Destroy Terraform workspace
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: terraform destroy
        uses: dflook/terraform-destroy@v1
        with:
          path: my-terraform-config
          workspace: $

This example retries the terraform destroy operation if it fails.

name: Cleanup

on:
  pull_request:
    types: [closed]

jobs:
  destroy_workspace:
    runs-on: ubuntu-latest
    name: Destroy Terraform workspace
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: terraform destroy
        uses: dflook/terraform-destroy@v1
        id: first_try
        continue-on-error: true
        with:
          path: my-terraform-config
          workspace: $

      - name: Retry failed destroy
        uses: dflook/terraform-destroy@v1
        if: $
        with:
          path: my-terraform-config
          workspace: $