BucketRegionError:区域不正确,存储桶不在“ eu-west-2”中-Terraform

时间:2019-03-25 12:07:33

标签: terraform

我需要地形来访问我的S3存储桶,但找不到指定区域上的存储桶

main.tf

provider "aws" {
region = "eu-west-2"
}

terraform {
backend "s3" {
bucket = "xyz-state-blog"
key    = "dev/terraform"
region = "eu-west-2"
}
}

 locals {
  azs       = ["eu-west-2a", "eu-west-2b", "eu-west-2c"]
  environment            = "dev"
  kops_state_bucket_name = "${local.environment}-kops-state"
 // Needs to be a FQDN
 kubernetes_cluster_name = "k8s-dev0.domain.com"
 ingress_ips             = ["10.0.0.100/32", "10.0.0.101/32"]
 vpc_name                = "${local.environment}-vpc"

  tags = {
  environment = "${local.environment}"
  terraform   = true
  }
  }

  data "aws_region" "current" {}

以下是我在terraform init命令中遇到的错误

   Error inspecting states in the "s3" backend:
   BucketRegionError: incorrect region, the bucket is not in 'eu-west-2' region
status code: 301, request id: , host id:

2 个答案:

答案 0 :(得分:8)

对我来说,删除 .terraform文件夹,然后再次尝试terraform init为我解决了与区域相关的问题。

答案 1 :(得分:1)

无需删除整个 .terraform 文件夹:

  1. 找到您的.terraform/terraform.tfstate
  2. 移除负责 S3 存储桶的 json 对象
  3. 删除生成远程后端的节
  4. 运行terraform init并享受

错误显然是因为没有创建要与之同步的 S3 存储桶。