-
Notifications
You must be signed in to change notification settings - Fork 12
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
Load terraformsh config from parent directory #19
base: main
Are you sure you want to change the base?
Conversation
Hi @Th0masL, I reopened a pull request with some of the changes you requested. I liked your proposal, but I'm just trying to find a way to formulate the code so the functionality is based on reusable functions, rather than one function that searches for files in two different ways. (Your suggestion is completely appropriate for most software projects; but since this is more of a pet project, I'm being annoying and trying to make the code better for its own sake 😉 ) ) Will make another attempt at it, but if I don't get far we can just go with your original suggestion. |
One problem to consider in looking for parent terraformsh configs is overloading/precedence. If there's a config in the current directory and a config in the parent directory, how do we load them?
It seems that the simplest/most reliable option is to only load one config. And it seems most logical to load the current dir's file as that is how the current behavior works, and generally you'd expect to load a config from the directory you're currently in with most tools. Similarly, it seems like loading the file "closest" to your current dir makes the most sense, if it isn't in your current dir. So that leaves situations when there's a config in a parent dir and a config in a child dir: do we assume we always want to load a parent dir's config, even if it might not relate to the current dir? And if there's a child dir, do we want to instead seek to that directory and run Terraform there? |
I think that it makes sense to only read Regarding where to stop the loading of files in the parents folders, I think it makes sense to either:
|
Just for example, in my current implementation, in my repo/branch, I'm exiting after the first match. See https://github.com/Th0masL/terraformsh/blob/main/terraformsh#L496 Full list of changes I added are visible in the custom version v0.12.1 |
I think either of those options could work, but I think this is one of those times where we have a lot of options but not really know which is the better choice because we haven't used them yet. Can you tell me more about your use case for this function? For myself, I use |
In my setup, I'm using a parent/child folder structure to breakdown Terraform stacks by folder, but I want a single Here is an overview of my folder structure:
What I do is Also, in my case, there are multiple people running One of the main goal of If you need a more clear example, I'm happy to share the content of my |
@Th0masL sure, if you could share the content that would be great! So what I've done in the past is in
Since To run this in CI/CD, I just check out the repo, then I also use symlinks to commonly-used configs to keep the configs DRY. (In the past I have experimented with functionality that auto-generates temporary config directories by overlaying multiple directories on top of one another, but some weird problems crop up because of that, and the current system ends up being much simpler while still working) |
Would still like to see your sample configs, but I'm leaning toward the terraformsh env var option that would tell it to look in parent directories for more configs to load. The value could be a number to indicate how far back to look. That way the user could either opt to do the Of course... if there is such an option, what happens when more than one config sets that option? Do we assume the second one is redundant? Or say that they both indicate how many parents to traverse; do we assume that the second instance of the variable increases the number of parents to traverse? Do we ignore it? Is it possible someone made a mistake by configuring that option in a parent file? With the So in order to use the |
I've been pretty busy recently so I couldn't spend too much time trying to implement a more complex way to parse parent folders, ans you suggested. I had a look at your suggestion, and that's true that the following approach would work fine for my use case:
So I'm going to use your suggested approach for the time being, and I might work on an improved semi-automated way to load files from parent folders in the future, but for the moment that's fine :) Thanks ! |
You can close this PR for now. Thanks ! |
No description provided.