Open bt-macole opened 1 year ago
Thanks for this request!
That feature would be super interesting
Thanks! I assume this request is only for existing infra. Isn't it? I hope we'll see that in the next few versions
This is actually for static use in modules. The two use cases happen at different levels of abstraction, but are complementary, and together, provide auto generated optional import statements in terraform modules.
For example:
This would mean a module developer could include the import blocks like dynamic blocks
providing optional imports that abstract resource names (id
) and import syntax, enabling users to easily import with whatever key
is needed. For resources that have a calculable key
before apply, this means the import could be flagged on with a bool and the module developer could use the already provided inputs to derive the key without a user needing to understand any extra implementation details, WYSIWYG.
key
is.The attributes required to achieve an import are defined at the provider level. Import blocks have a very common shape to them.
To accelerate development of modules and provide a further enhanced developer experience, developers should be able to run a scaffolding command that generates the import statements with the known id
(since resource names are statically typed + optional key indices) along with placeholders and/or comments that guide developers on what the key
is--or derive keys from the module automatically if known before apply.
This provides a more robust terraform module that can leverage the newest features of terraform to the fullest. And provides an even better user experience to module developers and their users.
Terraform Version
Use Cases
Attempted Solutions
Writing import blocks for a module on the consumer end and manually tracking down the correct resource names and import values.
Proposal
config-driven imports is great, the native use with traditional cicd via plan and apply is super powerful!
To make it more robust and support module development that takes full advantage of this feature import blocks should be dynamic and ideally auto generated.
It would be awesome if imports could be dynamic like other terraform blocks:
it would also be great if the import block(s) could be auto generated for resources in a module via cli, something like:
terraform generate imports
could generate import blocks for resources in a module with all the required import values using the correct resource names/paths.
References
No response