terraform

Guides Terraform and OpenTofu infrastructure-as-code authoring, testing, and security practices.

Updated Jul 13, 2016
One-click install
npx skills add https://github.com/yang-l/configs --skill terraform-yang-l
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: terraform
Source: https://github.com/yang-l/configs/tree/main/.claude/skills/terraform
Command: npx skills add https://github.com/yang-l/configs --skill terraform-yang-l

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing and maintaining Terraform configurations involves many pitfalls: unsafe state handling, over-privileged IAM policies, outdated language features, and weak testing. This Skill provides expert guidance on Terraform, OpenTofu, and related IaC tools so configurations are secure, testable, and follow current best practices. ## Core Features & Use Cases - Modern HCL Guidance: Covers ephemeral resources, write-only arguments, import/moved blocks, check blocks, terraform query, actions, typed outputs, and dynamic module sources across Terraform 1.1 through 1.15. - Layered Testing Strategy: Directs use of terraform validate, tflint, Checkov, terraform test with mock providers, and Terratest for integration testing of critical modules. - AWS & Security Patterns: Enforces least-privilege IAM verified against the AWS Service Authorization Reference, default_tags tagging, OIDC workload identity for CI/CD, state locking, and drift detection. - Use Case: When refactoring a module, the Skill recommends moved blocks instead of state surgery, pins providers with pessimistic constraints, and ensures .terraform.lock.hcl is committed. ## Quick Start Ask the assistant to review your Terraform module for security issues and modernize it using current HCL features.

Frequently Asked Questions about terraform

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Terraform modules before applying?▼

Use a layered approach: run terraform validate, tflint, and Checkov for static analysis, then terraform test with .tftest.hcl files and mock providers for contract testing. Reserve Terratest for real-deploy integration tests of high-blast-radius modules.

Terraform vs OpenTofu: which should I use?▼

OpenTofu 1.12 has diverged from Terraform with native client-side state encryption, provider for_each, and dynamic prevent_destroy. Migration from Terraform is straightforward, but rolling back after using OpenTofu-only features is not, so evaluate lock-in risk first.

How do I refactor Terraform resources without state surgery?▼

Use moved blocks (Terraform 1.1+) to rename or relocate resources declaratively instead of running terraform state mv or rm. Keep moved blocks in configuration for at least one release cycle after the migration.

Why does my IAM policy condition silently deny everything?▼

Unsupported condition keys fail closed without errors, and terraform validate or plan will not catch them. Verify actions, resources, and condition keys against the AWS Service Authorization Reference, noting that valid keys differ per action.

Should I commit the .terraform.lock.hcl file?▼

Yes, always commit .terraform.lock.hcl to version control. It is the only supply-chain lock for providers and ensures reproducible builds; note that modules are not covered, so pin exact versions for critical modules.

When should I avoid using terraform -target?▼

Use -target sparingly and prefer full plans, since targeted applies can miss dependencies and produce inconsistent state. Always review the full plan output and destroy counts before applying changes.