liveBook · Manning

Local backend

As explained in Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu

A local backend is a Terraform backend that stores state files directly on the local filesystem.

A local backend stores a Terraform workspace’s state files directly on the computer running Terraform. It is the default when no other backend is configured, making it convenient for testing and local development but unsuitable for shared production work. section 1.2.5 section 2.3.1

Initializing with local state

Run terraform init in a new Terraform project. Terraform initializes the default local backend before installing providers and modules, leaving state management on the local system. section 1.4.2

Listing 1.1 Initializing a Terraform project
$ terraform init                                                 #1
 
Initializing the backend...                                      #2
 
Initializing provider plugins...                                 #3
- Finding HashiCorp/aws versions matching "~> 4.0"...            #4
- Installing HashiCorp/aws v4.41.0...                            #5
- Installed HashiCorp/aws v4.41.0 (signed by HashiCorp)          #6
 
Terraform has created a lock file .terraform.lock.hcl to record the provider
selections it made above. Include this file in your version control 
repository so that Terraform can guarantee to make the same selections by 
default when you run "terraform init" in the future.
 
Terraform has been successfully initialized!
 
You may now begin working with Terraform. Try running "terraform plan" to 
see any changes that are required for your infrastructure. All Terraform 
commands should now work.
 
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, 
other commands will detect it and remind you to do so if necessary.

The initialization listing shows the local backend step alongside provider installation and lock-file creation. section 1.4.2

Use the local backend when its operational limits are acceptable:

  • It is easy to start with because no remote state service or additional backend configuration is required. section 1.2.5 section 6.4
  • It does not scale to teams because the workspace can be acted on only from the computer holding the state. section 1.2.5
  • It is not resilient or necessarily secure: hardware failure can remove the state, and access depends on the machine’s protections. section 6.4
  • Use another backend for production environments, reviewing its requirements for availability, security, and state locking. section 2.3.1 section 6.4

How Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu covers it

How deep it goes
Explains default storage, initialization, and operational limitations without detailing backend-specific configuration or state internals.
Examples
Uses terraform init, a local tfstate file, provider installation output, and the .terraform.lock.hcl file.
What it assumes
Assumes basic Terraform project usage while establishing backends, workspaces, state files, and initialization from common development practice.
What you can do after
Operate/configure Terraform locally with default state storage and recognize when production requires another backend.
How it connects
Connects Terraform state, workspaces, terraform init, remote backends, and state locking.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Terraform in Depth: Infrastructure as Code with Terraform and OpenTofu. The section links point to the parts of the book it draws on.