What is a .tf file?
Terraform Configuration File · Code and data · HashiCorp · 2014
A .tf file is Terraform configuration: infrastructure-as-code that declares cloud resources (servers, networks, databases) which Terraform then creates and keeps in sync. It is written in HCL, plain text.
What is a .tf file used for?
Terraform reads every .tf file in a directory and builds a plan: what must be created, changed or destroyed to make reality match the declared state. Variables live in .tfvars files, and the resulting resource state in terraform.tfstate.
The declarative model is the point: you describe the end state, not the steps. That state file is sensitive, it can contain secrets, so .tf files are committed while .tfstate usually is not.
What opens a .tf file?
The .tf format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list.
Windows
- VS Code (HashiCorp Terraform)
- any text editor
macOS
- VS Code (HashiCorp Terraform)
- any text editor
Linux
- VS Code (HashiCorp Terraform)
- any text editor
Open a .tf file step by step
- Confirm the file really is a .tf. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
- On Windows, open it with VS Code (HashiCorp Terraform) or any text editor.
- On Mac, use VS Code (HashiCorp Terraform) or any text editor.
- On Linux, try VS Code (HashiCorp Terraform) or any text editor.
- Still stuck? Convert the .tf to json (HCL JSON syntax), which opens more widely.
Why can't I open my .tf file?
Almost always because no installed app understands Terraform. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.
The other possibility is that the file is not really a .tf at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.
How to convert a .tf file
You can convert a .tf file to json (HCL JSON syntax) using a conversion tool or the export menu of an app that opens it.
Terraform has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.
Frequently asked questions
What is a .tf file?
A .tf file is Terraform configuration: infrastructure-as-code that declares cloud resources (servers, networks, databases) which Terraform then creates and keeps in sync. It is written in HCL, plain text.
How do I open a .tf file?
Any text editor; VS Code with the official HashiCorp Terraform extension adds validation and completion. Running it requires the terraform CLI (or OpenTofu).
What is the difference between .tf and .tfvars?
.tf files declare the resources and variables; .tfvars files supply the concrete values for those variables per environment, like region or instance size.
What is OpenTofu?
An open-source fork of Terraform created after HashiCorp's 2023 license change. It reads the same .tf configuration files.
Related formats
Sources
Details on this page were checked against authoritative references. How sources are ranked and what is deliberately left out is set out in the methodology.