Decouple the main.tf

Hi, I was wondering if there is a way to decouple the config file main.tf ? I have a pretty long configurations so I was looking for a way to split them into different parts (or maybe files) for better maintenance. But I couldn’t find any documentation about this.

Also, if there is a way to add a for loop to main.tf , like I have 1000 lambda functions, and name them as name-0 - name-999 . I’m filling the name manually 1 by 1 in the configurations, if there is a better way to fill their names with for loop?

main.tf is not a filename with special meaning to Terraform.

Terraform just loads all of the files named anything-at-all.tf in a directory, and treats them all the same.

(OK, the above isn’t totally true… there is a special case for files named override.tf or anything-at-all_override.tf. But apart from that one special case, Terraform doesn’t care what you name your .tf files.)

Have you read about count and for_each in the Terraform documentation?

If you give an example of 2 or 3 of your repeated definitions, so we can see in more detail what you’re dealing with, it would be easier to advise correctly.