-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[RFC] Imports: soliciting feedback from community #1025
Conversation
…mplement a few easy to understand functions that are in the context of the child?
- `path_relative_to_import` and `path_relative_from_import`: These are the equivalent functions of the ones named | ||
for `include`. | ||
- `find_in_parent_folders_from_importing_config`: This function is the version of `find_in_parent_folders` that | ||
works in the context of the config that is importing the current config. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use case that would benefit heavily from this: #744 (comment)
Thanks for the great write-up Yori. I love going through all the concrete use cases to make sure it's solving the right problems 👍 Of the "reuse" options on the table—that is, the existing It seems like with that approach, most of the code reuse issues go away. Everything in one environment is in one file (or, more likely, one set of |
Yes, very good write up and summary. Im really looking forward to having any of these solutions come to life as the current state is a bit annoying with the limitations in reusability. |
Thanks for the feedback so far!
Ah I was thinking of that as orthogonal, but you bring up a good point that it is related. When I get back to more thinking on this, I'll update with a section discussing this alternative.
Given that Given the above two and the feedback I've received, next steps on this RFC are for me to:
|
I agree with @brikis98 for what it's worth.. Flattening the structure and allowing locals to be used between modules would solve most problems I'm experiencing, though I guess there could be more complicated setups that might still need some nested, fancy shared variable hierarchy that your proposal seems to cover. |
UPDATE:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating the RFC with details from that new proposal! I left a few thoughts/comments.
See also #759 (comment) for a thought I had...
To understand this, consider a use case where you are operating in two regions, `us-east-1` and `eu-west-1`. To simplify | ||
this example, consider a limited application deployment where you have two modules: `vpc` and `app`. | ||
|
||
If we assume that `locals` are scoped within the file that they are defined, then you can implement this by separating |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would locals be scoped to a file? The idea with the new proposal is that all .hcl
files in a single folder are processed as if they are in a single file, just as Terraform processes all .tf
files in a single folder as if they are in a single file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is an advantage to having vars scoped to the file so that you don't have to keep picking new names for a thing like region
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but I think in net, treating all .hcl
files in a folder as if they were in one .hcl
file, just as Terraform does with .tf
files, is the better trade-off.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update to note that it is preferred to have scope of locals shared, but mention the possibility of having file scoped vars, its advantages and disadvantages.
``` | ||
|
||
However, if the namespace of `locals` was shared across the environment, then the above approach would not work and each | ||
region file will need to define a different name for the region variable. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, if you're deploying the same things across regions, you'd use a different local for each region.
|
||
Reusing common variables depends on the scope of `locals`. If the scope of `locals` is shared across the environment, | ||
then you can define the common variable in `locals` blocks to share across the entier environment. If instead the scope | ||
of `locals` is per file, we either: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure locals
and everything should be shared across all .hcl
files in a folder, just like how Terraform does it for .tf
files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above for why one would want variables that are scoped to the file. E.g function scope vs global scope to avoid namespace clashes.
Looking at the suggestions, I'd be inclined to agree that Our workaround for the for the differing inputs between configurations is to simply have two separate "top level" .hcl files that we @brikis98 Flattening the structure as you proposed in #759 seems counter-intuitive to our use-case as I described in #759 (comment) |
Hm, I guess I can agree there is still possibly a need for imports even with a flattened structure, after seeing some examples.. Orthogonal enough to warrant implementing both, at least. I think |
Thanks for the feedback everyone! I think based on the feedback and new thoughts around #759, it sounds to me like #759 is where we want to be heading. However, given how big of a change that really is, I am not sure that will get done anytime soon and, as @tomasbackman mentioned, there is a pressing need to solve this problem sooner rather than later. Given that, I propose that we should take an incremental approach here, implementing the features that are low cost and partially solve the problem, and slowly work towards more complete solutions. I think:
I'm going to start implementing EDIT: PR for |
Yea, the more I think about it, the more I believe the direction described in #759 (comment) is the way to go: turn Terragrunt into a preprocessor for more or less pure Terraform code. So many of the features we've built into Terragrunt already exist in Terraform (e.g., locals, helper functions, dependencies, etc), so many others become unnecessary with pure Terraform code (e.g., code generation of But yes, it'll take some time to do that, so +1 on putting in some reasonable stop gap solutions for now. |
UPDATE: I have updated the RFC to indicate that:
|
@brikis98 any objections to merging this in now? |
No objection, go for it! Thx Yori! |
Thanks for sanity check! Going to merge it in now. |
@yorinasub17 is there a PR open for the |
Unfortunately, not yet. |
@yorinasub17 Any news on |
@yorinasub17 is there any way we can reference a hcl file from another git repo either with |
We currently don't have plans to implement remote references for import, but a PR to add support for that is welcome. |
The I am not quite sure yet about #759. I would prefer to keep using the hierarchical folders. If you do get to implement #759 at some point, please make sure we can still do hierarchical folders. Mixing it all up in one single file should be optional. As mentioned by @arash-bizcover , a remote import would be a great addition. We have repeated top level For example, consider something like this:
In this case |
It's not one file, it's as many as you want. You just dont need a subfolder per module. Please read the whole proposal because most people, including myself, have propogated this misinformation |
How would you implement the following if the functions are deprecated |
I seem to recall a conversation in one of the issues regarding As for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has there been any progress on this RFC? |
This is an RFC that introduces
import
blocks for addressing limitations of configuration reuse withinclude
.I would like feedback from the entire community on this, as this has the potential to address a lot of limitations that were proposed throughout the lifetime of terragrunt, but is fairly opinionated in the design principle.
NOTE: It may be easier to read in the rendered form. Here is the direct link.