I have a use case in which we need to create local variables that depend heavily on Terraform functions for each environment. We would like to place these local variables within the environment folders and consume them from the root folder where we have the main.tf file that creates certain resources based on these local variables. However, so far, we have not found a way to achieve this as all .tf files need to be located in the same folder.
It is not possible to change these local variables to tfvars as the generation of the values requires the use of functions and loops. Moreover, these values change per environment, which is why we can’t put them in the root folder.
We want to avoid copying and pasting the main.tf file located in the root folder to the environment folder because we want to avoid environment drift.
The structure that we need is:
/-
| main.tf
|variables.tf
|/environment
----/dev
-------| - locals.tf
-------| - terraform.tfvars
----/pre
-------| - locals.tf
-------| - terraform.tfvars
----/pro
-------| - locals.tf
-------| - terraform.tfvars
Is there a way that Terraform can support it? Thank you in advance