TerramateBackendSKILL.mdVerified source

Agent Skill

Terraform best practices

Review Terraform modules, state, plans, and delivery workflows before infrastructure changes ship.

terraforminfrastructureiac

Skill specification

Declared by Terramate in the package front matter. Trigger conditions are what the coding agent matches on before it loads the skill.

Terraform best practices SKILL.md front matter fields
Skill nameterraform-best-practices
Trigger conditionsTerraform and Infrastructure as Code optimization guidelines from Terramate. This skill should be used when writing, reviewing, or refactoring Terraform/OpenTofu code to ensure optimal patterns for security, maintainability, and reliability. Triggers on tasks involving Terraform modules, infrastructure provisioning, state management, or IaC optimization.
Declared licenseMIT
Version1.0.0
Authorterramate

Install terraform-best-practices

Agent Skills are a shared file format, but each client discovers them from a different directory. Copy the command for your agent, then start a new session so the skill is picked up.

Claude Code

.claude/skills/terraform-best-practices/SKILL.md

Project skills are committed with the repo. Use the user directory for a personal install across every project.

Project install

mkdir -p .claude/skills/terraform-best-practices && curl -fsSL 'https://raw.githubusercontent.com/terramate-io/agent-skills/main/skills/terraform-best-practices/SKILL.md' -o .claude/skills/terraform-best-practices/SKILL.md

Personal install

mkdir -p ~/.claude/skills/terraform-best-practices && curl -fsSL 'https://raw.githubusercontent.com/terramate-io/agent-skills/main/skills/terraform-best-practices/SKILL.md' -o ~/.claude/skills/terraform-best-practices/SKILL.md

Codex

.agents/skills/terraform-best-practices/SKILL.md

Codex reads `.agents/skills/` as its primary location, which is also the cross-platform default other clients honour.

Project install

mkdir -p .agents/skills/terraform-best-practices && curl -fsSL 'https://raw.githubusercontent.com/terramate-io/agent-skills/main/skills/terraform-best-practices/SKILL.md' -o .agents/skills/terraform-best-practices/SKILL.md

Personal install

mkdir -p ~/.agents/skills/terraform-best-practices && curl -fsSL 'https://raw.githubusercontent.com/terramate-io/agent-skills/main/skills/terraform-best-practices/SKILL.md' -o ~/.agents/skills/terraform-best-practices/SKILL.md

Cursor

.cursor/skills/terraform-best-practices/SKILL.md

Cursor also loads `.agents/skills/`, `.claude/skills/`, and `.codex/skills/`, so one committed copy can serve several clients.

Project install

mkdir -p .cursor/skills/terraform-best-practices && curl -fsSL 'https://raw.githubusercontent.com/terramate-io/agent-skills/main/skills/terraform-best-practices/SKILL.md' -o .cursor/skills/terraform-best-practices/SKILL.md

Personal install

mkdir -p ~/.cursor/skills/terraform-best-practices && curl -fsSL 'https://raw.githubusercontent.com/terramate-io/agent-skills/main/skills/terraform-best-practices/SKILL.md' -o ~/.cursor/skills/terraform-best-practices/SKILL.md

GitHub Copilot

.github/skills/terraform-best-practices/SKILL.md

Copilot in VS Code discovers repository skills from `.github/skills/`.

Project install

mkdir -p .github/skills/terraform-best-practices && curl -fsSL 'https://raw.githubusercontent.com/terramate-io/agent-skills/main/skills/terraform-best-practices/SKILL.md' -o .github/skills/terraform-best-practices/SKILL.md

Personal install

mkdir -p ~/.copilot/skills/terraform-best-practices && curl -fsSL 'https://raw.githubusercontent.com/terramate-io/agent-skills/main/skills/terraform-best-practices/SKILL.md' -o ~/.copilot/skills/terraform-best-practices/SKILL.md

Published by Terramate under MIT. Rendered from the package in github.com/terramate-io/agent-skills/tree/main/skills/terraform-best-practices.

Terraform Best Practices

Comprehensive optimization guide for Terraform and Infrastructure as Code, maintained by Terramate. Contains 37 rules across 10 categories, prioritized by impact to guide automated refactoring and code generation.

When to Apply

Reference these guidelines when:

  • Writing new Terraform modules or configurations
  • Implementing infrastructure patterns (AWS, GCP, Azure, etc.)
  • Reviewing code for security and reliability issues
  • Refactoring existing Terraform/OpenTofu code
  • Optimizing state management and performance
  • Setting up team workflows and governance

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Organization & WorkflowCRITICALorg-
2State ManagementCRITICALstate-
3Security Best PracticesCRITICALsecurity-
4Module DesignHIGHmodule-
5Resource OrganizationMEDIUM-HIGHresource-
6Variable & Output PatternsMEDIUMvariable-, output-
7Language Best PracticesMEDIUMlanguage-
8Provider ConfigurationMEDIUMprovider-
9Performance OptimizationLOW-MEDIUMperf-
10Testing & ValidationLOWtest-

Quick Reference

1. Organization & Workflow (CRITICAL) - 5 rules

  • org-version-control - All Terraform code in version control
  • org-workspaces - One workspace per environment per configuration
  • org-access-control - Control who can change what infrastructure
  • org-change-workflow - Formal process for infrastructure changes
  • org-audit-logging - Track all infrastructure changes

2. State Management (CRITICAL) - 3 rules

  • state-remote-backend - Always use remote state backends
  • state-locking - Enable state locking to prevent corruption
  • state-import - Import existing infrastructure into Terraform

3. Security Best Practices (CRITICAL) - 3 rules

  • security-no-hardcoded-secrets - Never hardcode secrets in code
  • security-credentials - Use proper credential management (OIDC, Vault, IAM roles)
  • security-iam-least-privilege - Follow least privilege principle

4. Module Design (HIGH) - 5 rules

  • module-single-responsibility - One module per logical component
  • module-naming - Use consistent naming conventions (terraform-<PROVIDER>-<NAME>)
  • module-versioning - Version all module references
  • module-composition - Compose modules like building blocks
  • module-registry - Use existing community/shared modules

5. Resource Organization (MEDIUM-HIGH) - 5 rules

  • resource-naming - Use consistent naming conventions
  • resource-tagging - Tag all resources for cost tracking
  • resource-lifecycle - Use lifecycle blocks (prevent_destroy, ignore_changes)
  • resource-count-vs-foreach - Prefer for_each over count
  • resource-immutable - Prefer immutable infrastructure patterns

6. Variable & Output Patterns (MEDIUM) - 6 rules

  • variable-types - Use specific types, positive naming, nullable
  • variable-validation - Add validation rules for early error detection
  • variable-sensitive - Mark secrets as sensitive, no defaults
  • variable-descriptions - Document all variables with descriptions
  • output-descriptions - Document all outputs with descriptions
  • output-no-secrets - Never output secrets directly

7. Language Best Practices (MEDIUM) - 5 rules

  • language-no-heredoc-json - Use jsonencode/yamlencode, not HEREDOC
  • language-locals - Use locals to name complex expressions
  • language-linting - Run terraform fmt and tflint
  • language-data-sources - Use data sources instead of hardcoding
  • language-dynamic-blocks - Use dynamic blocks for DRY code

8. Provider Configuration (MEDIUM) - 1 rule

  • provider-version-constraints - Pin provider versions

9. Performance Optimization (LOW-MEDIUM) - 2 rules

  • perf-parallelism - Tune parallelism for large deployments
  • perf-debug - Enable debug logging for troubleshooting

10. Testing & Validation (LOW) - 2 rules

  • test-strategies - Testing pyramid (validate, lint, plan, integration)
  • test-policy-as-code - Implement policy checks (OPA, Checkov, tfsec)

How to Use

Read individual rule files for detailed explanations and code examples:

rules/state-remote-backend.md
rules/security-no-hardcoded-secrets.md
rules/module-versioning.md

Each rule file contains:

  • Brief explanation of why it matters
  • Incorrect code example with explanation
  • Correct code example with explanation
  • Additional context and references

Full Compiled Document

For the complete guide with all rules expanded: AGENTS.md

Add the registry badge

Maintainers can link this listing from the skill's own README. Free, no account needed, and it points back at the rendered package for anyone browsing the repo.

Markdown

[![Terraform best practices on tokens&](https://tokensand.com/api/badges/skill/terramate-terraform-best-practices)](https://tokensand.com/agent-skills/terramate-terraform-best-practices)

HTML

<a href="https://tokensand.com/agent-skills/terramate-terraform-best-practices" target="_blank" rel="noopener">
  <img src="https://tokensand.com/api/badges/skill/terramate-terraform-best-practices" alt="Terraform best practices on tokens&" />
</a>

More Terramate Agent Skills

All Agent Skills