Sentinel Policy-as-Code Authoring Prompt
Write and test HashiCorp Sentinel policies that gate infrastructure runs by enforcement level, using imports and mocks to validate plans before they ever apply.
- Target user
- Platform governance teams enforcing guardrails in Terraform/HCP workflows
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior governance engineer who authors HashiCorp Sentinel policies and test suites. I will provide: - The controls to enforce (mandatory tags, restricted instance types, region allowlist, cost ceiling, no wildcard IAM). - The desired enforcement levels (advisory, soft-mandatory, hard-mandatory) per control. - Sample plan data or the resource types involved. Your job: 1. **Structure the policy** — use the `tfplan/v2`, `tfconfig`, and `tfstate` imports as appropriate and explain which import answers which question. 2. **Write rules** — express each control as a Sentinel `rule` with helper functions, using `filter` and `all`/`any` over resource changes. 3. **Map enforcement** — recommend the right level per control and explain soft- vs. hard-mandatory override semantics. 4. **Author the policy set** — produce `sentinel.hcl` wiring policies, params, and enforcement levels. 5. **Mock and test** — generate mock plan data and `*.sentinel` test cases that assert pass and fail outcomes via `sentinel test`. 6. **Give clear messages** — use `print` to emit which resource and attribute violated. 7. **CI integration** — show running the suite in CI before the policy reaches the workspace. Output as: (a) policy files, (b) sentinel.hcl, (c) mock data + test files, (d) an enforcement-level rationale table. Flag any rule depending on data only present at apply time, where the plan import cannot evaluate it.
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
-
Policy-as-Code Rule Authoring from a Governance Requirement Prompt
Translate a written governance or compliance requirement into enforceable policy-as-code rules — choosing the right engine (OPA/Rego, Sentinel, Checkov, cfn-guard, Kyverno) and writing the rule with clear messages, tests, and a graduated rollout.
-
Conftest Policy Unit Testing Prompt
Write unit tests for your Rego policies so Conftest rules are themselves covered by passing and failing fixtures before they gate real deployments.
-
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.
-
IaC Naming & Tagging Convention Audit Prompt
Audit infrastructure-as-code for consistent resource naming and tagging so cost allocation, ownership, environment, and governance tags are complete and standardized.
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.