Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple .tf files in a folder

Tags:

terraform

I have a project that I inherited that has multiple .tf (main.tf, xyz.tf, ...) files in certain folders. When it does a source = "../<folder_name>" , what order are the files applied in? Is main.tf always applied first followed by the rest?

Note: These are different from the variables.tf and outputs.tf files.

like image 442
gamer Avatar asked Mar 29 '26 21:03

gamer


1 Answers

In Terraform 0.11, regular *.tf files were loaded in alphabetical order and then override files were applied.

When invoking any command that loads the Terraform configuration, Terraform loads all configuration files within the directory specified in alphabetical order.

...

Override files are the exception, as they're loaded after all non-override files, in alphabetical order.

In Terraform 0.12+ (including 1.x), the load order of *.tf files is no longer specified. Behind the scenes Terraform reads all of the files in a directory and then determines a resource ordering that makes sense regardless of the order the files were actually read.

Terraform evaluates all of the configuration files in a module, effectively treating the entire module as a single document. Separating various blocks into different files is purely for the convenience of readers and maintainers, and has no effect on the module's behavior.

like image 66
supersam654 Avatar answered Apr 02 '26 23:04

supersam654



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!