https://github.com/mattias-fjellstrom/tfc-delete-workspace
GitHub Action for deleting an existing workspace from Terraform Cloud
https://github.com/mattias-fjellstrom/tfc-delete-workspace
github-actions hashicorp hashicorp-terraform terraform terraform-cloud
Last synced: about 1 month ago
JSON representation
GitHub Action for deleting an existing workspace from Terraform Cloud
- Host: GitHub
- URL: https://github.com/mattias-fjellstrom/tfc-delete-workspace
- Owner: mattias-fjellstrom
- License: mit
- Created: 2023-03-19T14:07:45.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-19T14:09:48.000Z (about 2 years ago)
- Last Synced: 2025-02-13T15:19:10.155Z (3 months ago)
- Topics: github-actions, hashicorp, hashicorp-terraform, terraform, terraform-cloud
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# GitHub Actions for deleting an existing workspaces from Terraform Cloud
With this action you can delete an existing workspaces from Terraform Cloud as part of your GitHub Actions workflows.
- This action should be preceded by the [mattias-fjellstrom/tfc-setup](https://github.com/mattias-fjellstrom/tfc-setup/blob/main/action.yaml) action to configure required environment variables. See the sample below.
- The action only supports authenticating to Terraform Cloud using an API token, read the [Terraform Cloud documentation](https://developer.hashicorp.com/terraform/cloud-docs/users-teams-organizations/api-tokens) about tokens.
- You have to specify `organization` and `workspace` as input to this action, either as `with:` parameters or through environment variables using the [mattias-fjellstrom/tfc-setup](https://github.com/mattias-fjellstrom/tfc-setup/blob/main/action.yaml) action.## Sample workflow
Below is a full sample workflow that sets up a new workspace in Terraform Cloud when a pull-request is opened, and deletes the workspace once the pull-request is closed. If the pull request is opened for a branch named `feature-1` the resulting workspace will be named `my-workspace-feature-1` in this sample.
```yaml
name: Terraform Cloud workspaces for pull-requestson:
pull_request:
types:
- opened
- closedenv:
ORGANIZATION: my-terraform-cloud-organization
PROJECT: my-terraform-cloud-project
WORKSPACE: my-workspace-${{ github.head_ref }}jobs:
create-workspace:
if: ${{ github.event.action == 'opened' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: mattias-fjellstrom/tfc-setup@v1
with:
token: ${{ secrets.TERRAFORM_CLOUD_TOKEN }}
organization: ${{ env.ORGANIZATION }}
project: ${{ env.PROJECT }}
workspace: ${{ env.WORKSPACE }}
- uses: mattias-fjellstrom/tfc-create-workspace@v1
with:
directory: infrastructure
branch: ${{ github.head_ref }}
delete-workspace:
if: ${{ github.event.action == 'closed' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: mattias-fjellstrom/tfc-setup@v1
with:
token: ${{ secrets.TERRAFORM_CLOUD_TOKEN }}
organization: ${{ env.ORGANIZATION }}
project: ${{ env.PROJECT }}
workspace: ${{ env.WORKSPACE }}
- uses: mattias-fjellstrom/tfc-delete-workspace@v1
```