Block Terraform and Helmfile destroy
Deny Terraform and Helmfile destroy, including the Terraform destroy flag on plan, apply, and deploy.
apiVersion: atmos/v1
kind: Policy
metadata:
name: command-deny-destroy
description: Deny Terraform and Helmfile destroy, including the Terraform destroy flag on plan, apply, and deploy.
spec:
policies:
guard:
on: command
action: deny
rule: input.command == 'terraform destroy' || input.destroy
1 Configure
No parameters. The rule matches the terraform destroy command, and every invocation where the
normalized destroy input is true. Atmos derives destroy from the arguments, so the rule does not
parse flags itself.
destroy is true when:
- the command is
terraform destroy(also through thetfalias) orhelmfile destroy, or - a
terraformcommand (OpenTofu included) such asplan,apply, ordeployreceives the-destroyor--destroyflag, including when it comes after--.
A true flag value counts: -destroy=true, --destroy=1, -destroy=T. A false value does not:
-destroy=false, -destroy=0. An unparseable value counts as true, and any true occurrence wins over a
later false. Other commands, and other argument values, never set destroy.
For example, atmos terraform apply vpc -s prod -destroy -auto-approve is denied, while
atmos terraform apply vpc -s prod -destroy=false is allowed.
Limits:
atmos terraform apply <planfile>cannot be recognized as a destroy when the saved plan came fromplan -destroy. The plan was already created; govern it withterraform.planpolicies, such asterraform-protect-stateful-resources.- Resource removal through other commands, tools, or direct Terraform use outside Atmos is not covered,
for example
helm deleteor deleting resources from configuration. Pair this policy with saved-plan deletion policies when resource-level protection is required.
2 Save
Save the CEL policy as policy.d/command-deny-destroy.yaml. Install only one implementation of each policy.
Atmos discovers policy.d/ at the project root selected by atmos.yaml discovery. Set ATMOS_POLICY_DIR to use another directory.
3 Run
atmos terraform destroy vpc -s prod
Review required tools and callback settings before running. In CI, load policies from a protected, pinned revision. See enforcement configuration.