Here's why you shouldn't store your terraform state files in your version control repository like git:
- At times, if your colleague is working on the same terraform files you both may end up overwriting each others changes on the .tfstate files. On the other hand you may forget to commit your changes after working on terraform which in turn will result in your colleagues having an out dated .tfstate file.
- Another reason for not storing .tfstate files on git is that these files are not encrypted at all. There may be some instance when you have to use passwords while integrating with terraform. Terraform stores these in plain text in the .tfstate files.
Update:
Terraform has updated their documentation:
Terraform also puts some state into the terraform.tfstate file by default. This state file is extremely important; it maps various resource metadata to actual resource IDs so that Terraform knows what it is managing. This file must be saved and distributed to anyone who might run Terraform. It is generally recommended to setup remote state when working with Terraform. This will mean that any potential secrets stored in the state file, will not be checked into version control