May I request for examples if ‘terraform import …’ uses, for S3 resources, etc etc.
Thanks,
May I request for examples if ‘terraform import …’ uses, for S3 resources, etc etc.
Thanks,
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?
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
?
To make the import example more clear it should be
terraform import aws_s3_bucket.local-name bucket-name
Using the terminology from Terraform resource doc. It would have taken out the guess work.
Hi Ben,
Thanks for the direction.
Is it possible to fetch specific vpc with all resources via the import filter command?
Thanks
Hi, all
I don’t know if here is good place for my question, but it related to the terraform import.
I have endpoint with default configuration, and data source resource for reading this configuration. Of course I can import configuration to some resource, but how I can change it?
terraform import configuration.conf "-"
For example I need change this configuration, I write new configuration and change some fields.
resource "configuration" "conf" {
password_enforce_complexity = false
password_lockout_attempts = 0
storage_enabled = true
}
But I need to change only this fields another should be from configuration which I get from endpoint during import or data source reading.
How I can figure out from this?
PS. If I write question not very clearly please ask question.
When you import a resource you are saying that Terraform now manages it. Exactly what that means depends upon what the provider defines for the resource, but it means that all the defined parameters will be being checked & updated by Terraform.
Once you have imported the resource you can reference the values directly, so wouldn’t need to use a data resource.
Just want to share how to import a resource that’s referred via for_each
meta argument:
Given:
resource "ibm_cos_bucket" "a_set_of_buckets" {
for_each = toset(["foo", "bar"])
bucket_name = "${each.key}"
resource_instance_id = data.ibm_resource_instance.cos_instance.id
storage_class = "standard"
region_location = var.region
}
It needs to run terraform import ibm_cos_bucket.a_set_of_buckets[\"foo\"] $bucket_crn:meta:$type:$location
to import a keyed resource.
Once you import, is there a way to see HCL representing the imported object? I am using VS Code and was eventually successful in my import getting the ‘now managed by Terraform’ message but cannot figure out how to output it for editing.
There are import examples for some but not all, ie [Terraform Registry ]
@bentterp, the above link isn’t working for me, was there another good one?