-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
Feature request: Import resource into .tfstate AND create a HCL resource definition in .tf file #15608
Comments
This would be a very useful feature to be a part of terraform. To do something like currently, I use import and the . https://github.com/dtan4/terraforming to kind of achieve something similar. However, not all resources are supported as part of terraforming, and you have to sift through all the resources of a particular type and pull out the one you want/ |
Thanks for requesting this, @Nowaker. As you can see in the docs, this is definitely something we intend to implement. You're right that the basic mechanism here is rather straightforward, but there are some details that need to be addressed such as representation of dependencies (so e.g. Terraform can be told that an imported AWS VPC subnet depends on its associated AWS VPC, which must currently be hand-written in config) and some other user experience improvements around the specification of resources that don't have a "natural" identifier to use, such as We've been looking at all this under the heading "import improvements", and do intend to make these improvements but want to take the time to make sure it's designed and implemented robustly. We'll have more to share on this once we've completed some design work and prototyping. |
Hey @apparentlymart - thanks for your reply. Absolutely - things get challenging when you need to represent the dependencies. I'll look into this as well. I guess for time being some Ruby scripting for mass imports and HCL generation would do wonders - I'll post my results here. Thanks! |
Here's a naive script that imports a resource and generates an HCL file: https://gitlab.com/Nowaker/terraform-import-as-hcl. It's not perfect but still better than nothing. |
I would add a +1 to this, but there are already countless issues open on the same subject and apparently it's been in discussion since 2015. At the moment I'm struggling with importing an AWS resource: the default route table for a VPC. That resource has an AWS id, and I can't find any documentation on how to write HCL for it. I can try to replicate its attributes, but then the original will be deleted and a new one will be created. |
+1 for this feature, would be very useful! |
+1 to have this feature |
+1 for this feature |
2 similar comments
+1 for this feature |
+1 for this feature |
+1 |
1 similar comment
+1 |
+1 |
+1 would also like to see this for other providers like vSphere |
I'm going to lock this issue for now because it's attracting voting noise, which is disruptive for the people watching the issue. We'll unlock it again when we're ready to start working on this. Thanks for the interest, everyone! |
terraform import
is used for importing a resource into Terraform state, as pertf import --help
:I'd like to request an extension of
import
functionality. Two things would happen:*.tfstate
file. (Already implemented)*.tf
file with a resource definition in HCL. (Feature request)As far as I can see, (2) is trivial. All data that a HCL resource definition requires is already in the state - inside
primary.attributes
hash. Everything is super clear - 1 to 1. Example:And no changes detected:
The text was updated successfully, but these errors were encountered: