사용 방법
- 설치 명령을 복사하고 자신의 에이전트 환경에 설치하기 전에 소스 패키지를 확인하세요.
- 필요한 도구, 인증 정보, 지원 환경은 원본 문서에서 확인하세요.
- 입력과 원하는 산출물을 설명하고 출처와 결과를 대조하세요.
npx skills add https://github.com/hashicorp/agent-skills --skill terraform-policy시작 전 확인
- 설치에는 모델 구독, API 한도, 파일 접근 권한이 포함되지 않습니다.
- 별점 수와 설치 수는 활동 지표이며 독립적인 품질·보안 검증이 아닙니다.
원본 저장소의 제목, 예시, 코드, 표, 링크, 이미지를 유지해 표시합니다.
terraform-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.4.x and 0.5.x. The 0.3.x bullet below is baseline guidance that applies to every supported line. When a new minor ships, drop the oldest line and add the new one. Inline notes for versions earlier than 0.3.0 are retained only for older CLIs.
- If the CLI is
0.3.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. 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 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 strings outside Stack evaluations on 0.3.x and 0.4.x (nullon 0.5.x+, see below). On 0.3.x only, theno-opoperation does not exist: resource policies evaluate only resources that the run creates, updates, or deletes, and the defaultoperationsis["create", "update"]. - If the CLI is
0.4.xor newer, all0.3.xguidance still applies except theoperationsdefault, plus theno-opoperation, which evaluates resources that the run leaves unchanged (the entire state).operationsaccepts"create","update","delete", and"no-op". For policies that do not referenceprior_attrs, the defaultoperationsis now["create", "update", "no-op"], so omitting it evaluates every resource in state. Useoperations = ["create", "update"]to evaluate only changed resources.no-opexposes the existing values throughattrs, andprior_attrsis unavailable.deletecannot be combined withcreateorno-op(["update", "delete"]is valid), andprior_attrspolicies must setoperationsexplicitly. Attrs-only policies (noprior_attrs) callingcore::getresourceswhoseoperationsomitno-opload with a warning; do not addno-opto aprior_attrspolicy, which fails validation. In tests, setmeta.operation = "no-op"explicitly because it is never inferred (see tfpolicy-author and tfpolicy-test). - If the CLI is
0.5.xor newer, all0.4.xguidance still applies, with two changes. (1) Absentmetaattributes are exposed asnullinstead of an empty string:meta.alias(no alias),meta.version(no version specified, including modules), andmeta.tfe_stack.deployment_group/deployment_name/stack_name(workspace evaluations or not set).meta.tfe_workspace.tagsis still an empty map. Passingnullto a function such ascore::semverconstraint, or interpolating it into a string such aserror_message, fails, and&&does not short-circuit, so guard with a conditional:meta.version != null ? core::semverconstraint(meta.version, ">= 2.0.0") : false. Equality checks are null-safe (meta.alias == "secondary"isfalsewhen there is no alias), but checks likemeta.tfe_stack.stack_name == ""no longer match (use== null). (2)prior_attrsis rejected at parse time inprovider_policyandmodule_policyblocks; it is valid only inresource_policy(update and delete operations). Useattrs.for provider attributes (see tfpolicy-author). - If the CLI version is unknown, ask the user to check it first or provide guidance that clearly distinguishes the
0.3.x,0.4.x, and0.5.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
