Skip to content
CloudOps
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.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week