flowchart LR
A[코드(HCL)] -- plan --> B{현재 State 로드}
B -- 리프레시 --> C[실제 클라우드와 비교]
C -- diff --> D[Plan 생성]
D -- apply --> E[실제 변경]
E -- 결과 반영 --> F[State 쓰기(.tfstate/원격)]
outputs를 통해 의존(terraform_remote_state)terraform plan : 기본 리프레시 후 차이를 보여줌terraform apply -refresh-only : 실물 값을 State에만 반영(구성 변경 없음)apply로 수습terraform state list # 상태에 기록된 주소 나열
terraform state show aws_instance.web # 특정 리소스 상태 보기
terraform state mv old.addr new.addr # 주소 변경(신중! 일반적으론 moved 권장)
terraform state rm addr # 상태에서만 제거(실물은 남음)
terraform plan -replace=aws_instance.web # 해당 리소스 재생성 강제
terraform apply -refresh-only # 리프레시만 반영
리팩터링(이름/키 변경)은 가급적
moved블록을 코드에 남겨 수행.
data "terraform_remote_state" "network" {
backend = "s3"
config = {
bucket = "my-tfstate-bucket"
key = "project/prod/network.tfstate"
region = "ap-northeast-2"
}
}
output "public_subnet_ids" {
value = data.terraform_remote_state.network.outputs.public_subnet_ids
}
.tfstate, .tfstate.backup, .terraform/)project/env/stack.tfstate)plan -out → apply plan.bin 패턴으로 리뷰/적용moved { from = ... to = ... }로 파괴 없이 이전