Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import a S3 Bucket from a different region of my global provider #13750

Closed
nilo opened this issue Apr 18, 2017 · 5 comments
Closed

Import a S3 Bucket from a different region of my global provider #13750

nilo opened this issue Apr 18, 2017 · 5 comments

Comments

@nilo
Copy link

nilo commented Apr 18, 2017

Hi there,
The problem:
I have an S3 Bucket with my states on ca-central-1 and all my other infra are on us-east-2. I never created anything on us-east-2 when I ran terraform apply I can't create a Bucket resource on ca-central-1 that already exists, so I need to import it using something like: terraform import aws_s3_bucket.bucket states-terraform-stage. When I do this I get this error:

Error importing: 1 error(s) occurred:

* aws_s3_bucket.bucket (import id: states-terraform-stage): import aws_s3_bucket.bucket (id: states-terraform-stage): Error importing AWS S3 bucket policy: BucketRegionError: incorrect region, the bucket is not in 'us-east-2' region
        status code: 301, request id: , host id:

Terraform is trying to import the resource from us-east-2 and not from ca-central-1.
A -region= option should resolve the problem.

Terraform Version

0.9.3

Affected Resource(s)

  • aws_s3_bucket

Expected Behavior

import an s3 bucket from another region.

Actual Behavior

It is trying to import a bucket from the same region of the provider.

Steps to Reproduce

  1. Create an S3 bucket on ca-central-1 using AWS console eg: states-tr
  2. Create a S3 bucket config aws_s3_bucket with the provider point to ca-central-1 with the same name
  3. Create all you infra on us-east-2
  4. Try to import it using:
    terraform import aws_s3_bucket.bucket states-tr
@grubernaut
Copy link
Contributor

Hey @nilo, thanks for the issue!

If you specify the correct provider for the ca-central-1 region does the import work?
ie:

$ terraform import -provider=ca-central-provider aws_s3_bucket.bucket states-tr

@nilo
Copy link
Author

nilo commented Apr 19, 2017

That's what I was looking for @grubernaut thanks!

@nilo nilo closed this as completed Apr 19, 2017
@ILMostro
Copy link

Is there a minimum version of terraform where this works?
I keep getting errors still on v.0.8.8

@Laxman-SM
Copy link

i am using latest version of terraform with s3 backend KMS and server side encryption and this work fine for me.
Terraform v0.11.6
terraform import -provider=aws aws_s3_bucket.bucket_tfstates tfstates-dockerswarm-1

Acquiring state lock. This may take a few moments...
aws_s3_bucket.bucket_tfstates: Importing from ID "tfstates-dockerswarm-1"...
aws_s3_bucket.bucket_tfstates: Import complete!
Imported aws_s3_bucket (ID: tfstates-dockerswarm-1)
Imported aws_s3_bucket_policy (ID: tfstates-dockerswarm-1)
aws_s3_bucket.bucket_tfstates: Refreshing state... (ID: tfstates-dockerswarm-1)
aws_s3_bucket_policy.bucket_tfstates: Refreshing state... (ID: tfstates-dockerswarm-1)

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

Releasing state lock. This may take a few moments...

@ghost
Copy link

ghost commented Apr 3, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants