title: Terraform Error refreshing state: BucketRegionError: incorrect region
body: <p>I have the terraform file <code>main.tf</code> that used to create AWS resources:</p>
  <pre><code>provider &quot;aws&quot; {
      region = &quot;us-east-2&quot;
  }
  
  resource &quot;aws_instance&quot; &quot;example&quot; {
  
      ami = &quot;ami-0c55b159cbfafe1f0&quot;
      instance_type = &quot;t2.micro&quot;
      vpc_security_group_ids = [
          aws_security_group.instance.id]
  
      user_data = &lt;&lt;-EOF
                #!/bin/bash
                echo &quot;Hello, World&quot; &gt; index.html
                nohup busybox httpd -f -p &quot;${var.server_port}&quot; &amp;
                EOF
  
      tags = {
          Name = &quot;terraform-example&quot;
      }
  }
  
  resource &quot;aws_security_group&quot; &quot;instance&quot; {
  
      name = &quot;terraform-example-instance&quot;
  
      ingress {
  
          from_port = var.server_port
          to_port = var.server_port
          protocol = &quot;tcp&quot;
          cidr_blocks = [
              &quot;0.0.0.0/0&quot;]
      }
  }
  
  resource &quot;aws_security_group&quot; &quot;elb&quot; {
      name = &quot;terraform-example-elb&quot;
      # Allow all outbound
      egress {
          from_port = 0
          to_port = 0
          protocol = &quot;-1&quot;
          cidr_blocks = [
              &quot;0.0.0.0/0&quot;]
      }
      # Inbound HTTP from anywhere
      ingress {
          from_port = 80
          to_port = 80
          protocol = &quot;tcp&quot;
          cidr_blocks = [
              &quot;0.0.0.0/0&quot;]
      }
  }
  
  variable &quot;server_port&quot; {
  
      description = &quot;The port the server will use for HTTP requests&quot;
      type = number
      default = 8080
  }
  
  
  variable &quot;elb_port&quot; {
  
      description = &quot;The port the server will use for HTTP requests&quot;
  
      type = number
      default = 80
  }
  
  
  resource &quot;aws_launch_configuration&quot; &quot;example&quot; {
  
      image_id = &quot;ami-0c55b159cbfafe1f0&quot;
      instance_type = &quot;t2.micro&quot;
      security_groups = [
          aws_security_group.instance.id]
  
      user_data = &lt;&lt;-EOF
                #!/bin/bash
                echo &quot;Hello, World&quot; &gt; index.html
                nohup busybox httpd -f -p &quot;${var.server_port}&quot; &amp;
                EOF
      lifecycle {
          create_before_destroy = true
      }
  }
  
  
  resource &quot;aws_elb&quot; &quot;example&quot; {
  
      name = &quot;terraform-asg-example&quot;
      security_groups = [
          aws_security_group.elb.id]
  
      availability_zones = data.aws_availability_zones.all.names
  
      health_check {
          target = &quot;HTTP:${var.server_port}/&quot;
          interval = 30
          timeout = 3
          healthy_threshold = 2
          unhealthy_threshold = 2
      }
  
      # This adds a listener for incoming HTTP requests.
      listener {
          lb_port = var.elb_port
          lb_protocol = &quot;http&quot;
          instance_port = var.server_port
          instance_protocol = &quot;http&quot;
      }
  }
  
  
  resource &quot;aws_autoscaling_group&quot; &quot;example&quot; {
  
      launch_configuration = aws_launch_configuration.example.id
      availability_zones = data.aws_availability_zones.all.names
  
      min_size = 2
      max_size = 10
  
      load_balancers = [
          aws_elb.example.name]
      health_check_type = &quot;ELB&quot;
  
      tag {
          key = &quot;Name&quot;
          value = &quot;terraform-asg-example&quot;
          propagate_at_launch = true
      }
  }
  
  data &quot;aws_availability_zones&quot; &quot;all&quot; {}
  
  
  output &quot;public_ip&quot; {
  
      value = aws_instance.example.public_ip
      description = &quot;The public IP of the web server&quot;
  }
  </code></pre>
  <p>I successfully created the resources and then, destroyed them afterward. Now, I would like to create an AWS S3 remote backend for the project and appended the extra resources in the same file -</p>
  <pre><code>resource &quot;aws_s3_bucket&quot; &quot;terraform_state&quot; {
  
      bucket = &quot;terraform-up-and-running-state12345&quot;
      # Enable versioning so we can see the full revision history of our
      # state files
      versioning {
          enabled = true
      }
      # Enable server-side encryption by default
      server_side_encryption_configuration {
          rule {
              apply_server_side_encryption_by_default {
                  sse_algorithm = &quot;AES256&quot;
              }
          }
      }
  }
  
  
  resource &quot;aws_dynamodb_table&quot; &quot;terraform_locks&quot; {
  
      name = &quot;terraform-up-and-running-locks&quot;
      billing_mode = &quot;PAY_PER_REQUEST&quot;
      hash_key = &quot;LockID&quot;
  
      attribute {
          name = &quot;LockID&quot;
          type = &quot;S&quot;
      }
  }
  
  
  
  output &quot;s3_bucket_arn&quot; {
  
      value = aws_s3_bucket.terraform_state.arn
      description = &quot;The ARN of the S3 bucket&quot;
  }
  
  output &quot;dynamodb_table_name&quot; {
  
      value = aws_dynamodb_table.terraform_locks.name
      description = &quot;The name of the DynamoDB table&quot;
  }
  </code></pre>
  <p>Then, I created a new file named <code>backend.tf</code> and add the code there:</p>
  <pre><code>terraform {
  
      
      backend &quot;s3&quot; {
  
          # Replace this with your bucket name!
          bucket = &quot;terraform-up-and-running-state12345&quot;
          key = &quot;global/s3/terraform.tfstate&quot;
          region = &quot;us-east-2&quot;
  
  
          # Replace this with your DynamoDB table name!
          dynamodb_table = &quot;terraform-up-and-running-locks&quot;
          encrypt = true
      }
  }
  </code></pre>
  <p>When I run the <code>$ terraform init</code>, I get the error below:</p>
  <pre><code>Initializing the backend...
  Backend configuration changed!
  
  Terraform has detected that the configuration specified for the backend
  has changed. Terraform will now check for existing state in the backends.
  
  
  ╷
  │ Error: Error loading state:
  │     BucketRegionError: incorrect region, the bucket is not in 'us-east-2' region at endpoint ''
  │   status code: 301, request id: , host id: 
  │ 
  │ Terraform failed to load the default state from the &quot;s3&quot; backend.
  │ State migration cannot occur unless the state can be loaded. Backend
  │ modification and state migration has been aborted. The state in both the
  │ source and the destination remain unmodified. Please resolve the
  │ above error and try again.
  </code></pre>
  <p>I created the S3 bucket from the terminal:</p>
  <pre><code>$ aws s3api create-bucket --bucket terraform-up-and-running-state12345 --region us-east-2 --create-bucket-configuration LocationConstraint=us-east-2
  </code></pre>
  <p>Then, I tried again and receive the same error again. However, the bucket is already there:</p>
  <p><a href="https://i.stack.imgur.com/ggfjI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ggfjI.png" alt="enter image description here" /></a></p>
  <p>I can't also run the destroy command as well:</p>
  <pre><code>$ terraform destroy               
  
  Acquiring state lock. This may take a few moments...
  ╷
  │ Error: Error acquiring the state lock
  │ 
  │ Error message: 2 errors occurred:
  │   * ResourceNotFoundException: Requested resource not found
  │   * ResourceNotFoundException: Requested resource not found
  │ 
  │ 
  │ 
  │ Terraform acquires a state lock to protect the state from being written
  │ by multiple users at the same time. Please resolve the issue above and try
  │ again. For most commands, you can disable locking with the &quot;-lock=false&quot;
  │ flag, but this is not recommended.
  </code></pre>
  <p>Can someone explain to me why is that and how to solve it?</p>