The terraform.tfvars contains personal settings and should not be included in the repository.
For default values, we can use the default field when declaring the variable instead of putting them in terraform.tfvars
Next we add terraform.tfvars to gitignore (and delete the committed version) so we keep a clean status (git status should be clean most of the time) and avoid accidentally adding it back.
We can provide a terraform.example.tfvars which is a file that will not be loaded automatically and we put examples there. That is not so important as the variables file has nice descriptions, but can be added if you think its a nice touch.
TL;DR
variable.tf
terraform.tfvars
(and commit deletion)/terraform/terraform.tfvars
to.gitignore
terraform.example.tfvars
Explanation
The
terraform.tfvars
contains personal settings and should not be included in the repository.For default values, we can use the
default
field when declaring the variable instead of putting them interraform.tfvars
Next we add
terraform.tfvars
to gitignore (and delete the committed version) so we keep a clean status (git status
should be clean most of the time) and avoid accidentally adding it back.We can provide a
terraform.example.tfvars
which is a file that will not be loaded automatically and we put examples there. That is not so important as the variables file has nice descriptions, but can be added if you think its a nice touch.