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

**URL:** <https://discuss.hashicorp.com/t/best-practice-for-defining-values-tor-modules-vars-vs-locals/56568>\
**Category:** Terraform\
**Created:** [July 26, 2023, 8:23pm UTC](https://discuss.hashicorp.com/t/best-practice-for-defining-values-tor-modules-vars-vs-locals/56568 "2023-07-26T20:23:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![edank](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/edank/32/37052_2.png) [@edank](https://discuss.hashicorp.com/u/edank)\
**Post date:** [July 26, 2023, 8:23pm UTC](https://discuss.hashicorp.com/t/best-practice-for-defining-values-tor-modules-vars-vs-locals/56568/1 "2023-07-26T20:23:51Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![maxb](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/maxb/32/26655_2.png) [@maxb](https://discuss.hashicorp.com/u/maxb)\
**Post date:** [July 26, 2023, 10:03pm UTC](https://discuss.hashicorp.com/t/best-practice-for-defining-values-tor-modules-vars-vs-locals/56568/2 "2023-07-26T22:03:02Z")

</div>

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.
