terraform

Diagnoses Terraform and OpenTofu failure modes and generates version-aware fixes with validation and rollback plans.

Updated Nov 1, 2024
One-click install
npx skills add https://github.com/mlorentedev/dotfiles --skill terraform-mlorentedev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: terraform
Source: https://github.com/mlorentedev/dotfiles/tree/main/harness/skills/terraform
Command: npx skills add https://github.com/mlorentedev/dotfiles --skill terraform-mlorentedev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing and maintaining Terraform/OpenTofu infrastructure code involves recurring failure modes — identity churn from list-indexed resources, secrets leaking into state, CI plans diverging from local plans, and state corruption — that are hard to diagnose and risky to fix without version-aware guidance. ## Core Features & Use Cases - Failure-mode diagnosis: Routes symptoms to nine risk categories (identity churn, secret exposure, blast radius, CI drift, compliance gaps, testing blind spots, state corruption, provider upgrades, bootstrap misuse) before proposing fixes. - Version-aware remediation: Guards every recommendation against the runtime floor (e.g., moved blocks 1.1+, native tests 1.6+, mock providers 1.7+, write_only args 1.11+) for both Terraform and OpenTofu. - Structured response contract: Every answer states assumptions, risk category, remediation tradeoffs, exact validation commands (fmt -check, validate, plan -out), and rollback notes for state-mutating changes. - Use Case: A terraform plan shows dozens of resources being destroyed and recreated after reordering a list; the skill identifies identity churn, recommends converting count to for_each with moved blocks, and provides the validation and rollback procedure. ## Quick Start Ask the assistant to review your Terraform module for state, security, and CI risks and propose fixes with validation commands.

Frequently Asked Questions about terraform

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

FAQPage Schema
How do I fix Terraform resources being recreated after reordering a list?

This is identity churn caused by using count with list indices. Convert to for_each over a map or toset so resources have stable keys, and add moved blocks (Terraform 1.1+) to migrate existing state addresses without destroying resources.

Should I use count or for_each in Terraform modules?

Use count = cond ? 1 : 0 for simple boolean create-or-skip decisions. Use for_each with toset(list) when items may reorder or be removed, and for_each with a map when you need to reference resources by stable named keys.

Does Terraform sensitive = true keep secrets out of state?

No. The sensitive attribute only masks values in CLI output and logs; the plaintext value is still stored in the state file. Source secrets from cloud secret managers and use write_only or *_wo arguments (Terraform 1.11+) to avoid persisting them.

How do I test Terraform modules with native tests?

Native terraform test requires Terraform 1.6+ and uses .tftest.hcl files. Use command = plan for input-derived values and command = apply for computed values like ARNs or set-type nested blocks that cannot be index-addressed.

Why does my Terraform CI plan differ from my local plan?

CI drift usually comes from unpinned provider or runtime versions. Pin the runtime with required_version, pin providers with version constraints, commit .terraform.lock.hcl, and apply the reviewed plan artifact in CI instead of re-running plan.

When should I split Terraform state into multiple backends?

Split state when different teams or change cadences manage components, or when a single state exceeds roughly 500 resources. Combine tightly coupled components under about 100 resources, and always use a remote backend with locking and encryption for team or production work.