Search code examples
terraform

Terraform - Best practice which files to add to Git?


After creating main.tf and executing terraform apply

The following files are created:

  • terraform.tfstate
  • .terraform/

Should I add these files to Git?


Solution

  • You should add .terraform to your .gitignore file and never commit it.

    terraform.tfstate, on the other hand, is something you'd want to preserve. The best way to do this is to use a remote backend, such as S3. Committing this to source control is a bad practice, but would still work and is definitely better than losing the state file.