问题
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 ? I main.tf always applied first followed by the rest ?
Note: These are different from the variables.tf and outputs.tf
files.
回答1:
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 the newer Terraform 0.12, the load order of *.tf
files is no longer specified. Behind the scenes (in both versions), Terraform reads all of the files in a directory and then determines a resource ordering that makes sense ignoring the order the files were actually read.
Terraform automatically processes resources in the correct order based on relationships defined between them in configuration, and so you can organize resources into source files in whatever way makes sense for your infrastructure.
来源:https://stackoverflow.com/questions/59515702/multiple-tf-files-in-a-folder