Terraform Folder Files and Project Layout

Which files belong in version control and which are created at runtime. A practical file checklist.

Files you often keep in source control

A typical Terraform project folder contains a small set of .tf files that describe your infrastructure. These files are the main deliverable and should be committed.

  • main.tf — core resource definitions
  • variables.tf — input variable declarations
  • outputs.tf — output value declarations
  • versions.tfterraform block with required provider versions
  • terraform.tfvars — variable values for a specific environment (sometimes excluded if it contains secrets)
  • .terraform.lock.hcl — provider version lock file, always commit this

Files created during local work

When you run terraform init and terraform apply, Terraform creates several local files and folders. Most of these should not go into version control.

.terraform/
terraform.tfstate
terraform.tfstate.backup
*.tfplan
crash.log

The .terraform/ folder holds provider binaries. It can be large and is fully reconstructed by terraform init. The state files record what Terraform has actually created and may include sensitive values.

Never commit terraform.tfstate in a team project. Use a remote backend such as an S3 bucket with state locking to share state safely.

A safe starter rule

Add a .gitignore file to every new Terraform project before the first commit. Start with these entries:

.terraform/
terraform.tfstate
terraform.tfstate.backup
*.tfplan
crash.log

Then commit everything else. Later you can decide whether tfvars files with real values stay outside version control too.