Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Infrastructure as Code Difficulty: Advanced ClaudeChatGPT

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

More Infrastructure as Code prompts & error guides

Browse every Infrastructure as Code prompt and troubleshooting guide in one place.

Free download · 368-page PDF

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.