State backend

Spotlight keeps the Terraform state of a workspace's configuration, through Terraform's built-in http backend. Each workspace has states by name. See Keep Terraform state in Spotlight.

RequestAddressPermission
GET/api/terraform/workspaces/{slug}/states/{name}plan
POST/api/terraform/workspaces/{slug}/states/{name}configure
POST/api/terraform/workspaces/{slug}/states/{name}/lockplan
DELETE with lock info/api/terraform/workspaces/{slug}/states/{name}/lockplan for the token or person that took the lock, else configure
DELETE without a body/api/terraform/workspaces/{slug}/states/{name}/lockconfigure

{slug} is the workspace's slug. {name} is lowercase words joined by dashes, at most 64 characters.

Example

terraform {
  backend "http" {
    address        = "https://app.usespotlight.ai/api/terraform/workspaces/acme/states/default"
    lock_address   = "https://app.usespotlight.ai/api/terraform/workspaces/acme/states/default/lock"
    unlock_address = "https://app.usespotlight.ai/api/terraform/workspaces/acme/states/default/lock"
    lock_method    = "POST"
    unlock_method  = "DELETE"
    username       = "spotlight"
  }
}

Sign-in

The backend sends the token as the password of HTTP basic authentication. Spotlight ignores the username, but Terraform sends the password only when a username is set. Set the password in TF_HTTP_PASSWORD, not in the configuration. The routes also take Authorization: Bearer <token>.

TokenSource
A workspace tokenSPOTLIGHT_API_TOKEN, or the token itself
A token issued through an OIDC trustspotlight token with SPOTLIGHT_OIDC_TRUST
A loginspotlight token after spotlight login

A person has the permissions of their role: a member has plan, an owner or admin has plan and configure. A token has the permissions of its scopes.

Answers

RequestStatusWhen
GET200The latest version of the state, as JSON.
GET204No state was written under the name.
POST200The state is kept as a new version.
POST lock200The lock is taken, or the same lock ID holds it already.
DELETE lock200The lock is released, or nothing held it.
any423Another lock ID holds the lock. The body is that lock's info, which Terraform prints.
POST400The Content-MD5 header does not match the body.
any401No token, or a token that is unknown, expired or revoked.
any403The token or role lacks the permission.
any404No such workspace, or the token or person is not in it.
any409Another request changed the state at the same time, or a POST names a lock that was released. Run the command again.
POST409The state has another lineage than the latest version, a lower serial, or the same serial with other content. The message says which.
any422A state name that is not lowercase words joined by dashes, lock info without an ID, or a body that is not a Terraform state with a serial and a lineage.

A POST to a locked state must name the lock in ?ID=<lock id>, as Terraform does. After the first version, a POST must keep the lineage of the latest version and a serial at least as high. The same serial is taken again only with the same content, as when Terraform retries a write. A DELETE without a body is what terraform force-unlock sends, and releases the lock whoever holds it.

Storage

Each POST keeps a new version. Spotlight records the version's number, the state's serial and lineage, its size and MD5, and who wrote it, and keeps the body in the deployment's object storage. GET answers the latest version. Each state keeps its latest 100 versions: after a write, older versions and their bodies are deleted. Deleting the workspace deletes its states and every version.

The body is at most 64 MB.

Audit

These are recorded as configuration changes of the kind terraform-state, keyed by the state name:

ChangeActiondetails
The first version writtencreatedversion, serial, lineage
A later version writtenupdatedversion, serial, lineage
The lock released without lock info, as terraform force-unlock doesupdatedreleased: "forced", lock, heldBy, operation
The lock released by a token or person that did not take itupdatedreleased: "held-by-another", lock, heldBy, operation

lock is the lock ID, heldBy the token or person that took the lock, as token:<id> or person:<id>, and operation Terraform's operation, such as OperationTypeApply. A lock taken and released by the same token or person is not recorded.

On this page