IT/Terraform

[Terraform] 테라폼 소스 git push가 안돼는 이슈 해결책 (git push 특정 경로 제외시키기)

반응형

Intro

테라폼 소스를 git에 push를 할때 파일 사이즈가 크다는 에러가 발생할 수 있습니다. 그 이유는 테라폼 프로젝트 폴더안에 .terraform폴더가 있는데 여기에 terraform-provider 가 포함되기 때문입니다.

.terraform 폴더는 소스를 공유할 필요가 없기 때문에 해당 경로를 제외하고 git push를 하는 방법을 알아보도록 하겠습니다.

에러 메시지

terraform 소스를 git push를 할때 아래와 같이 파일 사이즈가 너무 커서 push할 수 없다는 에러메시지를 확인할 수 있습니다.

remote: error: File .terraform/providers/registry.terraform.io/hashicorp/aws/3.71.0/darwin_arm64/terraform-provider-aws_v3.71.0_x5 is 275.08 MB

해결책1

git filter-branch를 통해서 해당 경로(.terraform)를 제외 시킬 수 있습니다.

git filter-branch -f --index-filter 'git rm --cached -r --ignore-unmatch .terraform/’

그 이후에 다시 push를 하면 문제 없이 소스 파일만 잘 push되는것을 확인 할 수 있습니다.

해결책2

  • .gitignore 설정하기
    폴더 경로는 사용자의 구조에 맞게 변경하시면됩니다.
# Local .terraform directories
**/.terraform/*
terraform.exe
terraform

# Etc files
*.cmd*
old
plan.txt
*.csv*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# 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*
.terraform.lock.hcl
반응형