This project is a CloudFlare Worker that stores the state of a Terraform workspace in a KV namespace.
terraform {
backend "http" {
address = "https://worker.example.com/api/v1/example"
}
}
The following environment variables are required:
- USERNAME: The username to authenticate with
- PASSWORD: The password to authenticate with (
wrangler secret put PASSWORD
) - NAMESPACE_ID: The ID of the KV namespace to use (needs to be bound to the worker) wrangler.toml
npm install
wrangler publish
All endpoints require basic authentication with the configured username and password.
Returns the state of the project as JSON.
curl -X GET https://worker.example.com/api/v1/example -u username:password
HTTP/1.1 404 Not Found
Content-Type: application/json;charset=UTF-8
Content-Length: 0
Cache-Control: no-store
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Content-Length: 123
{"version": 4, "terraform_version": "0.12.24", "serial": 4, "lineage": "e2b0f0e0-7f1a-4c4a-8b1a-2b1a0b1a0b1a", "outputs": {}, "resources": []}
Updates the state of the project with the JSON body.
curl -X POST https://worker.example.com/api/v1/example -u username:password -H "Content-Type: application/json" -d '{"version": 4, "terraform_version": "0.12.24", "serial": 4, "lineage": "e2b0f0e0-7f1a-4c4a-8b1a-2b1a0b1a0b1a", "outputs": {}, "resources": []}'
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Content-Length: 123
{"version": 4, "terraform_version": "0.12.24", "serial": 4, "lineage": "e2b0f0e0-7f1a-4c4a-8b1a-2b1a0b1a0b1a", "outputs": {}, "resources": []}
Locks the statefile.
curl -X LOCK https://worker.example.com/api/v1/example -u username:password
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
HTTP/1.1 423 Locked
Content-Type: application/json
Cache-Control: no-store
{"id": "e2b0f0e0-7f1a-4c4a-8b1a-2b1a0b1a0b1a", "operation": "lock", "who": "username", "created": "2020-05-01T00:00:00Z"}
Unlocks the statefile.
HTTP/1.1 200 OK
Cache-Control: no-store
Deletes the statefile.
HTTP/1.1 200 OK
Cache-Control: no-store
This project is licensed under the GPL-3.0 License - see the LICENSE file for details.