一键导入
terraform-best-practices
Guidance for writing clean, maintainable, secure Terraform (HCL). Use when authoring or reviewing Infrastructure as Code with Terraform.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guidance for writing clean, maintainable, secure Terraform (HCL). Use when authoring or reviewing Infrastructure as Code with Terraform.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Guides users to build optimal agentic AI workflows OR optimize existing agents. Analyzes use cases, recommends patterns, selects frameworks (LangGraph, CrewAI, Strands), generates production-ready code, and optimizes existing implementations based on Amazon's production lessons.
Specialized agent for optimizing existing agentic AI systems based on Amazon's production lessons and AWS best practices
Generates production-ready agentic AI implementations with AWS best practices
Specialized agent for selecting optimal agentic AI frameworks (LangGraph, CrewAI, Strands)
Specialized agent for identifying optimal agentic AI patterns based on AWS prescriptive guidance
Guides AWS development with infrastructure automation and cloud architecture patterns. Use when designing or refactoring cloud-native applications on AWS, automating environment provisioning with Terraform/CDK/CloudFormation, setting up secure CI/CD pipelines, evaluating service choices for cost/scalability/fault tolerance, or preparing production runbooks and observability.
| name | terraform-best-practices |
| description | Guidance for writing clean, maintainable, secure Terraform (HCL). Use when authoring or reviewing Infrastructure as Code with Terraform. |
Guidance for writing clean, maintainable, secure Terraform (HCL). Reference when authoring or reviewing Infrastructure as Code with Terraform. Primary source: the HashiCorp Terraform Style Guide and Standard Module Structure.
Note: this project's existing backend uses AWS CDK (TypeScript). Use this skill when Terraform is preferred, or for greenfield IaC where Terraform is the chosen tool. For AWS service specifics, still verify against the AWS Knowledge MCP. Terraform, providers, and best practices evolve — confirm current syntax against official HashiCorp docs.
terraform fmt and terraform validate before every commit — automate via a Git pre-commit hook or CI step.= signs.count/for_each) first, then resource arguments, then nested blocks, then lifecycle, then depends_on. Separate groups with a blank line.# for single- and multi-line comments (// and /* */ are non-idiomatic)._, not dashes -, everywhere: resource names, data sources, variables, outputs, locals.resource "aws_instance" "web_api_aws_instance"resource "aws_instance" "web_api"resource "aws_instance" "web" {}.Recommended file layout for a configuration or module:
| File | Contents |
|---|---|
terraform.tf | Single terraform block: required_version and required_providers |
backend.tf | Backend configuration |
providers.tf | All provider blocks (default provider first) |
main.tf | Resources and data sources |
variables.tf | All variable blocks, alphabetical |
outputs.tf | All output blocks, alphabetical |
locals.tf | Local values referenced across files |
As the codebase grows, split main.tf by logical group (network.tf, storage.tf, compute.tf). It should always be obvious where to find a given resource.
type and description. Provide a sensible default for optional variables.sensitive = true (passwords, keys). Note: Terraform still stores these in plaintext in state — use a secrets manager for real protection.validation blocks only for genuinely restrictive requirements.description. Mark sensitive outputs accordingly. Design outputs around what consumers need.network module: VPC, subnets, gateway, security groups)../modules/<module_name>.terraform-<PROVIDER>-<NAME> (e.g. terraform-aws-ec2-instance).main.tf, variables.tf, outputs.tf, plus a README.md.terraform.tfstate*, .terraform.tfstate.lock.info, the .terraform/ directory, saved plan files, and any sensitive *.tfvars..tf files, the .terraform.lock.hcl dependency lock file, a .gitignore, and a README.md.tfe_outputs data source (HCP/TFE) or provider data sources — avoid sharing raw state files.terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.34.0"
}
}
required_version = ">= 1.7"
}
version parameter in the module block (local modules ignore version)..tf files or commit them. Use dynamic provider credentials or a secrets manager (e.g. HashiCorp Vault). Remember secrets still land in state in plaintext.count and for_each sparingly — they add power but also complexity. Comment non-obvious uses.count for near-identical resources or simple conditional creation (count = var.enabled ? 1 : 0).for_each (over a map or set) when instances need distinct values not derivable from an integer; gives stable keyed addresses rather than fragile index-based ones.main as the source of truth for all environments; use a workspace or directory per environment.terraform test) for modules and run them as a pre-merge check or CI step. Tests validate code behavior; preconditions/postconditions/validation validate deployed infrastructure — use both.