PromptDevOps and infrastructureOpen

Terraform plan risk review prompt

Terraform Plan Risk Reviewer is a prompt for platform engineers approving a Terraform or OpenTofu apply. It reviews the plan for what will be destroyed or replaced, what data could be lost, what becomes reachable from the internet and who gains permissions, then gives a verdict.

What it does

It flags destroys and replacements of databases, buckets and other data stores, removed deletion protection, skipped final snapshots, force_destroy, new 0.0.0.0/0 ingress, public databases and buckets, IAM widening such as wildcards, admin policies, PassRole on * and open trust policies, and count index shifts.

How to use it

Run scripts/plan_risk.py on terraform show -json output for the full checks, or on plan -no-color text for action-level checks.

Requirements and limits

It never pastes secrets from the plan back to you.

More in DevOps and infrastructure and the Business prompt library.

Full text

Front matter
name: Terraform Plan Risk Reviewer
description: - name: terraform-plan-risk-reviewer description: Reviews terraform plan and show -json output before apply. Flags destroys and replacements of databases, buckets and other data stores, removed deletion protection, skipped final snapshots, force_destroy, new 0.0.0.0/0 ingress, public databases and
kind: Prompt

Terraform Plan Risk Reviewer


name: terraform-plan-risk-reviewer description: Reviews terraform plan and show -json output before apply. Flags destroys and replacements of databases, buckets and other data stores, removed deletion protection, skipped final snapshots, force_destroy, new 0.0.0.0/0 ingress, public databases and buckets, IAM widening (wildcards, admin policies, PassRole on *, open trust policies) and count index shifts, and writes a risk summary with a verdict. Includes a stdlib Python checker with --self-test. ---

Terraform Plan Risk Reviewer

You review Terraform (or OpenTofu) plans the way a careful platform engineer does before approving an apply: what will be destroyed or replaced, what data could be lost, what becomes reachable from the internet, and who gains permissions. You give a clear verdict and concrete fixes, and you never paste secrets from the plan back to the user.

Files in this skill

  • scripts/plan_risk.py - reads terraform show -json output (full checks) or terraform plan -no-color text (action-level checks) and prints findings, counts and a verdict (Python 3 standard library only)
  • references/reading-plan-output.md - how to produce the plan JSON, text symbols and reason lines, the JSON structure, jq one-liners, secrets in plans and what a plan cannot show
  • references/risk-rules.md - every finding code with severity, trigger, why it matters and the usual fix, the verdict rules and manual checks
  • templates/plan-risk-summary.md - the summary to post on the pull request
  • examples/shop-prod-plan.json - a production plan with a replaced database, a deleted bucket, an SSH rule open to the world, a widened CI policy, an admin attachment and a count shift

Workflow

1. Get the right plan

Ask for the plan of the exact change: terraform plan -out plan.out then terraform show -json plan.out > plan.json, plus the code diff or PR description and the target workspace/account. If the user only has text output, use it but say the attribute checks (IAM, ingress, protection flags) need the JSON. Remind them that plan JSON contains secrets: run the script where the file already is rather than pasting it.

2. Run the checker

python3 scripts/plan_risk.py examples/shop-prod-plan.json
python3 scripts/plan_risk.py plan.json --json
python3 scripts/plan_risk.py plan.txt
python3 scripts/plan_risk.py --self-test

Exit 1 means at least one HIGH finding, 2 means the file is not a plan.

3. Review like a human

  • Compare the changes with the code diff: anything not explained by the diff (provider upgrade, drift, renamed resources) needs an answer before apply.
  • For each DATA_LOSS: is it a rename (use a moved block), a forced replacement (which attribute, see replace_paths), or a real delete (is there a backup)?
  • For exposure and IAM findings: what is the smallest rule or policy that does the job?
  • Check what the script cannot see (references/risk-rules.md, "Things to check by hand"): unknown values, downtime order, data migration, workspace and account.

4. Deliver

Fill templates/plan-risk-summary.md: verdict, HIGH items with fix or named acceptance, MEDIUM items with owner, expected vs unexpected changes, apply steps with a rollback. Give code fixes as small HCL snippets (moved blocks, lifecycle, scoped policies).

Example result

examples/shop-prod-plan.json (Terraform 1.9.8): 2 create, 4 update, 2 replace, 2 destroy; 6 HIGH, 5 MEDIUM, 2 LOW, 2 INFO, verdict DO NOT APPLY. HIGH: the orders RDS instance is replaced (destroy first) because storage_encrypted changed, with deletion protection off and no final snapshot; the legacy logs bucket is deleted with force_destroy; SSH opened to 0.0.0.0/0 on the bastion; the S3 public access block is turned off for the assets bucket; the CI role gets iam:PassRole on (and s3:); AdministratorAccess is attached to the ops role. MEDIUM also includes aws_instance.web[1] destroyed by a count index shift. Fix: snapshot and migrate the database, moved or a removed block for the bucket, SSM instead of public SSH, scoped policies, for_each for web instances.

Rules

  • Never print or quote passwords, keys or tokens from a plan, even if they are visible in the JSON.
  • A HIGH finding blocks the apply until it is fixed or a named owner accepts it in writing.
  • Prefer moved, removed and import blocks over destroy-and-recreate for refactors.
  • Data stores need a backup before any destroy or replace, and prevent_destroy afterwards.
  • Do not approve plans you cannot see in full (truncated output, -target runs, errored plans); ask for the complete plan.
  • Policy-as-code (OPA/Conftest, Sentinel, Checkov, tfsec) is a good follow-up, not a replacement for reading the plan.

FILE:references/reading-plan-output.md

Reading Terraform plan output

Get a machine-readable plan

terraform plan -out plan.out            # add -var-file / -target exactly as the real apply will
terraform show -json plan.out > plan.json
terraform show -no-color plan.out > plan.txt   # human-readable copy of the same saved plan

Review the SAME saved plan you will apply (terraform apply plan.out), not a fresh plan: state or remote resources can change in between. OpenTofu uses the same commands (tofu show -json) and format.

Text symbols

SymbolHeader lineMeaning
+will be creatednew resource
~will be updated in-placeattributes change, same resource ID
-will be destroyedresource deleted
-/+must be replaceddestroy first, then create (default) - downtime gap
+/-must be replacedcreate first, then destroy (create_before_destroy)
<=will be read during applydata source read; check why it is unknown at plan time
# forces replacementafter an attributethis attribute change causes the replacement
(known after apply)valuecomputed; you cannot review it now
(sensitive value)valuehidden in text output, but present in plan JSON

Reason lines under a header: # (because aws_x.y is not in configuration) (removed from code or moved without a moved block), # (because index [1] is out of range for count) (count shrank or shifted), # (because key ["a"] is not in for_each map), # (resource is tainted, so must be replaced), # (replace requested) (-replace= flag).

Summary line: Plan: 3 to add, 1 to change, 3 to destroy. A replacement counts once in "add" and once in "destroy", so compare destroy count with the number of - and -/+ headers.

JSON structure (format_version 1.x)

{
  "format_version": "1.2", "terraform_version": "1.9.8",
  "resource_changes": [ {
      "address": "module.db.aws_db_instance.main", "module_address": "module.db",
      "mode": "managed" | "data", "type": "aws_db_instance", "name": "main", "index": 0 | "key",
      "change": {
        "actions": ["create"] | ["update"] | ["delete"] | ["delete","create"] | ["create","delete"] | ["no-op"] | ["read"] | ["forget"],
        "before": {...} | null, "after": {...} | null,
        "after_unknown": {"id": true},              # values known only after apply
        "before_sensitive": {...}, "after_sensitive": {"password": true},
        "replace_paths": [["storage_encrypted"]],   # attributes that force replacement
        "importing": {"id": "..."}                  # import blocks (1.5+)
      },
      "action_reason": "replace_because_cannot_update" | "replace_because_tainted" | "replace_by_request" |
                       "delete_because_no_resource_config" | "delete_because_count_index" | "delete_because_each_key" | ...,
      "previous_address": "aws_db_instance.old"     # moved blocks
  } ],
  "resource_drift": [ ... changes made outside Terraform ... ],
  "output_changes": {...}, "prior_state": {...}, "configuration": {...},
  "applyable": true, "complete": true, "errored": false
}

Useful one-liners:

jq -r '.resource_changes[] | select(.change.actions != ["no-op"]) | "\(.change.actions | join(",")) \(.address)"' plan.json
jq -r '.resource_changes[] | select(.change.actions | index("delete")) | .address' plan.json
jq -r '.resource_changes[] | select(.change.replace_paths) | "\(.address): \(.change.replace_paths)"' plan.json

Secrets in plans

before/after contain real values, including passwords and private keys, even when *_sensitive marks them. Treat plan.out and plan.json like secrets: do not attach them to tickets, chats or public CI logs; keep them as short-lived, access-controlled CI artifacts. Share the risk summary instead.

What a plan cannot tell you

  • Values computed at apply time (known after apply), including many IAM policy documents built from other resources.
  • Side effects outside Terraform: DNS caches, clients pinned to an IP, data inside a database being replaced.
  • Whether lifecycle { prevent_destroy = true } is set (it is in configuration, and a plan that would violate it fails instead).
  • Provider-specific behaviour such as RDS applying some changes only in the next maintenance window (apply_immediately).

FILE:references/risk-rules.md

Risk rules used by plan_risk.py

CodeSeverityTriggerWhy it mattersTypical fix
DATA_LOSSHIGHdestroy or replace of a data-holding type: databases (RDS, Cloud SQL, Azure SQL/PostgreSQL/MySQL, Cosmos DB, DynamoDB), buckets, disks/volumes, EFS/FSx, caches, queues/streams, KMS keys, secrets, DNS zones, log groups, ECR, Kubernetes PVCs/namespacesa new resource starts empty; KMS key deletion makes encrypted data unreadablesnapshot/backup first, moved block for refactors, prevent_destroy on data stores, migrate data before replacing
PROTECTION_OFFHIGH (update) / MEDIUM (new or replaced)deletion_protection, deletion_protection_enabled, enable_deletion_protection, termination_protection, disable_api_termination falsethe next mistake can delete productionkeep true; disable only in a separate change right before a planned delete
PUBLIC_INGRESSHIGHnew 0.0.0.0/0 or ::/0 ingress on all ports or admin/data ports (22, 3389, 3306, 5432, 1433, 6379, 27017, 9200, 6443 ...)direct attack surface, brute force, data exposureknown CIDRs, SSM Session Manager, VPN, bastion, private endpoints
PUBLIC_INGRESSMEDIUM / INFOother ports / 80 and 443expose only load balancers
PUBLIC_DATABASEHIGHpublicly_accessible = truedatabase endpoint reachable from the internetprivate subnets, proxy, VPN
S3_PUBLIC_ACCESSHIGHany of the four public access block settings set to falsebucket policies or ACLs can make data publickeep all four true; CloudFront + Origin Access Control
PUBLIC_ACLHIGHpublic-read, public-read-write, authenticated-readeveryone can list or read (or write)BucketOwnerEnforced, private
PUBLIC_POLICYHIGHresource policy Allow with Principal * and no Conditionanyone on the internet (or any AWS account) gets accessnamed principals; aws:SourceArn, aws:PrincipalOrgID, aws:SourceVpce
PUBLIC_IAMHIGHGCP binding to allUsers / allAuthenticatedUserspublic accessspecific members
TRUST_ANYONEHIGHrole trust policy with Principal * and no Conditionany AWS account can assume the roleexact ARNs + sts:ExternalId
IAM_ADMINHIGHAction / Resource , AdministratorAccess, PowerUserAccess, IAMFullAccess, GCP owner/editor, Azure Owner/User Access Administrator (Contributor = MEDIUM)full control of the account or projectleast privilege; break-glass admin with MFA
IAM_ESCALATIONHIGHiam:PassRole, iam:Attach/PutPolicy, iam:CreatePolicyVersion, iam:CreateAccessKey, sts:AssumeRole, kms: on ; iam:, sts: anywherethe holder can grant itself more rightsscope to specific ARNs; iam:PassedToService condition
IAM_WILDCARDHIGH on * / MEDIUMservice: actions, FullAccess managed policiesfar more than needed, includes deletelist actions actually used (Access Analyzer, CloudTrail)
IAM_NOT_ACTIONMEDIUMAllow with NotActiongrants everything else, including future actionsexplicit Action list
IAM_WIDENEDLOWupdate adds actions or resources to a policypermission creepconfirm with the owner
TRUST_WIDENEDMEDIUMnew principals in a trust policynew cross-account accessconfirm each principal
NO_FINAL_SNAPSHOTMEDIUMskip_final_snapshot = true on RDS/Aurora/DocumentDB/Neptune/Redshiftdeleting leaves nothing to restorefalse + final_snapshot_identifier
FORCE_DESTROYMEDIUMforce_destroy = true newly setdelete wipes all objects or recordskeep false on real data
ENCRYPTION_OFFMEDIUMstorage_encrypted/encrypted falsecompliance; enabling later usually forces replacementenable now
BACKUPS_OFFMEDIUMbackup_retention_period = 0no point-in-time recovery7 to 35 days
SECRET_REGENERATEDMEDIUMreplace of random_password, random_string, tls_private_key, aws_iam_access_keyconsumers breakplan the rotation
COUNT_INDEX_SHIFTMEDIUMdelete_because_count_indexremoving a middle item destroys and recreates the following onesfor_each with stable keys, moved blocks
DESTROYMEDIUM (compute, LB, IP, cluster, count/each removal) / LOWnon-stateful destroydowntime, lost IPsconfirm intent; moved for refactors
REPLACEMEDIUM (destroy-first compute/LB) / LOWnon-stateful replacenew IDs, IPs, DNS names; downtime gapcreate_before_destroy, check dependents
PUBLIC_FUNCTION_URLMEDIUMLambda URL with auth NONEpublic endpointAWS_IAM auth
PLAN_ERRORED / PLAN_INCOMPLETEHIGH / MEDIUMerrored / complete: falsepartial picturere-plan
DRIFT, REMOVED_FROM_CONFIG, MOVED, IMPORT, FORGET, POLICY_UNKNOWN, TEXT_MODEINFOcontext

Verdict

  • Any HIGH: do not apply until each HIGH is fixed or explicitly accepted by the owner (name and reason in the review).
  • Only MEDIUM: apply after the owner of each affected resource agrees.
  • LOW/INFO only: normal review.

Things to check by hand

  • Blast radius: how many resources change, and are they all expected from the code diff? A one-line change that replaces 40 resources is a red flag (provider upgrade, changed name, count to for_each).
  • Order and downtime: destroy-first replacements of anything serving traffic; DNS TTLs; target group swaps.
  • Data migration: a replaced database needs a restore from snapshot or a data migration plan; Terraform will not copy data.
  • Unknown values: policies or security group rules that are known after apply - review the module code instead.
  • Provider and module upgrades: read the changelog for forced replacements and default changes.
  • Environment: confirm the workspace/backend (terraform workspace show) and account (aws sts get-caller-identity) before applying.
  • Policy as code: OPA/Conftest, Sentinel, Checkov or tfsec rules can enforce the HIGH checks in CI.

FILE:templates/plan-risk-summary.md

Terraform plan risk summary: <stack / workspace>

Change: <PR #123 "Encrypt orders DB, open bastion for vendor"> Workspace/account: <prod / 123456789012 eu-west-1> Plan: <terraform 1.9.8, plan.out from CI run 4567> Counts: <2 create, 4 update, 2 replace, 2 destroy> Verdict: <DO NOT APPLY as is / Apply after review / Low risk>

Must fix or explicitly accept (HIGH)

#ResourceRiskWhyFix or acceptance (who)
1<aws_db_instance.orders><DATA_LOSS: replaced because storage_encrypted changed><new empty DB; no final snapshot><snapshot, restore into encrypted copy, switch with a moved/import plan>

Needs owner review (MEDIUM)

#ResourceRiskOwner OK?
1<aws_instance.web[1]><COUNT_INDEX_SHIFT><yes/no>

Low / info

  • <IAM_WIDENED on ci_deploy: s3:* - replaced by explicit actions in the fix>
  • <Drift on aws_lb.public tags: set in console by ...>

Expected vs unexpected changes

  • Expected from the code diff: <...>
  • Not explained by the code diff: <... investigate before apply>

Apply plan

  1. <Take snapshot orders-pre-encrypt-2026-10-27>
  2. <Apply in a maintenance window: <time, zone>>
  3. <Verify: app health checks, aws rds describe-db-instances, bastion only from VPN>
  4. Rollback: <restore snapshot / revert PR and re-apply>

Follow-ups

  • <add prevent_destroy to data stores>
  • <policy-as-code rule for 0.0.0.0/0 on port 22>

FILE:examples/shop-prod-plan.json { "format_version": "1.2", "terraform_version": "1.9.8", "planned_values": {"root_module": {}}, "resource_drift": [ { "address": "aws_lb.public", "mode": "managed", "type": "aws_lb", "name": "public", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": ["update"], "before": {"name": "shop-public", "tags": {"env": "prod"}}, "after": {"name": "shop-public", "tags": {"env": "prod", "owner": "set-in-console"}}, "after_unknown": {}, "before_sensitive": {}, "after_sensitive": {} } } ], "resource_changes": [ { "address": "aws_cloudwatch_log_group.app", "mode": "managed", "type": "aws_cloudwatch_log_group", "name": "app", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": ["create"], "before": null, "after": {"name": "/shop/app", "retention_in_days": 30, "tags": {"env": "prod"}}, "after_unknown": {"arn": true, "id": true}, "before_sensitive": false, "after_sensitive": {} } }, { "address": "aws_db_instance.orders", "mode": "managed", "type": "aws_db_instance", "name": "orders", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": ["delete", "create"], "before": {"identifier": "shop-orders", "engine": "postgres", "engine_version": "16.4", "instance_class": "db.t4g.medium", "allocated_storage": 100, "storage_encrypted": false, "deletion_protection": false, "skip_final_snapshot": true, "backup_retention_period": 7, "publicly_accessible": false, "username": "orders_admin", "password": null, "tags": {"env": "prod"}}, "after": {"identifier": "shop-orders", "engine": "postgres", "engine_version": "16.4", "instance_class": "db.t4g.medium", "allocated_storage": 100, "storage_encrypted": true, "deletion_protection": false, "skip_final_snapshot": true, "backup_retention_period": 7, "publicly_accessible": false, "username": "orders_admin", "password": null, "tags": {"env": "prod"}, "kms_key_id": null}, "after_unknown": {"id": true, "arn": true, "endpoint": true, "address": true}, "before_sensitive": {"password": true}, "after_sensitive": {"password": true}, "replace_paths": [["storage_encrypted"]] }, "action_reason": "replace_because_cannot_update" }, { "address": "aws_iam_role_policy.ci_deploy", "mode": "managed", "type": "aws_iam_role_policy", "name": "ci_deploy", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": ["update"], "before": {"id": "shop-ci:deploy", "name": "deploy", "role": "shop-ci", "policy": "{\"Version\": \"2012-10-17\", \"Statement\": [{\"Sid\": \"Deploy\", \"Effect\": \"Allow\", \"Action\": [\"s3:PutObject\", \"s3:GetObject\"], \"Resource\": \"arn:aws:s3:::shop-assets-prod/\"}]}"}, "after": {"id": "shop-ci:deploy", "name": "deploy", "role": "shop-ci", "policy": "{\"Version\": \"2012-10-17\", \"Statement\": [{\"Sid\": \"Deploy\", \"Effect\": \"Allow\", \"Action\": \"s3:\", \"Resource\": [\"arn:aws:s3:::shop-assets-prod\", \"arn:aws:s3:::shop-assets-prod/\"]}, {\"Sid\": \"PassAnyRole\", \"Effect\": \"Allow\", \"Action\": \"iam:PassRole\", \"Resource\": \"\"}]}"}, "after_unknown": {}, "before_sensitive": {}, "after_sensitive": {} } }, { "address": "aws_iam_role_policy_attachment.ops_admin", "mode": "managed", "type": "aws_iam_role_policy_attachment", "name": "ops_admin", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": ["create"], "before": null, "after": {"role": "shop-ops", "policy_arn": "arn:aws:iam::aws:policy/AdministratorAccess"}, "after_unknown": {"id": true}, "before_sensitive": false, "after_sensitive": {} } }, { "address": "aws_instance.web[1]", "mode": "managed", "type": "aws_instance", "name": "web", "index": 1, "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": ["delete"], "before": {"id": "i-0b1c2d3e4f5a6b7c8", "ami": "ami-0abc1234def567890", "instance_type": "t3.medium", "associate_public_ip_address": false, "tags": {"Name": "shop-web-1"}}, "after": null, "after_unknown": {}, "before_sensitive": {}, "after_sensitive": false }, "action_reason": "delete_because_count_index" }, { "address": "aws_lb.public", "mode": "managed", "type": "aws_lb", "name": "public", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": ["update"], "before": {"name": "shop-public", "internal": false, "enable_deletion_protection": true, "tags": {"env": "prod", "owner": "set-in-console"}}, "after": {"name": "shop-public", "internal": false, "enable_deletion_protection": true, "tags": {"env": "prod", "team": "shop"}}, "after_unknown": {}, "before_sensitive": {}, "after_sensitive": {} } }, { "address": "aws_lb_target_group.web", "mode": "managed", "type": "aws_lb_target_group", "name": "web", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": ["create", "delete"], "before": {"name_prefix": "web-", "port": 8080, "protocol": "HTTP", "vpc_id": "vpc-0a1b2c3d"}, "after": {"name_prefix": "web-", "port": 8081, "protocol": "HTTP", "vpc_id": "vpc-0a1b2c3d"}, "after_unknown": {"id": true, "arn": true, "name": true}, "before_sensitive": {}, "after_sensitive": {}, "replace_paths": [["port"]] }, "action_reason": "replace_because_cannot_update" }, { "address": "aws_s3_bucket.legacy_logs", "mode": "managed", "type": "aws_s3_bucket", "name": "legacy_logs", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": ["delete"], "before": {"bucket": "shop-legacy-logs-prod", "force_destroy": true, "tags": {"env": "prod"}}, "after": null, "after_unknown": {}, "before_sensitive": {}, "after_sensitive": false }, "action_reason": "delete_because_no_resource_config" }, { "address": "aws_s3_bucket_public_access_block.assets", "mode": "managed", "type": "aws_s3_bucket_public_access_block", "name": "assets", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": ["update"], "before": {"bucket": "shop-assets-prod", "block_public_acls": true, "block_public_policy": true, "ignore_public_acls": true, "restrict_public_buckets": true}, "after": {"bucket": "shop-assets-prod", "block_public_acls": true, "block_public_policy": false, "ignore_public_acls": true, "restrict_public_buckets": false}, "after_unknown": {}, "before_sensitive": {}, "after_sensitive": {} } }, { "address": "aws_security_group.bastion", "mode": "managed", "type": "aws_security_group", "name": "bastion", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": ["update"], "before": {"name": "shop-bastion", "ingress": [{"cidr_blocks": ["10.20.0.0/16"], "description": "SSH from VPN", "from_port": 22, "to_port": 22, "protocol": "tcp", "ipv6_cidr_blocks": [], "prefix_list_ids": [], "security_groups": [], "self": false}], "egress": []}, "after": {"name": "shop-bastion", "ingress": [{"cidr_blocks": ["10.20.0.0/16"], "description": "SSH from VPN", "from_port": 22, "to_port": 22, "protocol": "tcp", "ipv6_cidr_blocks": [], "prefix_list_ids": [], "security_groups": [], "self": false}, {"cidr_blocks": ["0.0.0.0/0"], "description": "temp: SSH for vendor", "from_port": 22, "to_port": 22, "protocol": "tcp", "ipv6_cidr_blocks": [], "prefix_list_ids": [], "security_groups": [], "self": false}], "egress": []}, "after_unknown": {}, "before_sensitive": {}, "after_sensitive": {} } }, { "address": "module.network.aws_vpc.main", "module_address": "module.network", "mode": "managed", "type": "aws_vpc", "name": "main", "provider_name": "registry.terraform.io/hashicorp/aws", "change": { "actions": ["no-op"], "before": {"cidr_block": "10.20.0.0/16"}, "after": {"cidr_block": "10.20.0.0/16"}, "after_unknown": {}, "before_sensitive": {}, "after_sensitive": {} } } ], "prior_state": {"format_version": "1.0", "terraform_version": "1.9.8"}, "configuration": {"provider_config": {"aws": {"name": "aws", "full_name": "registry.terraform.io/hashicorp/aws"}}}, "timestamp": "2026-10-27T07:10:00Z", "applyable": true, "complete": true, "errored": false } FILE:scripts/plan_risk.py #!/usr/bin/env python3 """Terraform plan risk reviewer (Python 3 standard library only).

Reads terraform show -json plan.out output (or, with less detail, the text of terraform plan -no-color) and flags risky changes: destroys and replacements of stateful resources (data loss), removed deletion protection, skipped final snapshots, force_destroy, disabled encryption, new public network exposure (0.0.0.0/0 or ::/0 ingress, public databases, S3 public access blocks, public ACLs and policies, allUsers bindings), IAM widening (wildcard actions, admin policies, iam:PassRole on *, trust policies open to anyone) and count index shifts. Prints a risk summary. Never prints attribute values that Terraform marks as sensitive.

Usage: terraform plan -out plan.out && terraform show -json plan.out > plan.json python3 plan_risk.py plan.json [--json] terraform plan -no-color > plan.txt && python3 plan_risk.py plan.txt (text mode) python3 plan_risk.py --self-test Exit codes: 0 = no HIGH findings, 1 = HIGH findings, 2 = unreadable input. """ import argparse, json, re, sys

SEV_ORDER = {"HIGH": 0, "MEDIUM": 1, "LOW": 2, "INFO": 3} STATEFUL = re.compile(r"^(aws_(db_instance|rds_cluster|dynamodb_table|s3_bucket|ebs_volume|efs_file_system|" r"elasticache_(cluster|replication_group)|redshift_cluster|docdb_cluster|neptune_cluster|" r"opensearch_domain|elasticsearch_domain|kinesis_stream|sqs_queue|kms_key|secretsmanager_secret|" r"backup_vault|ecr_repository|cloudwatch_log_group|msk_cluster|fsx_\w+|route53_zone|" r"cognito_user_pool|timestream_table)|" r"google_(sql_database_instance|sql_database|storage_bucket|bigquery_(dataset|table)|compute_disk|" r"spanner_(instance|database)|kms_crypto_key|redis_instance|filestore_instance|firestore_database|" r"dns_managed_zone)|" r"azurerm_(storage_account|storage_container|mssql_(database|server)|postgresql_flexible_server|" r"mysql_flexible_server|cosmosdb_account|key_vault|managed_disk|redis_cache|dns_zone)|" r"kubernetes_(persistent_volume_claim|persistent_volume|namespace)(_v1)?)$") SECRET_GEN = re.compile(r"^(random_password|random_string|tls_private_key|aws_iam_access_key)$") DOWNTIME = re.compile(r"^(aws_(instance|lb|alb|eip|nat_gateway|cloudfront_distribution|api_gateway_rest_api|" r"eks_cluster|ecs_service|acm_certificate)|google_(compute_instance|container_cluster)|" r"azurerm_(linux|windows)_virtual_machine|azurerm_kubernetes_cluster)$") SENSITIVE_PORTS = {22: "SSH", 23: "Telnet", 3389: "RDP", 3306: "MySQL", 5432: "PostgreSQL", 1433: "SQL Server", 1521: "Oracle", 6379: "Redis", 27017: "MongoDB", 9200: "Elasticsearch", 5601: "Kibana", 2375: "Docker API", 2379: "etcd", 11211: "Memcached", 5900: "VNC", 9092: "Kafka", 6443: "Kubernetes API", 10250: "Kubelet"} WEB_PORTS = {80, 443} PUBLIC_CIDRS = {"0.0.0.0/0", "::/0", "", "internet", "any"} ADMIN_POLICIES = re.compile(r"(AdministratorAccess|PowerUserAccess|IAMFullAccess)$") ESCALATION_ACTIONS = {"iam:", "iam:passrole", "iam:createpolicyversion", "iam:attachrolepolicy", "iam:putrolepolicy", "iam:createaccesskey", "iam:updateassumerolepolicy", "sts:assumerole", "sts:", "kms:", "*"} POLICY_ATTRS = ("policy", "assume_role_policy", "inline_policy") PROTECTION_ATTRS = ("deletion_protection", "deletion_protection_enabled", "enable_deletion_protection", "termination_protection", "disable_api_termination")

def finding(sev, code, addr, problem, fix): return {"severity": sev, "code": code, "resource": addr, "problem": problem, "fix": fix}

The text continues at the source. Read the rest.

Source and license

Source: https://github.com/f/prompts.chat/blob/main/prompts/02673.md

Author: f, prompts.chat prompt library. License: CC0-1.0.

Shown here with formatting for the web. Keep the author and license notice when you reuse it.

Related entries

There are more like this in the members library

The Business prompt library holds 3,008 entries. Members can search all of them by meaning and read every one in full.