Skip to content

CICD-245 · Controlled infrastructure destruction ​

Encyclopedia · Terraform and infrastructure as code · All snippets

Previous · CICD-244 · Next · CICD-246

1. Where it fits ​

  • Placement CI run step or authorized lab terminal.
  • Prerequisites trusted Linux runner, Terraform CLI, reviewed IaC and a disposable state for writes.
  • Platforms local-linux, github-actions, gitea-actions.
  • Parameters TF_WORKSPACE.

2. Copy the snippet ​

bash
test "${TF_WORKSPACE:?}" = lab-disposable
test "$(terraform workspace show)" = "$TF_WORKSPACE"
terraform plan -destroy -input=false -out=destroy.tfplan
terraform show -no-color destroy.tfplan

3. How it works ​

The first checks confirm the disposable workspace identity. Terraform then renders a destroy plan for review without applying it.

4. Verify the result ​

Prepare only a reviewed destruction plan in an isolated sandbox. Apply the reviewed file through CICD-237 after separate approval.

Validation syntax-validated (Bash parse). Status definitions.