Terraform import examples

May I request for examples if ‘terraform import …’ uses, for S3 resources, etc etc.

Thanks,

1 Like

There are import examples for some but not all, ie https://www.terraform.io/docs/providers/aws/r/s3_bucket.html#import but not for bucket_object.
Anything in particular you’re missing?

1 Like

I could be wrong but I dont think this is a supported function. Terraform import allows you to import resources from one state to another.

I know in the past I’ve seen some Github projects but no I know of no official projects that support what you’re asking.

That is exactly what terraform import does, only you have to create the resource definition first - otherwise, Terraform won’t know how to refer to the resource, it doesn’t have a name.

Then, you do a plan and see if you need to tweak your resource definition a bit to match what’s deployed.

Make a backup of your statefile and try it out

As i’m going through the same process myself, i go to the resource in question, to see what the id is and then run something like this:

aws ec2 describe-security-groups --filters="Name=vpc-id,Values=vpc-fkdiekdi" --query "SecurityGroups[*].{Name:GroupName, Id:GroupId}" --output table

But with s3, its fairly simple, like aws_iam_role importing a bucket requires only the name:
terraform import aws_s3_bucket.bucket_value_from_config bucket_name

https://www.terraform.io/docs/providers/aws/r/s3_bucket.html - See Bottom for the import statement, which is on every resource page at the bottom.

HTH,
Jeff

That may be part of it, but why in your import did you not give it a second argument? Or is that just what you put in this thread. I would think it should be terraform import aws_s3_bucket.glen-bucket2 glen-bucket2?