POLICY
Protect stateful resources
Reject deletion or replacement of selected stateful resource types.
Policy reason
Stateful resources must not be deleted or replaced
policy.d/terraform-protect-stateful-resources.yaml
apiVersion: atmos/v1
kind: Policy
metadata:
name: terraform-protect-stateful-resources
description: "Reject deletion or replacement of selected stateful resource types."
spec:
policies:
protect-stateful-resources:
on: terraform.plan
action: deny
reason: Stateful resources must not be deleted or replaced
with:
types:
- aws_db_instance
- aws_rds_cluster
- aws_s3_bucket
rule: >-
has(input.resource_changes) && input.resource_changes.exists(r,
r.mode == 'managed' && r.type in params.types && 'delete' in r.change.actions)
1 Configure
types: [aws_db_instance, aws_rds_cluster, aws_s3_bucket].
Updates and unrelated types pass. Both replacement orders are denied.
2 Save
Save the CEL policy as policy.d/terraform-protect-stateful-resources.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
Replace <component> and <stack> with your target.
atmos terraform plan <component> -s <stack>
Review required tools and callback settings before running. In CI, load policies from a protected, pinned revision. See enforcement configuration.