본문 바로가기

♻ Terraform(테라폼)/👉 Terraformer

Terraformer 트러블 슈팅 Error: Failed to read state file

# 오류내용은 아래와 같다.

│ Error: Failed to read state file
│
│ The state file could not be read: read ../../../generated/aws/route_table/terraform.tfstate: The  
│ process cannot access the file because another process has locked a portion of the file.

- 리소스를 콘솔에서 클릭 클릭 해서 만들고 라우트 테이블에 igw 라우팅 정보 입력하고 서브넷 까지 연결해줬다

그리고 아래의 명령어를 수행하여 import를 하고 로컬로 가져와서 terraform init / plan 했는데 위의 오류가 발생 했다.

terraformer import aws --resources=route_table --regions=ap-northeast-2 --filter="Name=tags.Name;Value=terraformer-test-01"

구글링을 아무리해도 답이 없길래...

삽질하다가

해당 내용을 주석처리하고 init / plan 했더니 되더라...

# data "terraform_remote_state" "route_table" {
#   backend = "local"

#   config = {
#     path = "../../../generated/aws/route_table/terraform.tfstate"
#   }
# }

data "terraform_remote_state" "subnet" {
  backend = "local"

  config = {
    path = "../../../generated/aws/subnet/terraform.tfstate"
  }
}

data "terraform_remote_state" "vpc" {
  backend = "local"

  config = {
    path = "../../../generated/aws/vpc/terraform.tfstate"
  }
}

퐝당하다.

terraformer도 완벽하지는 않은것 같다.

갓글이 만들었지만, GCP에 최적화를 시켜놓은것 같다.

AWS와는 호환되지 않는 부분이 조금은 있는것 같은데

그래도 이게 어디냐

기존 리소스를 Terraform Code로 변환해주고 오픈소스이고, 잘만 쓰면 리소스 관리에 도움이 많이 될거 같다.

- 끝 -