A state backend server that implements the Terraform HTTP backend API. This server does not handle authentication and should be used behind a reverse proxy (like nginx).
The server is rather an experiment in writing HTTP servers in C++. It is probably OK for hobby usage but not for mission-critical applications.
tl;dr: see Dockerfile.
- Install required dependencies: clang++ or g++, cmake, make.
- Install optional dependencies: libev, ada, nanodbc, llhttp, json, libretls.
- If you don't install the optional dependencies, the system will try to download and build them. In this case, it may need
git
,python3
,python3-whichcraft
(for Ada),unixodbc
(for nanodbc), andopenssl
(for LibreTLS). See Dockerfile for details. - Build:
cmake -B build -DCMAKE_BUILD_TYPE=MinSizeRel && cmake --build build
.
The following environment variables control the server:
TFHTTP_ADDRESS
: IP address the server will listen on. The default value is0.0.0.0
(listen on all IP addresses).TFHTTP_PORT
: port the server will listen on. The default value is3000
.TFHTTP_DSN
: the data source name to request a connection to an ODBC Data Source. By default, it isDriver={SQLite3};Database=:memory:
(an in-memory SQLite3 database that does not survive application restarts). You will need to have the corresponding ODBC connector installed.TFHTTP_HTTPS
: set to1
to enable HTTPS.TFHTTP_CERTIFICATE
: path to the TLS certificate.TFHTTP_PRIVATE_KEY
: path to the TLS certificate key.TFHTTP_CA_CERTIFICATE
: path to the CA certificate.TFHTTP_TRUSTED_CERTIFICATE
: path to the trusted certificate (used for OCSP stapling).TFHTTP_TLS_PROTOCOLS
: a comma- or colon-delimited list of the TLS protocols to use. The valid values aretlsv1.0
,tlsv1.1
,tlsv1.2
,tlsv1.3
,all
,default
,legacy
,secure
. Seetls_config_parse_protocols(3)
.TFHTTP_TLS_CIPHERS
: list of the allowed ciphers. The valid values aresecure
,default
,compat
,legacy
,insecure
,all
, or a libssl ciper string. Seetls_config_set_ciphers(3)
.TFHTTP_TLS_CURVES
: a comma-separated list of the elliptic curves used during ECDHE key exchange. Seetls_config_set_ecdhecurves(3)
.TFHTTP_TLS_VERIFY_CLIENT
: set to1
to enable client certificate verification, requiring the client to send a certificate.TFHTTP_TLS_ENABLE_DHE
: set to1
to enable DHE key exchange.
The server provides the following endpoints:
GET /:project/state
: fetch Terraform state for the givenproject
. The state will be created if it does not exist.POST /:project/state
: save Terraform state for the givenproject
.DELETE /:project/state
: delete Terraform state for the givenproject
.LOCK /:project
: lock state.UNLOCK /:project
: unlock state.
:project
is an alphanumeric string matching the [A-Za-z0-9_-]+
regular expression. This makes is possible to use this server for multiple Terraform projects.
terraform {
backend "http" {
address = "http://127.0.0.1:3000/myproject/state"
lock_address = "http://127.0.0.1:3000/myproject"
unlock_address = "http://127.0.0.1:3000/myproject"
}
}
(More details).