Skip to content
Back to skills

Iac Terraform

ASecurity

Terraform & OpenTofu discipline and HCL code conventions — modules, remote state, workspaces, backends, plan/apply gates, drift detection, state surgery, security defaults, style, and .tftest.hcl testing. Activate when working on *.tf / *.tfvars files, terraform/tofu plan/apply/state operations, backend or workspace config, provider versioning, or diagnosing drift and partial applies.

  • 4 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 2, 2026
ai-agentsgoawsgcpazureterraformtestingdatabasebackendsecurity

Works with

  • cli

Security analysis

A100/100

Scanned November 9, 2026

npx -y skills add eric-sabe/engsys --skill iac-terraform --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Iac Terraform?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Iac Terraform
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/eric-sabe-iac-terraform/badge)](https://www.skillsdirectory.com/skills/eric-sabe-iac-terraform)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: iac-terraform
description: Terraform & OpenTofu discipline and HCL code conventions — modules, remote state, workspaces, backends, plan/apply gates, drift detection, state surgery, security defaults, style, and .tftest.hcl testing. Activate when working on *.tf / *.tfvars files, terraform/tofu plan/apply/state operations, backend or workspace config, provider versioning, or diagnosing drift and partial applies.
---

# Terraform & OpenTofu Discipline and Conventions

Operational discipline and HCL coding conventions for Terraform and OpenTofu (`*.tf`, `*.tfvars`, `*.tftest.hcl`) — cloud-independent. Service-level resource detail comes from the active `cloud-architecture-<cloud>` pack; project file layout and backend config come from `CLAUDE.md`.

## Core Stance

- **Infrastructure is software.** If it only works once, it doesn't work. "Just apply it again" is not a strategy — understand *why* it failed first.
- **Plan is the contract.** Never `apply` without reading the `plan`. Treat a surprising plan as a bug to investigate, not a step to skip.
- **Pin everything.** Constrain the CLI version with `terraform.required_version`, declare provider version constraints in `required_providers`, and commit `.terraform.lock.hcl` to lock provider selections.

## State Management & Surgery

- **Remote state with locking, always** (S3 + DynamoDB/native lock, GCS, Azure Blob lease, or Terraform Cloud). Never commit `.tfstate` files.
- **Separate state per major component and environment** (`dev` vs. `prod` never share state) to minimize blast radius and lock contention.
- **State surgery** when reality and state diverge (use the project's active IaC executable, `terraform` or `tofu`):
  - `<terraform|tofu> state list` — inspect tracked resources
  - `<terraform|tofu> import <addr> <id>` (or `import {}` blocks) — adopt existing resources
  - `moved { from = ... to = ... }` or `<terraform|tofu> state mv` — refactor without destroy+recreate
  - `<terraform|tofu> state rm` — stop tracking without deleting the underlying cloud resource
  - Always run `plan` immediately after state surgery to confirm zero unintended diffs.

## Security & Safe Defaults

- **Never store secrets in `.tf`, `.tfvars`, or state where avoidable.** Reference secrets from AWS Secrets Manager / SSM, Azure Key Vault, or GCP Secret Manager, and mark sensitive variables/outputs with `sensitive = true`.
- Enforce least-privilege IAM/OIDC roles, private networking by default, encryption at rest and in transit, and static IaC scanning (`trivy`, `checkov`, or `tflint`) in CI.
- Protect stateful resources (databases, disks, buckets) with `lifecycle { prevent_destroy = true }`.

## Modularity, Style & Testing Conventions

- **Modules**: Group cohesive resources into version-pinned modules with typed, documented `variable` and `output` contracts. Never wrap a single resource in a thin pass-through module.
- **File layout & ordering**: Group by domain (`providers.tf`, `variables.tf`, `main.tf`, `network.tf`, `outputs.tf`). Within a resource block, order: `depends_on` → `for_each`/`count` → required attributes → optional attributes → `lifecycle`. Prefer `for_each` (keyed by stable string ID) over positional `count`.
- **Formatting & validation**: Run `<terraform|tofu> fmt -check`, `<terraform|tofu> validate`, and `tflint` before every commit using the active IaC executable.
- **Testing**: Author idempotent `.tftest.hcl` test suites covering both nominal and invalid variable inputs.

## Plan / Apply Gates & Drift

- **Pipeline gate**: `fmt` → `validate` → `plan` (posted on PR) → operator approval gate → `apply` on merge.
- **Inspect for `-/+` replacements**: Never rubber-stamp a replacement on a stateful resource.
- **Drift**: Schedule `plan -refresh-only` checks; reconcile any out-of-band click-ops back into `.tf` immediately.
- **Preflight**: Always run the active cloud's `*-deployment-preflight` skill before applying.

## Hard-Won Lessons

### Span two control planes? Use a multi-provider graph so one apply wires both sides
- **Symptom:** Infrastructure crosses a cloud *and* a managed SaaS (e.g., Azure + MongoDB Atlas Private Endpoint), and single-cloud IaC (Bicep/CDK) leaves the SaaS half to manual console clicks.
- **Fix:** Use Terraform/OpenTofu multi-provider composition (e.g., `azurerm` + `mongodbatlas` in one root module) so a single `plan`/`apply` wires both sides of the boundary deterministically.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.