Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (29.3k points)

I am a little bit puzzled on the question of whether to commit .tfstate files to Git or not. The Terraform documentation states:

Terraform also put 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. We recommend simply putting it into version control since it generally isn't too large.

Now, on the other hand, the accepted and upvoted answer on Best practices when using Terraformstates:

Terraform config can be used to provision many boxes on different infrastructure, each of which could have a different state. As it can also be run by multiple people this state should be in a centralized location (like S3) but not git.

(Emphasis by the original author, not by me)

Who is right, and if so, why?

closed

1 Answer

0 votes
by (50.2k points)
selected by
 
Best answer

In the recent updates of documentation of Terraform states that

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 set up a remote state when working with Terraform.  This state is stored by default in a local file named "terraform.tfstate", but it can also be stored remotely, which works better in a team environment.

The above quote of official docs says that remote state is still beneficial as a solo developer

It allows the solo user to run terraform code for several devices and can have an easy backup and also segregates sections of their architecture.

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.1k users

Browse Categories

...