본문 바로가기
T101 4기

4-2. tfstate 파일 관리

by yeongki0944 2024. 7. 6.

1. 팀 단위 테라폼 운영시 - 상태파일 관리 문제점

  1. 상태 파일을 저장하는 공유 스토리지 Shared storage for state files
    • 각 팀원이 동일한 테라폼 상태 파일 사용을 위해서, 공유 위치에 저장이 필요
  2. 상태 파일 잠금 Locking state files
    • 잠금 기능 없이 두 팀원이 동시에 테라폼 실행 시 여러 테라폼 프로세스가 상태 파일을 동시에 업데이트하여 충돌 가능(경쟁 상태 race condition)
  3. 상태 파일 격리 Isolating state files
    • 예를 들면 테스트 dev 와 검증 stage 과 상용 prodction 각 환경에 대한 격리가 필요

 

출처 : [악분의 블로그] 테라폼 시리즈 20편. 협업을 위한 테라폼 관리

 

2. tfstate 파일 저장 위치

관리방법 저장위치
로컬 상태 파일 관리 로컬 파일(terraform.tfstate)
원격 상태 파일 관리 원격 백엔드
     - AWS S3
     - Azure Blob Storage
     - Google Cloud Storage
     - Consul
     - Postgres database 등
Terraform Cloud
(Enterprise)
Terraform Cloud

 

3. tfstate 파일 격리하는 방법

3-1. Workspace

https://developer.hashicorp.com/terraform/language/state/workspaces

 

3-2. file layout