IT/Terraform

[Terraform] terraform init Error 해결

반응형

terraform init을 할때 backend로 설정한 s3 버킷이 없거나 버킷명이 잘못 되었을 경우 아래와 같은 메시지가 발생합니다.

Initializing the backend...

Successfully configured the backend "s3"! Terraform will automatically
use this backend unless the backend configuration changes.
Error refreshing state: BucketRegionError: incorrect region, the bucket is not in 'ap-northeast-2' region at endpoint ''
        status code: 301, request id: , host id:

이때 backend 로 설정한 s3 bucket, key를 확인해서 실제로 존재하는 s3 bucket, key 를 입력하면 됩니다.

terraform {
  backend "s3" {
    bucket = "버킷이름"
    key    = "폴더/파일"
    region = "ap-northeast-2"
  }
}

만약 아래와 같이 backend.hcl 파일을 사용할 경우에도 bucket명 확인하여 해결 할 수 있습니다.

bucket = "버킷이름"
region = "ap-northeast-2"  
반응형