terraform-github-actions

terraform-destroy-workspace action

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

This action uses the terraform destroy command to destroy all resources in a Terraform workspace and then delete the workspace.

Inputs

Outputs

Environment Variables

Example usage

This example deletes the workspace named after the git branch when the associated PR is closed.

name: Destroy testing workspace

on:
  pull_request:
    types: [closed]

jobs:
  integration:
    runs-on: ubuntu-latest
    name: Cleanup after integration tests
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: terraform destroy
        uses: dflook/terraform-destroy-workspace@v1
        with:
          path: terraform
          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-workspace@v1
        id: first_try
        continue-on-error: true
        with:
          path: my-terraform-config
          workspace: $

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