planlens / rules
Rule reference
42 checks that run against terraform show -json output. Most report only what this plan introduces, so existing debt isn't re-reported on every PR. Change severities with severity_overrides, turn rules off with disable, or accept a finding with ignore in .planlens.yml.
Stateful resource will be destroyed
Stateful resource will be replaced (destroy + create)
High-impact resource will be replaced or destroyed
Resource will be replaced or destroyed
Large number of resources destroyed
Refactor will destroy and recreate a resource
Infrastructure drifted from Terraform state
Resource will be imported
Resource address moved
Deletion protection disabled
Final snapshot disabled on database
Backups disabled or retention reduced
Encryption disabled
S3 versioning suspended
Force-destroy / immediate deletion enabled
Point-in-time recovery disabled
KMS key rotation disabled
High availability reduced
Security monitoring or logging removed
Major engine or cluster version upgrade
Capacity scaled to zero
Ingress opened to the internet
Database publicly accessible
Load balancer becomes internet-facing
Kubernetes API endpoint open to the internet
S3 Block Public Access weakened
Storage made public
IMDSv1 allowed on EC2
IAM policy grants full admin (*:*)
IAM policy grants service-wide wildcard on all resources
IAM policy allows privilege escalation
Admin-level AWS managed policy attached
Resource policy allows anyone (Principal "*")
OIDC trust policy not restricted to a subject
Role trust policy allows any AWS principal
Long-lived IAM access key created
Lambda callable by anyone
Privileged Azure role assigned
GCP IAM grants public or primitive role
Plaintext secret in resource configuration
Output exposes a secret without `sensitive = true`
Monthly cost increase above budget
PL001 · Stateful resource will be destroyed
CRITICAL default severity · data-loss
A resource that holds data (database, bucket, volume, key, DNS zone, queue…) is deleted. Unless backups exist and were tested, the data is gone.
Fix: Confirm the deletion is intended and a backup/snapshot exists. Add lifecycle { prevent_destroy = true } to resources that must never be destroyed. If you only want Terraform to stop managing it, use a removed { from = ... lifecycle { destroy = false } } block (Terraform ≥ 1.7) instead of deleting the block.
PL002 · Stateful resource will be replaced (destroy + create)
CRITICAL default severity · data-loss
Terraform must destroy and recreate a resource that holds data because an attribute that cannot be changed in place was modified. The new resource starts empty.
Fix: Revert the attribute that forces replacement, or plan a migration (snapshot/restore, blue-green). For RDS, many changes (e.g. engine version) can be done in place; check which attribute is listed under 'Forced by'.
PL003 · High-impact resource will be replaced or destroyed
HIGH default severity · availability
A resource with a large blast radius (cluster, load balancer, network, instance, IAM role, DNS record, generated secret…) is replaced or destroyed. Expect downtime, new IDs/IPs/ARNs, or broken references.
Fix: Check the 'Forced by' attribute and whether it can be changed in place. Use create_before_destroy for zero-downtime replacement where supported, and schedule the change in a maintenance window.
PL004 · Resource will be replaced or destroyed
LOW default severity · availability
Any other destroy or replace. Usually expected, listed so reviewers see every destructive action.
Fix: Confirm each destroy/replace is intended.
PL005 · Large number of resources destroyed
HIGH default severity · availability
The plan destroys or replaces more resources than the configured threshold (default 10). This is often caused by a wrong workspace, a renamed module, or a provider/backend misconfiguration.
Fix: Double-check the workspace/backend and module addresses. If this is a refactor, use moved blocks so Terraform updates addresses instead of recreating resources.
PL006 · Refactor will destroy and recreate a resource
HIGH default severity · refactor
A resource is destroyed at one address and an identical resource is created at another (rename, moved into a module, count→for_each), or removing an item from a count list shifts the indexes of everything after it. Terraform treats these as new resources.
Fix: Add a moved block from the old address to the new one so Terraform only updates state. For count index shifts, switch to for_each with stable keys.
PL007 · Infrastructure drifted from Terraform state
MEDIUM default severity · drift
Terraform detected changes made outside of Terraform (console, CLI, other automation) during refresh. Applying this plan may revert them.
Fix: Find out who changed what (CloudTrail / activity logs). Either codify the change in Terraform or let this apply revert it — deliberately.
PL008 · Resource will be imported
INFO default severity · hygiene
An existing object is being imported into Terraform state via an import block.
Fix: Make sure the configuration matches the real object so the import does not also trigger an update.
PL009 · Resource address moved
INFO default severity · refactor
A moved block changes a resource address without recreating it.
Fix: No action needed — this is the safe way to refactor.
PL101 · Deletion protection disabled
HIGH default severity · data-loss
Deletion/termination protection is turned off on an existing resource — usually the first step before an accidental destroy.
Fix: Keep deletion protection on in production. If you really need to destroy the resource, disable protection in a separate, reviewed change.
PL102 · Final snapshot disabled on database
MEDIUM default severity · data-loss
skip_final_snapshot is switched on, so destroying the database later will not leave a snapshot behind.
Fix: Keep skip_final_snapshot = false and set final_snapshot_identifier for production databases.
PL103 · Backups disabled or retention reduced
HIGH default severity · data-loss
Automated backups are turned off or their retention is shortened.
Fix: Keep automated backups enabled with a retention that meets your RPO/compliance requirements (commonly ≥ 7 days in production).
PL104 · Encryption disabled
HIGH default severity · security
Encryption at rest or in transit is off. For most storage services this cannot be enabled later without replacing the resource.
Fix: Enable encryption (ideally with a customer-managed KMS key). Required by PCI DSS 3.5, ISO 27001 A.8.24 and most internal baselines.
PL105 · S3 versioning suspended
MEDIUM default severity · data-loss
Object versioning protects against accidental overwrites and deletes (and is required for replication and Object Lock).
Fix: Keep versioning enabled on buckets that hold important data; use lifecycle rules to expire old versions instead of suspending versioning.
PL106 · Force-destroy / immediate deletion enabled
MEDIUM default severity · data-loss
Lets Terraform delete a non-empty bucket/repository/zone, or deletes a secret without a recovery window.
Fix: Only enable force-destroy on ephemeral (dev/test) resources. Keep a recovery window on secrets.
PL107 · Point-in-time recovery disabled
MEDIUM default severity · data-loss
DynamoDB point-in-time recovery is switched off.
Fix: Keep PITR enabled on production tables.
PL108 · KMS key rotation disabled
LOW default severity · security
Automatic key rotation is switched off on a KMS key.
Fix: Enable enable_key_rotation on customer-managed symmetric keys.
PL109 · High availability reduced
MEDIUM default severity · availability
Multi-AZ / automatic failover / regional availability is turned off.
Fix: Keep production databases and caches Multi-AZ.
PL110 · Security monitoring or logging removed
HIGH default severity · security
An audit/detection control (CloudTrail, GuardDuty, AWS Config, Security Hub, VPC Flow Logs, WAF association, diagnostic settings) is disabled or destroyed.
Fix: Security controls should only be removed through an explicit, approved change. Required by ISO 27001 A.8.15/A.8.16, PCI DSS 10 and SOC 2 CC7.
PL111 · Major engine or cluster version upgrade
MEDIUM default severity · availability
A database major version or Kubernetes control-plane version changes. These upgrades are one-way, can take minutes of downtime, and may break clients.
Fix: Test the upgrade on a snapshot/staging first, check deprecated APIs/extensions/parameter groups, and schedule a maintenance window. Kubernetes can only move one minor version at a time.
PL112 · Capacity scaled to zero
MEDIUM default severity · availability
An Auto Scaling group, node group or service is scaled down to zero.
Fix: Make sure nothing is still serving traffic from this capacity.
PL201 · Ingress opened to the internet
CRITICAL default severity · network
A firewall / security group rule newly allows inbound traffic from 0.0.0.0/0, ::/0 or Internet. Critical for admin, database and cache ports or all ports; low for 80/443.
Fix: Restrict the source to known CIDRs, a VPN, or a load balancer security group. For admin access use SSM Session Manager / a bastion / IAP instead of opening SSH/RDP.
PL202 · Database publicly accessible
HIGH default severity · network
A managed database gets a public endpoint, or its firewall allows the whole internet.
Fix: Keep databases in private subnets. Connect through a VPN, bastion, PrivateLink or application tier.
PL203 · Load balancer becomes internet-facing
MEDIUM default severity · network
An internal load balancer is changed to internet-facing.
Fix: Confirm the service is meant to be public and is protected (WAF, auth, TLS).
PL204 · Kubernetes API endpoint open to the internet
MEDIUM default severity · network
The EKS public API endpoint is enabled for 0.0.0.0/0.
Fix: Disable the public endpoint or restrict public_access_cidrs to office/VPN/CI egress ranges.
PL205 · S3 Block Public Access weakened
HIGH default severity · network
One or more S3 Block Public Access settings is turned off or the block is removed.
Fix: Keep all four Block Public Access settings enabled. Serve public content through CloudFront with Origin Access Control instead.
PL206 · Storage made public
HIGH default severity · network
A bucket/container ACL grants access to everyone.
Fix: Remove public ACLs. Use signed URLs or a CDN with origin access control for public content.
PL207 · IMDSv1 allowed on EC2
MEDIUM default severity · security
http_tokens = "optional" allows IMDSv1, which is exploitable via SSRF to steal instance role credentials.
Fix: Set metadata_options { http_tokens = "required" }.
PL301 · IAM policy grants full admin (*:*)
CRITICAL default severity · iam
A new policy statement allows every action on every resource (or uses NotAction with Allow).
Fix: Grant only the actions and resources the workload needs. Use IAM Access Analyzer policy generation to derive least-privilege policies from CloudTrail.
PL302 · IAM policy grants service-wide wildcard on all resources
HIGH default severity · iam
A new statement allows service:* on Resource: "*" (e.g. s3:* on every bucket in the account).
Fix: List the specific actions needed and scope Resource to specific ARNs.
PL303 · IAM policy allows privilege escalation
HIGH default severity · iam
A new statement grants actions that let the principal give itself more permissions (iam:PassRole, iam:CreatePolicyVersion, iam:Attach*Policy, iam:Put*Policy, iam:CreateAccessKey, iam:UpdateAssumeRolePolicy…) on all resources.
Fix: Scope these actions to specific role/user ARNs, and constrain iam:PassRole with an iam:PassedToService condition.
PL304 · Admin-level AWS managed policy attached
CRITICAL default severity · iam
AdministratorAccess, IAMFullAccess, PowerUserAccess or another *FullAccess managed policy is attached.
Fix: Replace with a customer-managed least-privilege policy. Reserve AdministratorAccess for break-glass roles behind MFA.
PL305 · Resource policy allows anyone (Principal "*")
CRITICAL default severity · iam
A bucket/queue/topic/key/secret policy statement allows Principal: "*" without any Condition — the resource is public to every AWS account and often the internet.
Fix: Name explicit principals, or add conditions such as aws:PrincipalOrgID, aws:SourceVpce or aws:SourceArn.
PL306 · OIDC trust policy not restricted to a subject
CRITICAL default severity · iam
A role trusts a web-identity provider (GitHub Actions, EKS IRSA, GitLab, Terraform Cloud…) without restricting the token subject (:sub). For GitHub, that means any repository on github.com can assume the role.
Fix: Add a StringEquals/StringLike condition on <provider>:sub, e.g. token.actions.githubusercontent.com:sub = repo:my-org/my-repo:ref:refs/heads/main, and on :aud.
PL307 · Role trust policy allows any AWS principal
CRITICAL default severity · iam
An IAM role can be assumed by Principal: {"AWS": "*"} — every AWS account in the world.
Fix: Name the exact accounts/roles that may assume it, and require sts:ExternalId for third parties.
PL308 · Long-lived IAM access key created
MEDIUM default severity · secrets
A static IAM access key is created. The secret ends up in Terraform state.
Fix: Prefer IAM roles (IRSA, instance profiles, OIDC federation for CI). If a key is unavoidable, rotate it and keep state encrypted with restricted access.
PL309 · Lambda callable by anyone
HIGH default severity · iam
A Lambda permission allows principal * without source_arn/source_account/principal_org_id, or a function URL has no auth.
Fix: Restrict the permission with source_arn (the calling service resource) or use AWS_IAM auth on function URLs.
PL310 · Privileged Azure role assigned
HIGH default severity · iam
Owner / Contributor / User Access Administrator is assigned at subscription or management-group scope (high) or resource-group scope (medium).
Fix: Use built-in least-privilege roles or custom roles, assign at the narrowest scope, and use PIM for just-in-time elevation.
PL311 · GCP IAM grants public or primitive role
HIGH default severity · iam
A GCP IAM binding grants access to allUsers/allAuthenticatedUsers (critical) or a primitive/admin role such as roles/owner or roles/editor (high).
Fix: Grant predefined least-privilege roles to specific groups/service accounts. Never bind allUsers to non-public data.
PL401 · Plaintext secret in resource configuration
HIGH default severity · secrets
A credential-looking value (API key, token, private key, password-named environment variable) is set as plain text. It ends up in the plan, the state file, CI logs and the provider's console.
Fix: Reference secrets from Secrets Manager / SSM SecureString / Key Vault / Secret Manager at runtime (ECS secrets, Lambda extension, CSI driver) instead of literal values, and rotate any value that was already committed.
PL402 · Output exposes a secret without `sensitive = true`
HIGH default severity · secrets
An output whose name or value looks like a credential is not marked sensitive, so it is printed in CI logs and readable via terraform output.
Fix: Add sensitive = true to the output, or stop exporting the secret and have consumers read it from a secret store.
PL501 · Monthly cost increase above budget
HIGH default severity · cost
The Infracost estimate for this plan raises the monthly bill by more than cost.max_monthly_increase (absolute) or cost.max_monthly_increase_percent. Only active when an Infracost file is provided and a threshold is configured.
Fix: Check the largest cost deltas (instance sizes, NAT gateways, provisioned IOPS, data transfer). Right-size, use Savings Plans/Spot, or get the budget owner's approval and record it with an ignore entry.