Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BucketRegionError: incorrect region, the bucket is not in 'eu-west-2' - terraform

Tags:

terraform

I need terraform to access my S3 bucket, but it is not able to find the bucket on the specified region.

My 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" {}

following is the error which I'm getting on terraform init command:

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:
like image 390
Charvee Punia Avatar asked Mar 25 '19 12:03

Charvee Punia


2 Answers

For me removing the .terraform folder and trying terraform init again solved the region related issue for me.

like image 90
Tara Prasad Gurung Avatar answered Sep 17 '22 10:09

Tara Prasad Gurung


no need to remove the whole .terraform folder:

  1. find your .terraform/terraform.tfstate
  2. remove json object responsible for S3 bucket
  3. remove the stanza generating remote backend
  4. run terraform init & enjoy

error is appearing apparently because there's no S3 bucket created to sync with.

like image 36
Artem Kozlenkov Avatar answered Sep 18 '22 10:09

Artem Kozlenkov