terraform-policy

Menulis, menguji, atau mengonversi file Kebijakan Terraform (.policy.hcl, .policytest.hcl, Sentinel→tfpolicy). Pemicu: policy.hcl, policytest, convert sentinel, tfpolicy,…

npx skills add https://github.com/hashicorp/agent-skills --skill terraform-policy

terraform-policy

UTILITY SKILL — INVOKES: tfpolicy-author | tfpolicy-test

USE FOR:

  • Writing a new .policy.hcl policy from a description or requirement
  • Converting a .sentinel policy to Terraform Policy
  • Writing or debugging a .policytest.hcl test 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-level policy { required_providers { ... } } block when authoring .policy.hcl files containing resource or provider policies. It is mandatory for tfpolicy validate; version-range validation is best effort, and wildcard targets such as resource_policy "*" are not schema-validated. tfpolicy test does not preflight mocked attrs/prior_attrs against provider schemas, core::alltrue/core::anytrue do not exist, and, only in this 0.2.x line, mock resource {} blocks may omit attrs/prior_attrs entirely.
  • If the CLI is 0.3.x or newer, the other guidance above still applies, but the 0.2.x allowance for omitting resource state does not: every mock resource {} block in .policytest.hcl files must declare attrs or prior_attrs; if both evaluate to empty, the test case is skipped (provider {} and module {} mocks are unaffected) (see tfpolicy-test). tfpolicy test reuses the target .policy.hcl's existing top-level policy { required_providers { ... } } block (there is no separate .policytest.hcl-level declaration) to validate provider, resource, and data-source policies and core::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) and core::anytrue(list) are also available — prefer them over the core::length() list-comprehension workaround (see tfpolicy-author). meta.tfe_stack and meta.tfe_workspace.tags are 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.x and 0.3.x paths.

DO NOT USE FOR:

  • Writing .tftest.hcl files for Terraform modules — use terraform-test
  • General Terraform HCL authoring — use terraform-style-guide

Routing

TaskSub-skill
Write or convert a .policy.hcl policytfpolicy-author
Write or debug a .policytest.hcl testtfpolicy-test

Examples

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

Lebih banyak skill dari hashicorp

provider-framework-migration
hashicorp
Migrasikan resource dan data source penyedia Terraform dari Plugin SDKv2 ke Plugin Framework: menggabungkan kedua plugin dalam satu penyedia (terraform-plugin-mux,…)
provider-configuration
hashicorp
Menerapkan konfigurasi provider Terraform dan otentikasi dengan Plugin Framework: skema provider untuk kredensial (atribut Opsional + Sensitif),…
provider-ephemeral-resources
hashicorp
Implementasikan resource ephemeral penyedia Terraform dengan Plugin Framework: siklus hidup Open/Renew/Close, desain skema ephemeral, registrasi melalui…
terraform-test
hashicorp
Panduan lengkap untuk menulis dan menjalankan tes Terraform dengan asersi, mocking, dan validasi modul. Tulis file tes menggunakan sintaks .tftest.hcl dengan blok run yang dijalankan dalam mode plan atau apply, mendukung eksekusi sekuensial dan paralel dengan isolasi status opsional. Asersi kondisi pada atribut sumber daya, output, dan sumber data; gunakan expect_failures untuk memvalidasi bahwa input yang tidak valid ditolak dengan benar. Mock provider (Terraform 1.7.0+) mensimulasikan perilaku infrastruktur tanpa...
terraform-search-import
hashicorp
Temukan sumber daya cloud yang ada menggunakan kueri Terraform Search dan impor secara massal ke dalam manajemen Terraform. Gunakan saat membawa infrastruktur yang tidak terkelola…
aws-ami-builder
hashicorp
Bangun Amazon Machine Images kustom dengan builder amazon-ebs milik Packer. Mengotomatiskan pembuatan AMI dari AMI sumber menggunakan templat HCL dengan provisioner untuk kustomisasi (skrip shell, unggahan file, manajemen konfigurasi). Mendukung distribusi AMI multi-region melalui ami_regions dan pemfilteran AMI sumber yang fleksibel berdasarkan nama, pemilik, dan tipe virtualisasi. Otentikasi melalui variabel lingkungan, file kredensial AWS, atau profil instance IAM; mencakup perintah validasi dan build untuk templat...
tfctl
hashicorp
Berinteraksi dengan HCP Terraform / Terraform Cloud / Terraform Enterprise menggunakan CLI tfctl. Cakupan API penuh. Gunakan untuk HCP Terraform atau Terraform Cloud atau…
provider-actions
hashicorp
Menerapkan tindakan penyedia Terraform imperatif pada peristiwa siklus hidup sumber daya menggunakan Plugin Framework. Mendukung pemicu siklus hidup sebelum/sesudah pembuatan dan sebelum/sesudah pembaruan (peristiwa penghancuran tidak tersedia di Terraform 1.14.0). Memerlukan definisi skema yang tepat dengan tipe kerangka yang benar, ElementType untuk koleksi, dan validator untuk validasi input. Termasuk pelaporan kemajuan, manajemen waktu tunggu, dan penanganan kesalahan yang komprehensif untuk operasi yang berjalan lama. Menerapkan polling dan...