1. Backend Config:

  • Backends determine where Terraform State is stored
    • must run terraform init to restart
    • terraform init -migrate-state to migrate where state is stored
  • Stored as a backend block within terraform block
  • Responsible for State locking
    • not all backends support state locking
  • Available backends:
    • Cant load additional backends as plugins
  • Using backend block:
    • This tells Terraform where to store as backend
    • A config can only have 1 backend block
    • cant refer to named value
    • when using Terraform Cloud, it doesnt need to have backend block
  • Can set backend to refer to an existing Terraform State file
  • Can set backend dynamically with terraform init —backend-config
  • Workspace prefix
    • workspaces { prefix = “application-” }
    • terraform workspace new prod
    • creates a new workspace application-prod

2. Available backends:

  • Local
    •   terraform {
          backend "local" {
            path = "terraform/state/terraform.tfstate"
          }
        }
  • Remote
    •     terraform {
        	  backend "remote" {
        		organization = "example_corp"
        	
        		workspaces {
        		  name = "my-app-prod"
        		}
        	  }
        	}
  • azurerm
  • consul
  • cos
  • gcs
  • http
  • Kubernetes
  • s3