Skip to content
Skills Library
DevOps & cloud · Review & audit

terraform-optimizer

/terraform-optimizer

Audit and optimize Terraform/OpenTofu infrastructure code (Terraform 1.17 current, 1.16 supported, 1.15/1.14 EOL) for module and state structure, remote backends and locking, provider/module version pinning, plan/apply safety, drift and imports/moved blocks, secrets and IAM least privilege, network/storage/database security, CI policy/testing, and cost, with real before/after measurement. Always produces a written findings report and a fix plan for approval before touching code. Use this whenever the user mentions Terraform, OpenTofu, `.tf`/state/backend, state locking, `terraform plan`, drift

Licence
MIT
Last repository change
04.11.2026

Assessment and security

85/ 100Class: good
Format20 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content25 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
11
Scripts
1
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 04.11.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What to check before installing
  • 1 scripts in this package. Review them before installing, as Claude may execute them.

Scripts: scripts/audit.py

What it does and when to use it

Audit and optimize Terraform/OpenTofu infrastructure code (Terraform 1.17 current, 1.16 supported, 1.15/1.14 EOL) for module and state structure, remote backends and locking, provider/module version pinning, plan/apply safety, drift and imports/moved blocks, secrets and IAM least privilege, network/storage/database security, CI policy/testing, and cost, with real before/after measurement. Always produces a written findings report and a fix plan for approval before touching code. Use this whenever the user mentions Terraform, OpenTofu, `.tf`/state/backend, state locking, `terraform plan`, drift

Original author description

Audit and optimize Terraform/OpenTofu infrastructure code (Terraform 1.17 current, 1.16 supported, 1.15/1.14 EOL) for module and state structure, remote backends and locking, provider/module version pinning, plan/apply safety, drift and imports/moved blocks, secrets and IAM least privilege, network/storage/database security, CI policy/testing, and cost, with real before/after measurement. Always produces a written findings report and a fix plan for approval before touching code. Use this whenever the user mentions Terraform, OpenTofu, `.tf`/state/backend, state locking, `terraform plan`, drift

How it works

  1. Workflow
  2. Principles
Original SKILL.md headings · 64 lines, 653 words
SKILL.md preview
---
name: terraform-optimizer
description: Audit and optimize Terraform/OpenTofu infrastructure code (Terraform 1.17 current, 1.16 supported, 1.15/1.14 EOL) for module and state structure, remote backends and locking, provider/module version pinning, plan/apply safety, drift and imports/moved blocks, secrets and IAM least privilege, network/storage/database security, CI policy/testing, and cost, with real before/after measurement. Always produces a written findings report and a fix plan for approval before touching code. Use this whenever the user mentions Terraform, OpenTofu, `.tf`/state/backend, state locking, `terraform plan`, drift, modules, providers, `moved`/`import`, tfstate leaks, IaC security, Checkov/tfsec/Trivy, Terragrunt, or "optimize my Terraform" -- even if they never say audit or optimize.
---

# Terraform Optimizer

Audit a Terraform codebase, report what is unsafe, brittle or expensive and why, agree a plan, then change it. Order: evidence, approval, edits. State and apply changes can destroy infrastructure; nothing is applied before approval.

## Workflow

### 1. Scope (quick)

- Map the repo: root modules, environments, backends, workspaces, providers, modules, state files, CI apply path and cloud accounts. Record Terraform/OpenTofu and provider versions.
- Run `python <skill-dir>/scripts/audit.py <repo-root>` -- static scan of `.tf`/`.tfvars`/lockfiles/state for EOL versions, unpinned providers/modules, missing backends/locking, hardcoded secrets, public network/storage, IAM wildcards, destructive settings and plan-safety gaps, with file:line evidence. Use `--json` to post-process.
- Classify the pain: state/backend, plan/apply safety, drift, module structure, security/compliance, provider/version upgrades, or cost. Ask which hurts if unclear.
- Read `references/tooling.md` once: what can be measured here (`terraform validate/plan`, plan JSON, `terraform graph`, cost, policy scans).

### 2. Audit

The script finds cheap leads; you find the rest by reading the root module, backend, variables, state and the CI plan/apply path. Load only what applies:

| Area | Reference |
|------|-----------|
| Modules, state/backends, workspaces, drift, moved/import | `references/modules-state.md` |
| Plan/apply safety, refresh, targeting, lifecycle, destroy | `references/plan-safety.md` |
| Secrets, IAM, network/storage/database security, provider auth | `references/security-secrets.md` |
| Plan time/parallelism, provider/resource graph, cost | `references/performance-cost.md` |
| `terraform test`, validation, policy/scanning, CI/CD | `references/testing-ci.md` |
| Measurement and honest reporting | `references/tooling.md` |

**Measure, never guess.** Run `terraform init -backend=false`, `validate`, `fmt -check`, a read-only `plan` in the target workspace/account, and a policy/scan pass. A clean `plan` is not proof of safety; review the diff, state and apply path.

Mark each finding **Confirmed** (plan/state/config/policy evidence) or **Suspected** (needs measuring).

### 3. Report

Fill `assets/report-template.md`, save it as `TERRAFORM_OPTIMIZATION_REPORT.md` in the repo root, and show the user. Five-line summary, findings table by impact/effort/risk, then per-finding detail (evidence, why it hurts, fix, state/plan impact, rollback). Group near-duplicates.

### 4. Plan -- then stop for approval

Use plan mode: `EnterPlanMode` (load with ToolSearch if deferred), write the plan, present with `ExitPlanMode`; if unavailable show it in chat and wait for an explicit "go". Structure:

1. **Quick wins** -- pin versions/providers/modules, add lockfile, remote backend/locking, remove hardcoded secrets, close public ports/ACLs, enable encryption/deletion protection, add lifecycle/prevent_destroy, fix plan-safety scripts. Low risk.
2. **Structural** -- split root modules/environments, introduce modules/composition, move state with `moved`/`import`, adopt workspaces or separate states, add policy/tests/CI gates, centralize providers/tags. Name each state/plan change.
3. **Heavy** -- Terraform/OpenTofu major upgrade, backend migration, provider major, module extraction/refactor, account/region split, Terragrunt/Stacks adoption. Separately approved with state backup and rollback.
   Each step: files/state touched, expected plan diff, how to verify, how to roll back.

### 5. Fix

Only approved items, in small groups. After each: `terraform fmt -check`, `validate`, `plan` in the target workspace, policy/scan, and review the diff. Never run `apply` as part of an audit without explicit approval. If a change alters state addresses, provider auth, IAM, network exposure or data stores, stop and ask; take a state backup first.

### 6. Verify and wrap up

Re-run the same checks: plan diff/no-op, policy/scan findings, state lineage/lock, drift, apply time, resource count and cost estimate. State plainly what could not be measured. End with deferred items and one suggested next step.

## Principles

- **State is the source of truth.** Remote, encrypted, locked, backed up and access-controlled.
- **Plan is a review artifact.** Save/show it; apply the exact approved plan, not a fresh one.
- **Pin everything.** Terraform/OpenTofu, providers, modules and lockfiles; upgrades are deliberate.
- **Least privilege and no public defaults.** IAM, security groups, buckets, databases.
- **Move, don't recreate.** `moved`/`import` before address changes; never hand-edit state.
- **Secrets are not variables in git.** Secret manager/CI env, sensitive/ephemeral values, encrypted state.
- **Modules need contracts.** Inputs/outputs/versions/README; avoid god modules and remote-state coupling.
- **Test and gate.** `terraform test`, validation, policy/scan and a PR plan.
- **Measure cost and drift.** A cheap plan can create expensive, drifting infrastructure.
Files in this package (11)
  • LICENSE 1 KB
  • README.md 1 KB
  • SKILL.md 6 KB
  • assets/report-template.md 1 KB
  • references/modules-state.md 2 KB
  • references/performance-cost.md 2 KB
  • references/plan-safety.md 2 KB
  • references/security-secrets.md 2 KB
  • references/testing-ci.md 2 KB
  • references/tooling.md 2 KB
  • scripts/audit.py 11 KB

Versions

The database has no other skills named terraform-optimizer.

Database snapshot: 13.11.2026 · package version 839558a2c0c4 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 1 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100terraform-patterns
    Use this skill when the user says 'terraform patterns', 'terraform remote state', 'terraform state locking', 's3 backend use_lockfile', 'terraform module structure', 'terraform environments', 'terraform for_each vs count', 'terraform moved block', 'terraform import block',…
  • 100terraform-ops
    Terraform and OpenTofu infrastructure-as-code operations - project layout, state management, module design, plan/apply safety, CI/CD pipelines, and secrets. Use for: terraform, opentofu, infrastructure as code, IaC, tfstate, terraform state, terraform module, remote backend,…
  • 100terraform
    Operate Terraform and OpenTofu across the whole infrastructure lifecycle: module structure, state backends and locking, plan/apply workflow, drift detection, remote state, upgrade and refactor flows, and evidence-based diagnostics. Use when running or inspecting terraform plans,…
  • 100trove-terraform
    Terraform/OpenTofu conventions and best practices. Auto-activates on .tf files. Covers module structure, state management, and security patterns. Use when: terraform module; tf state; opentofu.
  • 95glab-opentofu
    Work with OpenTofu state management in GitLab. Use when managing Terraform/OpenTofu state, configuring state backends, or working with infrastructure as code. Triggers on OpenTofu, Terraform, state management, infrastructure as code, IaC.
  • 100terraform-bump-terraform
    Use when updating the Terraform or OpenTofu CLI across module constraints, version-manager files, CI, and images.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.