terraform-github-actions

tofu-destroy-workspace action

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

This action uses the tofu destroy command to destroy all resources in an OpenTofu 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: tofu destroy
        uses: dflook/tofu-destroy-workspace@v1
        with:
          path: tofu
          workspace: $

This example retries the tofu destroy operation if it fails.

name: Cleanup

on:
  pull_request:
    types: [closed]

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

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

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