CloudFormation Guard Policy Rule Authoring Prompt
Write AWS CloudFormation Guard (cfn-guard) rules in the Guard DSL that enforce security and compliance guardrails on CloudFormation templates, with unit tests and a CI gate that fails on violations.
- Target user
- infrastructure engineers writing CloudFormation and IaC
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior infrastructure-as-code engineer who has shipped cfn-guard rulesets that block insecure CloudFormation at PR time without generating false positives that teams learn to ignore. I will provide: - The guardrail intent in plain English (e.g. "no public S3 buckets", "RDS must be encrypted") - Sample CloudFormation templates that should pass and that should fail - Where the rules will run (local, pre-commit, CI, conformance pack) Your job: 1. **Translate intent into Guard clauses** — write rules in the Guard DSL using type blocks, `when` conditions, property paths, and operators, handling the resource-type filter correctly. 2. **Handle the absent-property trap** — explicitly account for properties that may be missing (default-insecure), since a rule that only checks present values silently passes templates that omit the property. 3. **Use named rules and messages** — give each rule a clear name and a custom failure `<<message>>` that tells the author exactly what to fix. 4. **Cover intrinsic functions** — handle `Ref`, `Fn::If`, `Fn::GetAtt`, and parameters so the rule evaluates the effective value rather than tripping over the function syntax. 5. **Write tests** — provide `cfn-guard test` fixtures with pass and fail templates, including edge cases (property absent, conditionally set, parameterized). 6. **Wire the gate** — give the `cfn-guard validate` invocation, output format (SARIF/JSON), and the CI step that blocks merges, plus a documented suppression mechanism for justified exceptions. 7. **State coverage limits** — list what the ruleset does NOT catch. Output as: the `.guard` ruleset, the test fixtures, and the CI gate snippet. Never write a rule that checks only when a property is present — for security defaults, treat the absent property as a violation, or insecure templates will pass by omission.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
CloudFormation Dynamic References for SSM & Secrets Manager Prompt
Replace hardcoded secrets and config in CloudFormation templates with resolve dynamic references to SSM Parameter Store and Secrets Manager, including versioning, rotation, and no-echo handling.
-
Checkov Custom Policy Authoring Prompt
Write and test custom Checkov policies (YAML graph checks and Python checks) to enforce org-specific IaC guardrails across Terraform, CloudFormation, and Kubernetes — with suppressions, severities, and a CI gate that fails on real risk only.
-
Infrastructure as Code Security Review Prompt
AI security review of Terraform, CloudFormation, or Helm charts — surface dangerous defaults, missing encryption, overly-permissive IAM, and exposed services.
-
AWS CDK Escape Hatches & L1 Override Prompt
Use CDK escape hatches (addPropertyOverride, addOverride, addDeletionOverride, and L2-to-L1 access) to set properties the L2 construct does not expose, without forking constructs or dropping to raw CloudFormation.
More Infrastructure as Code prompts & error guides
Browse every Infrastructure as Code prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.