Terraform: Feature Proposal: Subfolder support that is backward compatible

Created on 27 Jul 2016  ·  10Comments  ·  Source: hashicorp/terraform

We have a big infrastructure. We want to split it up by folders, but Terraform currently doesn't support this. So having thought about it, how about a new structure for importing folders:

Given folder structure of:

./main.tf
./core/aws.tf
./core/vpc.tf
./ec2/bastion.tf
./ebs/app1.tf
./ebs/app2.tf
./rds/app1.tf
./rds/app2.tf

and a ./main.tf file of:

import { path = './core' }
import { path = './ec2' }
import { path = './ebs' }
import { path = './rds' }

With this proposal, it doesn't change current behaviour incase people have nested terraform configs they don't want loaded, and under the hood, all the import directive would need to do is load all files in that directory.

Though not necessary, you could add glob support as well. import { path = './apps/*/app.tf' }

And files it imports could also import things:

./main.tf: import { path = './core' }
./core/main.tf: import { path = './misc' }
./core/misc/main.tf: resource { .... }

Please give this consideration, as it would greatly increase the organisation of larger Terraform backed infrastructures.

enhancement question

All 10 comments

Should also point out that many articles point at modules to help with this. However, it creates extra work, as a module ends up isolating references, so suddenly, everything needs to have outputs and references need to be changed to module.core.aws_vpc or similar through the whole codebase rather than just aws_vpc. The approach above would be similar as if all imported scripts simply got appended to make one big script.

There is an "include" core enhancement request that I agreed with so I think we will eventually support something like this.

+1

Completely agree, modules are not very convenient when there is no actually need to re-use the code but rather include files from sub-directories purely from structure organization point of view.
+1

Hey @mitchellh , can you point to the "include" core enhancement issue, please? I would like to keep track on that. Thanks.

👍

+1

+1

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.

Was this page helpful?
0 / 5 - 0 ratings