Itβs a configuration where Terraform will store its state.
There are a number of available backends. The most important for me are:
local
is the default backend option.
Remote backends solve:
- Manual error. All team members and CIβs will have the latest state of the infrastructure.
- Locking. Avoids race conditions.
- Secrets. Most remote backends support encryption in transit and encryption at rest.
local
backend will store unencrypted sensitive values in plain text. - Versioning.
s3
backend has this support.
Configuration
backend
block in Terraform does not support variables.
Partial configuration with local file
Create a separate file, e.g. backend.hcl
:
In the Terraform code provide remaining parameters:
To put this all together, run:
Partial configuration with CLI parameters
Similar to the approach above. I configured it this way.
Makefile recipe:
Terragrunt
Can parameterize backend
block. But for what itβs worth, I would avoid it, as it adds additional layer of complexity and one more tool to manage.