Consul provides a self-managed key/value store that Terraform can use as a backend for state. It also includes a service mesh, though that capability is unnecessary for this use. Consul can run locally for backend testing. section 6.4.3
Run Consul locally for Terraform state
Launch a Consul container with Docker Compose, then configure a terraform block with backend "consul". Set address to localhost:8500, choose a state path, and provide the Consul access token. Terraform can also receive these values through -backend-config during terraform init, keeping sensitive or environment-specific settings outside the main configuration. section 6.4.3
Listing 6.8 Terraform backend block with Consul
terraform { #1
backend "consul" { #2
address = "localhost:8500" #3
scheme = "http" #4
path = "path/to/save/state"
access_token = "01a56e2d-a96a-4ca5-9d39-d5152015f533" #5
}
}
Inspect the complete Terraform Consul backend configuration, including address, HTTP scheme, state path, and access token. section 6.4.3
