About terraform-policy
terraform-policy is a utility skill for authoring and testing Terraform Policy files. It routes policy creation or conversion to tfpolicy-author and policy tests to tfpolicy-test, with guidance tailored to the installed tfpolicy CLI version.
Key features
- 01Author and convert .policy.hcl files
- 02Write and debug .policytest.hcl files
- 03Route tasks to focused sub-skills
- 04Distinguish tfpolicy CLI version behavior
Use cases
- 01Creating a policy from a requirement
- 02Converting a Sentinel policy
- 03Debugging a policy test
- 04Choosing version-specific authoring guidance
Install
Copy the command and run it in a terminal.
$
npx skills add https:/ / github.com/ hashicorp/ agent-skills --skill terraform-policyAfter installing, type/terraform-policyin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
.gitignoreexamples/conversion/cloudfront-associated-with-waf/cloudfront-associated-with-waf.policy.hclcloudfront-associated-with-waf.sentinelREADME.mdexamples/conversion/cloudtrail-server-side-encryption-enabled/cloudtrail-server-side-encryption-enabled.policy.hclcloudtrail-server-side-encryption-enabled.sentinelREADME.mdexamples/conversion/dms-endpoint-should-be-ssl-configured/dms-endpoint-should-be-ssl-configured.policy.hcldms-endpoint-should-be-ssl-configured.sentinelREADME.mdexamples/conversion/dms-endpoints-should-use-ssl/dms-endpoints-should-use-ssl.policy.hcldms-endpoints-should-use-ssl.sentinelREADME.mdexamples/conversion/ec2-network-acl-should-have-subnet-ids/ec2-network-acl-should-have-subnet-ids.policy.hclec2-network-acl-should-have-subnet-ids.sentinelREADME.mdexamples/conversion/ec2-vpc-default-security-group-no-traffic/ec2-vpc-default-security-group-no-traffic.policy.hclec2-vpc-default-security-group-no-traffic.sentinelREADME.mdexamples/conversion/efs-access-point-should-enforce-user-identity/efs-access-point-should-enforce-user-identity.policy.hclefs-access-point-should-enforce-user-identity.sentinelREADME.mdexamples/conversion/elasticache-redis-replication-group-encryption-at-transit-enabled/elasticache-redis-replication-group-encryption-at-transit-enabled.policy.hclelasticache-redis-replication-group-encryption-at-transit-enabled.sentinelREADME.mdexamples/conversion/elasticsearch-encrypted-at-rest/elasticsearch-encrypted-at-rest.policy.hclelasticsearch-encrypted-at-rest.sentinelREADME.mdexamples/conversion/elasticsearch-https-required/elasticsearch-https-required.policy.hclelasticsearch-https-required.sentinelDetails
From the project READMEterraform-policy
UTILITY SKILL — INVOKES: tfpolicy-author | tfpolicy-test
USE FOR:
- Writing a new
.policy.hclpolicy from a description or requirement - Converting a
.sentinelpolicy to Terraform Policy - Writing or debugging a
.policytest.hcltest file - Migrating a Sentinel policy library to Terraform Policy
Before giving authoring or testing instructions, check the installed tfpolicy CLI version and tailor guidance accordingly. This skill maintains guidance for the two most recent minor lines, 0.2.x and 0.3.x; when a new minor ships, drop the oldest line and add the new one.
- If the CLI is
0.2.x(baseline), include a top-levelpolicy { required_providers { ... } }block when authoring.policy.hclfiles containing resource or provider policies. It is mandatory fortfpolicy validate; version-range validation is best effort, and wildcard targets such asresource_policy "*"are not schema-validated.tfpolicy testdoes not preflight mockedattrs/prior_attrsagainst provider schemas,core::alltrue/core::anytruedo not exist, and, only in this0.2.xline, mockresource {}blocks may omitattrs/prior_attrsentirely. - If the CLI is
0.3.xor newer, the other guidance above still applies, but the0.2.xallowance for omitting resource state does not: every mockresource {}block in.policytest.hclfiles must declareattrsorprior_attrs; if both evaluate to empty, the test case is skipped (provider {}andmodule {}mocks are unaffected) (see tfpolicy-test).tfpolicy testreuses the target.policy.hcl's existing top-levelpolicy { required_providers { ... } }block (there is no separate.policytest.hcl-level declaration) to validate provider, resource, and data-source policies andcore::getdatasource()/core::getresources()arguments against resolved provider schemas before any test runs, failing the whole run on a schema mismatch (see tfpolicy-test).core::alltrue(list)andcore::anytrue(list)are also available — prefer them over thecore::length()list-comprehension workaround (see tfpolicy-author).meta.tfe_stackandmeta.tfe_workspace.tagsare available to resource, provider, and module policies; Stack fields are empty outside Stack evaluations. - If the CLI version is unknown, ask the user to check it first or provide guidance that clearly distinguishes the
0.2.xand0.3.xpaths.
DO NOT USE FOR:
- Writing
.tftest.hclfiles for Terraform modules — useterraform-test - General Terraform HCL authoring — use
terraform-style-guide
Routing
| Task | Sub-skill |
|---|---|
Write or convert a .policy.hcl policy | tfpolicy-author |
Write or debug a .policytest.hcl test | tfpolicy-test |
Examples
- "Block EC2 instances without encryption" → tfpolicy-author
- "Convert this Sentinel policy to tfpolicy" → tfpolicy-author
- "Write a policytest for my EBS policy" → tfpolicy-test
Troubleshooting
- Wrong skill triggered? Load the sub-skill directly from the routing table above.
npx skills add hashicorp/agent-skills/terraform/terraform-policy/skills/tfpolicy-author
npx skills add hashicorp/agent-skills/terraform/terraform-policy/skills/tfpolicy-test
Comments
Markdown supported