Santosh Kumar Arjunan
Santosh Kumar Arjunan

Reputation: 3896

AWS S3 buckets creation in different regions using Terraform

I'm getting the following error while trying to create an S3 bucket in different region other than the region mentioned in the provider declaration.

Error: Error creating S3 bucket: IllegalLocationConstraintException: The eu-central-1 location constraint is incompatible for the region specific endpoint this request was sent to. status code: 400, request id: CDC41B1AC8DECE02, host id: rZq1QatrmMLJ4pKfM5Ry5vg2asFYOGTJJNVVquXgnr3L506hHpFZf67YOiatapSc3UGtYntQsbU=

Solution: It seems that as per AWS Documentation, https://docs.aws.amazon.com/cli/latest/reference/s3api/create-bucket.html, need to mention the LocationConstraint also.

$ aws s3api create-bucket --bucket my-bucket --region eu-west-1 --create-bucket-configuration LocationConstraint=eu-west-1

However, I don't see that equivalent configuration parameter in the Terraform code documentation https://www.terraform.io/docs/providers/aws/r/s3_bucket.html. I use latest Terraform version: 0.12.3

Sample Terraform Code:

resource "aws_s3_bucket" "public-alb-logs-bucket" {
  bucket  = "alb-access-logs-prod"
  region  = "eu-central-1"
}

provider "aws" {
  version   = "~> 2.14.0"
  region  = "us-west-2"  
}

The same code works in case if both the regions are the same. (in S3 resource and provider sections).

Any help/idea would be much appreciated. thanks. Please also let me know in case of any additional information.

Upvotes: 3

Views: 5521

Answers (1)

Mike Williamson
Mike Williamson

Reputation: 3218

I cannot confirm, but I think the problem is that your regions don't match:

resource "aws_s3_bucket" "public-alb-logs-bucket" {
  bucket  = "alb-access-logs-prod"
  region  = "eu-central-1" ### This region is different from the one below
}

provider "aws" {
  version   = "~> 2.14.0"
  region  = "us-west-2" ### This region is different from the one above
}

I currently work with accounts in different regions and accounts that have resources in multiple regions. But I have never tried to deploy resources using a provider region that does not match a resource region.

So I'm guessing this is the problem??

Upvotes: 0

Related Questions