Terraform resource with this ID doesn't exist

I’m trying to import the existing s3 bucket to my terraform using the below commands

$ terraform import aws_s3_bucket.test-bucket test-bucket200

Here is my code;

resource "aws_s3_bucket" "test-bucket" {
  bucket = "test-bucket200"

resource "aws_s3_bucket_public_access_block" "test-bucket-acl" {
  bucket = "${aws_s3_bucket.test-bucket.id}"

  block_public_acls   = false
  block_public_policy = false

While importing aws_s3_bucket_public_access_block (after the bucket import) throwing me the error

$ terraform import aws_s3_bucket_public_access_block.test-bucket-acl test-bucket200

Terraform detected a resource with this ID doesn’t exist. Please verify the ID is correct. You cannot import non-existent.resources using Terraform import.

However my state shows;

$ terraform state show
id = test-bucket200
arn = arn:aws:s3:::test-bucket200

What am I doing wrong here?

$ terraform version
Terraform v0.11.13
+ provider.aws v2.10.0

Thanks in Advance!

I can’t see anything that you’re doing wrong here. I was able to successfully follow the steps you took with Terraform 0.12.28 and 0.13.2, and the import succeeded. Can you try upgrading your Terraform version?

1 Like

@teammoolepadam Hi there :slight_smile:

This is not an issue of aws provider, the root cause is the way how bucket was created.
If you created it manually via AWS Web Console, then public-access-block configuration is created automatically and you can import it.
If you created it via aws cli (with aws s3 mb command) or via terraform, then public-access-block configuration was not created and thus can’t be imported.
I have just checked this with your particular version of aws provider — it works fine when public-access-block configuration does exist.

1 Like