본문으로 건너뛰기
cccskills
무료GitHub에 공개

terraform

Terraform best practices: state, security, modules, workflow, testing, tooling. Use when writing or reviewing Terraform code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

연동 도구Terraform
설치 방법 보기

포함된 파일(1)

  • SKILL.md4.8 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Terraform

State

  • Remote state always. Local state for throwaway experiments only
  • State backend with locking: S3 + DynamoDB, GCS, or Terraform Cloud/HCP
  • Separate state files per environment (dev, staging, prod). Never share state across envs
  • Encrypt state at rest. Versioning on state bucket enables rollback — never delete old versions without confirming they are not needed
  • Never commit .tfstate or .tfstate.backup to git. Add to .gitignore
  • sensitive = true on all outputs containing secrets, tokens, or credentials. Limits plaintext exposure in logs and state diffs

Security

  • Least privilege for the Terraform runner. Scope to exactly what it creates
  • OIDC / Workload Identity for CI runners. No long-lived access keys
  • Secrets never in .tf files or terraform.tfvars committed to git. Pass via TF_VAR_* env vars, Vault, or secret manager at plan/apply time
  • prevent_destroy = true on critical resources (databases, buckets, KMS keys)
  • plan before every apply. Review the diff. Never auto-apply to production without human approval
  • Pin provider versions with pessimistic constraints: ~> 5.0 locks to 5.x not 6.x. Full pins for production stability
  • required_version in every root module. Prevents silent version drift across team members

Workflow

  • CI pattern: plan on PR (post as comment), apply on merge to main. Never apply from developer laptops in production
  • GitOps orchestration: Atlantis (self-hosted, PR-driven), Spacelift or env0 for team workflows, audit trails, and drift detection
  • terraform fmt -recursive and terraform validate in CI. Fail on violations
  • tflint for provider-specific lint. checkov or tfsec for security misconfigurations. Both in CI pre-apply
  • Infracost in CI to surface cost delta per PR before apply
  • Drift detection: scheduled plan runs that alert on non-empty diffs
  • terraform-docs to auto-generate module README from variables and outputs. Enforce via CI check
  • tfenv for CLI version management. Commit .terraform-version to repo

Module design

  • Modules for reusable patterns. Flat root module for env-specific wiring
  • Required variables explicit. Optional variables with sane defaults
  • Expose only necessary outputs. sensitive = true on any output with secret values
  • Version-pin module sources (registry or git tag). Never ?ref=main — breaks reproducibility
  • Keep modules small and focused. One domain per module
  • for_each over count for resources with identity (databases, buckets, queues). count only for truly homogeneous replicas
  • moved blocks when renaming or refactoring resources. removed blocks when deleting managed resources
  • Variable validation with custom error messages: validation { condition = ... error_message = "..." }

Code quality

  • Consistent naming: <env>-<service>-<resource>. Pick one convention, enforce via tflint
  • locals for repeated expressions. No duplicated logic across resources
  • terraform_data (1.4+) over deprecated null_resource for triggers and lifecycle hooks
  • Avoid local-exec provisioners — side effects that survive plan/apply cycles. Use provider resources
  • lifecycle blocks only when needed. Document ignore_changes with a comment explaining why
  • Separate data source lookups from resource definitions. No inline data lookups mixed into resource arguments
  • Terragrunt for DRY multi-env root module wiring when directory-per-environment leads to excessive duplication

Testing

  • terraform test (native, 1.6+) for unit and integration testing of modules
  • check blocks for post-apply assertions: validate actual resource state beyond what Terraform tracks
  • Terratest (Go) for complex integration tests requiring real infra provisioning and teardown
  • Test variable edge cases: empty strings, null optionals, boundary values in validation blocks

Tooling reference

ToolPurpose
tfenvCLI version management
terraform fmtFormatting
tflintProvider-aware linting
checkov / tfsecSecurity misconfiguration scanning
InfracostCost delta per PR
AtlantisSelf-hosted GitOps PR automation
terraform-docsAuto-generated module documentation
TerragruntDRY multi-env root module wiring
terraform test / TerratestModule testing

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

aws

무료

AWS best practices: IAM, secrets, networking, security, compute, IaC, ops. Use when building, reviewing, or modifying AWS resources.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

SumonMSelim/agentguard542026년 10월 12일 업데이트

docker

무료

Docker best practices: image security, build efficiency, runtime hardening, Compose, local tooling (Colima, OrbStack). Use when writing or reviewing Dockerfiles and Compose files.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

SumonMSelim/agentguard542026년 10월 12일 업데이트

gcp

무료

GCP best practices: IAM, secrets, networking, security, compute, IaC, ops. Use when building, reviewing, or modifying GCP resources.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

SumonMSelim/agentguard542026년 10월 12일 업데이트

go

무료

Idiomatic Go 1.25 practices: errors, interfaces, concurrency, generics, testing, security, tooling. Use when writing or reviewing Go code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

SumonMSelim/agentguard542026년 10월 12일 업데이트

java

무료

Modern Java practices: design, errors, concurrency, security, testing, tooling. Targets Java 21 LTS baseline; Java 25 LTS features called out explicitly. Use when writing or reviewing Java code.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

SumonMSelim/agentguard542026년 10월 12일 업데이트

Behavioral guidelines to reduce common LLM coding mistakes. Use when writing, reviewing, or refactoring code to avoid overcomplication, make surgical changes, surface assumptions, and define verifiable success criteria.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

SumonMSelim/agentguard542026년 10월 12일 업데이트

SumonMSelim의 스킬 모두 보기

이 스킬의 문제 신고