Terraform policy files
Writes, converts and tests HCP Terraform policy files (.policy.hcl, .policytest.hcl), including Sentinel-to-tfpolicy conversion with a quality label per policy. Use when writing a new policy, porting Sentinel or debugging a policy test.
terraform-policy- Author
- HashiCorp
- Source
- hashicorp/agent-skills/plugins/terraform/skills/terraform-policy @ 5e30fa5
- License
- MPL-2.0
About this skill
What it does
The skill writes, converts and tests Terraform Policy files, HCP Terraform's policy-as-code format: .policy.hcl policies and .policytest.hcl tests. SKILL.md only routes; the substance is in three reference files. references/tfpolicy-author.md turns a plain-language rule into resource_policy, module_policy or provider_policy blocks, with input blocks for allowlists, operations and prior_attrs for update and delete checks, and core::getresources() for cross-resource lookups. It also converts Sentinel: a construct mapping, a list of what cannot be converted, and a label for every result (Perfect, Good, Simplify, Not convertible). references/tfpolicy-test.md covers mocks, expect_failure and a required missing-attribute case in every test file. references/verified-syntax.md lists verified syntax and common mistakes, such as meta.address: undefined in resource policies and caught only by a real terraform plan --policies=. examples/conversion/ holds 16 AWS Sentinel policies beside their conversions, each with a README on what was lost.
The agent first checks the installed tfpolicy CLI version: the guidance differs for 0.3.x, 0.4.x and 0.5.x.
When to use it, and when not
Use it to write a new policy, port a Sentinel policy or library, or debug a policy test that passes or fails unexpectedly. It needs the tfpolicy CLI; the policies themselves are enforced by HCP Terraform. verified-syntax.md says its patterns were verified during the private beta, on beta builds of Terraform and tfpolicy.
Module tests in .tftest.hcl and ordinary HCL are out of scope; the skill sends those elsewhere.
How to run it
We do not copy this skill: its files are under MPL-2.0, a file-level copyleft licence outside the set we copy under. Install it from HashiCorp's repository with the button to the source: one skill via npx skills add hashicorp/agent-skills/plugins/terraform/skills/terraform-policy, or the whole terraform plugin via claude plugin marketplace add hashicorp/agent-skills, then claude plugin install terraform@hashicorp. In Codex: codex plugin marketplace add hashicorp/agent-skills, then install terraform from /plugins and start a new session. In Claude Code, the plugin's skill may appear as /terraform:terraform-policy. The npx paths in its Troubleshooting section are out of date.
- Claude Code:
/terraform-policy, or ask for the skill by name. - Codex:
$terraform-policy. - Cursor: type
/in the Agent chat and pickterraform-policy.
Example: /terraform-policy Convert policies/ebs-encrypted.sentinel to .policy.hcl and add a .policytest.hcl with passing and failing cases.
How it differs from similar skills
Nothing else in the catalog writes policy as code. Terraform tests checks module behaviour with run blocks, while this skill tests policies against mocked resources. Terraform style guide covers ordinary configuration. Security review traces untrusted input through application code and enforces nothing on a Terraform plan.
Install
This skill is not copied to the catalog: its licence allows a copy only under the same licence, and the catalog does not copy under such licences. Install it from the author's repository.
Connect through AnyModel API
This skill runs on whatever model your agent uses. Point Claude Code, Codex or Cursor at AnyModel to run it on Claude, GPT, Gemini and more with one key — pay per token, no subscription.
AnyModel