.tf

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.

Category
Code and data
MIME type
Type
Plain text
Also seen as
.tfvars
Is a .tf file safe to open? Caution. The file itself is declarative text, but applying it creates, changes or destroys real (often billed) infrastructure. Always review terraform plan output before apply.

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.

How to open 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. For a step-by-step walkthrough, see how to open a .tf file.

Windows

  • VS Code (HashiCorp Terraform)
  • any text editor

macOS

  • VS Code (HashiCorp Terraform)
  • any text editor

Linux

  • VS Code (HashiCorp Terraform)
  • any text editor

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.

.tf file signature (magic bytes)

Programs recognise a .tf file by the bytes at the start of the file, not by its name. These are the signatures for Terraform.

Hex signatureOffsetNote
(no fixed signature)0plain text; no fixed magic bytes

See the full magic-numbers reference for every format.

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: