-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
provider/template: Add a 'dir' resource to template entire directories #13652
Conversation
Hi @Quentin-M! Thanks for submitting this. This is an interesting idea. Again I don't have time today to dig in fully but I'll mark myself as reviewer on it to remind me to look soon. One bit of initial feedback is on the name itself. Elsewhere in Terraform we've tended to use the term "dir" to talk about directories, vs. "folder". So perhaps we could call this I assume you based this on the |
Hey @apparentlymart, Thank you for the extremely prompt answer!
|
I'd like to follow-up on this PR. Would this provider be of interest for the HashiCorp project and its community? |
Hi again @Quentin-M. Sorry for the delay here... I'm taking a deeper look at this now. |
When TerraForm is used to configure and deploy infrastructure applications that require dozens templated files, such as Kubernetes, it becomes extremely burdensome to template them individually: each of them requires a data source block as well as an upload/export (file provisioner, AWS S3, ...). Instead, this commit introduces a mean to template an entire folder of files (recursively), that can then be treated as a whole by any provider or provisioner that support directory inputs (such as the file provisioner, the archive provider, ...). This does not intend to make TerraForm a full-fledged templating system as the templating grammar and capabilities are left unchanged. This only aims at improving the user-experience of the existing templating provider by significantly reducing the overhead when several files are to be generated - without forcing the users to rely on external tools when these templates stay simple and that their generation in TerraForm is justified.
When an error is passed, the FileInfo can be nil, which was previously causing a crash on trying to evaluate f.IsDir(). By checking for an error first we avoid this crash.
Previously we were letting it get implicitly created as part of making the structure for copying in each file, but that isn't sufficient if the source directory is empty. By explicitly creating the directory first we ensure that it will complete successfully even in the case of an empty directory.
@apparentlymart Oh wow, thank you so much for your changes! I'd be happy to help in any way I can! |
Hi @Quentin-M! I just took care of a couple edge cases I found during testing. Seemed more efficient to just tweak in place rather than having another round-trip of change/review! I've just merged it with the little tweaks you saw and some elaborated documentation. Thanks again! |
Thanks again for your prompt help on both providers, and for your hard work on TerraForm itself of course! Truly appreciate it! Slick open-source experience. 💯 I wish you to have a great week. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
When TerraForm is used to configure and deploy infrastructure
applications that require dozens templated files, such as Kubernetes, it
becomes extremely burdensome to template them individually: each of them
requires a data source block as well as an upload/export (file
provisioner, AWS S3, ...).
Instead, this commit introduces a mean to template an entire folder of
files (recursively), that can then be treated as a whole by any provider
or provisioner that support directory inputs (such as the
file provisioner, the archive provider, ...).
This does not intend to make TerraForm a full-fledged templating system
as the templating grammar and capabilities are left unchanged. This only
aims at improving the user-experience of the existing templating
provider by significantly reducing the overhead when several files are
to be generated - without forcing the users to rely on external tools
when these templates stay simple and that their generation in TerraForm
is justified.
/cc @sym3tri @philips @apparentlymart