Best practice for defining values tor modules (vars vs locals)

Hi, I wanted to get some feedback on 2 possible ways to define variables for a module.
Hopefully the description is clear.

Case 1 seems cleaner, or at least more properly defined? However, every module variable needs to be defined twice (in main and in module).

Case 2 has less definitions, and feels less bloated. I want to avoid though definitions that are hacky or not clean.

Same between both Cases

Module_A.variables.tf (var a1, var a2)
Module_B.variables.tf (var b1)

Case 1

main variables.tf (var a1, var a2, var b1).
main terraformv.tfars (a1=…, a2=…)
main.tf - Module_A.a1=var.a1. etc

Case 2

main variables.tf (locals{ a1=…, a2=…, b1=…}
main.tf - Module_A.a1=local.a1. etc

I’m very new to TF, so I’m open to hear different opinions, or downsides to either implementation.

Thanks!

Use locals when the target audience for customizing the values is people working on the Terraform configuration code in a text editor.

Use variables when the target audience for customizing the values is a source outside of the Terraform itself - for example, if you want to use the same Terraform configuration code in multiple different Terraform Cloud workspaces, with different variable values.

1 Like