github/gitignore · Terraform.gitignore
Terraform .gitignore 템플릿 해설
Terraform.gitignore가 .terraform 폴더, tfstate, tfvars, override 파일, CLI 설정을 무시하는 이유와 .terraform.lock.hcl은 커밋해야 하는 이유를 설명합니다.
Terraform.gitignore는 인프라 코드를 다루는 저장소에서 상태와 비밀이 새지 않게 하는 데 초점이 있다. Terraform 상태 파일에는 리소스 속성이 평문으로 저장되며, 데이터베이스 비밀번호나 키가 포함될 수 있다.
.terraform.lock.hcl은 이 템플릿이 무시하지 않는다. HashiCorp는 이 의존성 잠금 파일을 버전 관리에 포함하라고 안내한다.
규칙별 해설
| 패턴 | 무엇을, 왜 무시하나 |
|---|---|
.terraform/ | 로컬 작업 디렉터리terraform init이 내려받은 프로바이더 바이너리와 모듈, 백엔드 설정이 들어간다. 운영체제별 바이너리라 공유할 수 없고 용량도 크다. |
*.tfstate*.tfstate.*.terraform.tfstate.lock.info | 상태 파일실제 인프라와 코드의 대응 관계를 기록한 파일이다. 민감 정보가 평문으로 들어가고, 여러 사람이 각자 복사본을 가지면 상태가 어긋난다. S3·Terraform Cloud 같은 원격 백엔드에 두고 잠금을 건다. |
*.tfvars*.tfvars.json | 변수 값 파일환경별 값과 비밀이 들어가는 파일이다. 템플릿 주석도 비밀번호·개인 키가 들어갈 가능성이 높다고 설명한다. |
override.tfoverride.tf.json*_override.tf*_override.tf.json | override 파일로컬에서 리소스 설정을 임시로 덮어쓰는 파일이다. 커밋하려면 템플릿 주석처럼 !example_override.tf 형태로 되살린다. |
crash.logcrash.*.log | 크래시 로그Terraform이 비정상 종료할 때 남기는 로그로, 설정 내용이 포함될 수 있다. |
.terraformrcterraform.rc | CLI 설정CLI 설정 파일로, Terraform Cloud 인증 토큰이 들어갈 수 있다. |
실무에서 주의할 점
.terraform.lock.hcl은 커밋한다. 모두가 같은 프로바이더 버전과 해시로 초기화하게 된다.- 공유가 필요한 기본 변수는
*.auto.tfvars가 아닌variables.tf의default나 예시 파일(terraform.tfvars.example)로 둔다.*.tfvars규칙은.example로 끝나는 파일은 무시하지 않는다. terraform plan -out=tfplan으로 만든 계획 파일도 민감 정보를 담으므로 템플릿 주석처럼*tfplan*규칙을 추가하는 것이 안전하다.- 상태 파일이 이미 커밋됐다면 저장소에서 제거하는 것과 함께 그 안에 있던 비밀을 모두 교체한다.
원본 템플릿
Terraform.gitignore
# Local .terraform directories.terraform/# .tfstate files*.tfstate*.tfstate.*# Crash log filescrash.logcrash.*.log# Exclude all .tfvars files, which are likely to contain sensitive data, such as# password, private keys, and other secrets. These should not be part of version# control as they are data points which are potentially sensitive and subject# to change depending on the environment.*.tfvars*.tfvars.json# Ignore override files as they are usually used to override resources locally and so# are not checked inoverride.tfoverride.tf.json*_override.tf*_override.tf.json# Ignore transient lock info files created by terraform apply.terraform.tfstate.lock.info# Include override files you do wish to add to version control using negated pattern# !example_override.tf# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan# example: *tfplan*# Ignore CLI configuration files.terraformrcterraform.rc# Optional: ignore graph output files generated by `terraform graph`# *.dot# Optional: ignore plan files saved before destroying Terraform configuration# Uncomment the line below if you want to ignore planout files.# planout
템플릿 출처: github/gitignore/Terraform.gitignore @356fd7b (2026-09-11) · CC0-1.0