opentofu / opentofu

OpenTofu lets you declaratively manage your cloud infrastructure.
https://opentofu.org
Mozilla Public License 2.0
21.71k stars 800 forks source link

Add include statement to use external .tf file in the root module #1767

Open paulaustin-automutatio opened 4 days ago

paulaustin-automutatio commented 4 days ago

OpenTofu Version

OpenTofu v1.7.2
on windows_amd64

Use Cases

Modules are good when you want to group resources into components. However they don't provide a good way to re-use fragments of code between modules.

Terragrunt can be used to do this, but it is cumbersome to work with. Although it's motto is DRY (Don't repeat yourself), I found it needed a lot of boilerplate code which was hard to maintain.

What would be useful if there was a way to import a file into the scope of the current module.

Consider the following scenario

Env
  ComponentTypeA
    Instance1
    Instance2
  ComponentTypeA
    Instance1
    Instance2
  Shared
    provider.tf

The deployment units are the Instance* modules. All of these need to use the same providers which define which environment to deploy to.

It would be useful to be able to either include the whole of the Shared folder in the current context or specify a single file to include.

Attempted Solutions

Terragrunt

Proposal

Add a new include block to include a whole folder or single file.

Or adapt the module block to have a flag that indicates that the module should be included in the current scope rather than a nested scope.

References

No response

paulaustin-automutatio commented 4 days ago

One other thought would be to be able to include .tfvars(and json) variable files