-
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
allow terraform to choose which .tf files to include / ignore #13021
Comments
+1. But another idea is to check if some custom.include is present to drop default behaviour (which is include everything) and read inclusion rules form that file... |
@aholbreich I like your idea even better. |
Hi @FlorinAndrei! Thanks for this feature request. I'd love to hear a bit more about the problem you're trying to solve here, since you hinted a bit by saying "add/remove parts of the environment dynamically" but I'm not sure I understand fully what you mean by "dynamically" here, since usually we think of dynamic behavior as having Terraform adjust part of the configuration depending on the outcome of another part (which isn't known until apply time), but I don't think that's what you're trying to do here since your proposal wouldn't address that need as far as I can tell. Generally we try to encourage thinking of things at resource-level granularity rather than file-level granularity, since the decision for how to split things into files can be driven by lots of different motivations. For example, sometimes certain things are split into a separate file just because that part of the configuration happens to be generated by a pre-deploy script. We currently have the |
Let's say I have a bunch of modules for prefab components. Stuff like a "network" module (including VPC, subnets, NAT, routes...), EC2 cluster module, RDS module, etc. Modules are all stashed in a separate top directory tree in the repo, and are source'd in my asset-building Built upon this, I have various environment templates. Let's say there's a QA env. It has a Then there's Then there's Then there's For a clean test, I need to tear down then rebuild the QA env. But there's no reason to tear down networking (VPC, subnets, NAT, routes). So Currently I accomplish this via some awkward symlink create/delete in a
It would be a lot better if I could just leave all Managing an include template file is easy, from bash here documents to Ansible templates and so on. This is just an example, but really, the current aggressive "include all" policy seems rigid no matter what. Give some runtime leeway to the user, please. |
@apparentlymart i have simmilar setup as @FlorinAndrei |
Thanks for the additional context, @FlorinAndrei . Some common solutions to what you're doing here are:
For the moment I'd recommend addressing such use-cases using wrapper scripts that encode the appropriate set of There are some other issues open that should make this approach easier in future:
I believe that this, with the addition of the above fixes, should be able to address your needs, albeit in a different way than you imagined. We'd rather keep the current approach of thinking of things in a resource- and module-oriented way rather than a file-oriented way, since this gives more flexibility and allows Terraform to make better guarantees about properly handling dependencies. I'm going to close this since I think what you need here can be addressed with existing features combined with work represented in other open issues. However, I do appreciate you taking the time to describe your use-case in detail, and we'll keep it in mind as we build on these existing features in future to see if we can make things smoother while remaining consistent with the existing model of Terraform. Thanks! |
|
you could use : terraform destroy -auto-approve -target=aws_instance. |
I know this issue is closed but the idea was great. In my case I split my cluster configuration in several terraform files because I have things to deploy with packer/ansible before deploying the last part of my terraform configuration. At the moment, the only I found to do it is by moving my configuration in another folder to deploy my first part, deploy packer/ansible, and then bring my configuration in my folder to finish the terraform deployment. An option like |
We really need to have the capability to plan and apply individual terraform tf files rather than resource level. How to build individual environments using terrafom? |
If you see the documentation on their website, it speaks to how to use re-usable modules to handle different environments ...
References: My personal opinion is that workspaces (pretty much namespaces) seems more appropriate for this type of environment segmentation but, the documentation suggests otherwise. ¯\_(ツ)_/¯ |
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. |
By default, TF includes all
*.tf
files in the current directory. This is a bit rigid and makes it harder to add / remove parts of an environment dynamically.Please allow the user to more easily select which
*.tf
files to include at runtime. There are many ways one could think of to accomplish this. Just a random example: allow an optionalinclude_me
statement in the file, with a value of eithertrue
(default) orfalse
. Then the user could do things such as:Not sure if this is consistent with the current TF syntax, it's just an example.
The text was updated successfully, but these errors were encountered: