This is a informational article on how the variable precedence works in Terraform. This is how the priority is defined for variable when you use it in different ways. In the following diagram, it shows the information of variable priority matrix. Lower the number it has higher the priority and it will always override the sub variables you defined. This documentation will help you to troubleshoot, variable related inforamation.
I have here five different ways to pass variables in terraform. From bottom providing default value in variable block variable "name" { default = "dev"}. It is most basic and first variable information you provide in terraform as variable block. It has lowest priority and it will be superseded by Environment Variables, when you define variable $env: in windows PowerShell or export in Linux. Whatever the variable name is you need to prefix TF_VAR in front for the variable name. In my case it is $env:TF_VAR_name="dev4".
In the following priority matrix, variable defined inside file *.terraform.tfvars or *.terraform.tfvars.json (Just a note: json file has less priority than non json and will be superseded by normal tfvars file extension)
Next in the line matrix variables mentioned inside *.auto.tfvars file will always have higher priority and will override higher number variables as per the above diagram.
This is the last variable you can provide in -var as a parameters to terraform with key pair value. It will take over all the variables in the line and has highest supremacy.
Useful Articles
Terraform passing different credentials to different subscriptions with provider alias
Using terraform to clone a virtual machine on VMware vSphere infrastructure
Terraform module clone VMware vSphere Linux and Windows virtual machine
Terraform VMware vSphere Virtual Machine customization clone failed on Windows
Terraform VMware vSphere Virtual Machine cloning Operating system not found