# terraform-policy

Creates and tests Terraform Policy files, and converts Sentinel rules into Terraform Policy. Use it when policy files or their test cases need changes.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 1500 installs · ★ 909
- Author: hashicorp
- License: MPL-2.0 · policy=link-only · description only; the file stays with the author
- Source: https://github.com/hashicorp/agent-skills/tree/HEAD/plugins/terraform/skills/terraform-policy/SKILL.md
- Updated: 2026-10-05
- HTML: https://affpapa.org/en/nevibecode/skills/terraform-policy

## What it does

This skill drafts `.policy.hcl` files, prepares or fixes `.policytest.hcl` cases, and moves rules from `.sentinel` into Terraform Policy. Authoring and conversion go through `tfpolicy-author`; test work goes through `tfpolicy-test`.

It asks for the installed `tfpolicy` version before giving guidance. In `0.2.x`, resource and provider policies need a top-level required-provider block, while resource mocks in tests may omit state. Check the CLI version before editing.

With `0.3.x`, every resource mock in `.policytest.hcl` needs `attrs` or `prior_attrs`, and an empty state skips that case. This line also validates schemas before tests run and includes `core::alltrue()` and `core::anytrue()`.

## Requirements
- Works with: Terraform

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add hashicorp/agent-skills --skill terraform-policy -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/terraform-policy/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/terraform-policy/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add hashicorp/agent-skills --skill terraform-policy -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/terraform-policy/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add hashicorp/agent-skills --skill terraform-policy -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/terraform-policy/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install hashicorp/agent-skills terraform-policy
```

2. **Manually: put the files in place**
- File: `.github/skills/terraform-policy/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add hashicorp/agent-skills --skill terraform-policy -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/hashicorp/agent-skills --path plugins/terraform/skills/terraform-policy
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/terraform-policy/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add hashicorp/agent-skills --skill terraform-policy -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/hashicorp/agent-skills/tree/HEAD/plugins/terraform/skills/terraform-policy/SKILL.md

## When to use it
- write a Terraform Policy rule from a requirement
- convert a `.sentinel` rule to Terraform Policy
- create a `.policytest.hcl` test case
- debug a failing policy test
- handle `tfpolicy` `0.2.x` and `0.3.x` differences

## Example prompts
- Write a `.policy.hcl` rule that rejects unencrypted EC2 instances.
- Convert this `.sentinel` policy into Terraform Policy.
- Debug my `.policytest.hcl` test for an EBS policy.

## Similar
- [huawei-cloud-terraform-installer](https://affpapa.org/en/nevibecode/skills/huawei-cloud-terraform-installer.md) — skill · 17400 installs
- [huawei-cloud-terraform-generator](https://affpapa.org/en/nevibecode/skills/huawei-cloud-terraform-generator.md) — skill · 17000 installs
- [terraform-module-library](https://affpapa.org/en/nevibecode/skills/terraform-module-library.md) — skill · 15615 installs
- [terraform-azurerm-set-diff-analyzer](https://affpapa.org/en/nevibecode/skills/terraform-azurerm-set-diff-analyzer.md) — skill · 8900 installs
- [terraform-skill](https://affpapa.org/en/nevibecode/skills/terraform-skill.md) — skill · 7400 installs
- [terraform-engineer](https://affpapa.org/en/nevibecode/skills/terraform-engineer.md) — skill · 5400 installs

From the same set: [hashicorp/agent-skills](https://affpapa.org/en/nevibecode/by/hashicorp/agent-skills.md) — 16 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
