Terraform state
Arbinel can store OpenTofu and Terraform state as an HTTP backend.
Each state is a package of the type Terraform State, and every upload adds a version named after the state’s serial.
A site administrator turns the backend on with [packages] ENABLE_TERRAFORM_STATE = true.
Configure the backend
Section titled “Configure the backend”Add an http backend to your configuration.
Replace <instance>, <owner> and <name> with the address of your Arbinel instance, the user or organization the state belongs to, and a name for the state.
Then sign in and initialize the backend:
The token needs the write:package scope.
The same configuration works with terraform instead of tofu.
A state name can contain letters, digits, -, _, . and +.
The paths and status codes are the same as in the Terraform state registry of Gitea, so a configuration written for Gitea works with Arbinel too.
Access
Section titled “Access”Every request needs write access to the owner’s packages, also to read a state. That is the owner itself, or a member of a team with write access to packages in the organization. In Forgejo, anyone who can read an owner’s packages can download them, which includes everyone for a public owner. A state often holds passwords and keys, so Arbinel does not let readers download it.
Readers still see that a state exists, its versions, who uploaded them and whether the state is locked. Only users with write access see who holds a lock. To keep the content unreadable to the server as well, use OpenTofu’s state encryption. Arbinel stores encrypted state unchanged.
Locking
Section titled “Locking”OpenTofu and Terraform lock the state before they change it.
While a state is locked, Arbinel refuses uploads that do not carry the lock’s ID, another lock, and deleting the state or any of its versions.
A refused request gets 423 Locked, with the current lock in the body, so the client can say who holds it.
The lock is stored in the database, so it holds across all nodes of a high availability setup. Arbinel checks the lock and stores the upload in one database transaction, so nobody can remove the lock halfway through an upload.
To remove a lock that a failed run left behind, use one of these:
- Run
tofu force-unlock <lock-id>. The client sends its request to remove the lock without a lock in the body, and Arbinel removes any lock. - Open the state’s latest version in the web interface and select Remove lock. The button shows for users with write access to the owner’s packages.
A request to remove the lock that carries a different lock’s ID is refused with 423 Locked.
Versions
Section titled “Versions”Every upload with a new serial adds a version.
The client always gets the latest upload, not the version with the highest serial.
Uploading the latest serial again with the same content changes nothing.
Uploading an older serial again with the same content makes it the latest version, which is what tofu state push -force with an older state needs.
Uploading a serial that exists with other content is refused with 409 Conflict.
These rules protect the state from deletion:
- No version can be deleted while the state is locked.
- The latest version cannot be deleted while older versions exist, because the state would silently roll back. Delete the older versions first.
- The only version can be deleted, which removes the state.
The rules apply in the web interface, in the package API at /api/v1/packages/{owner}/terraform/{name}/{version} and in the state API.
The package API answers a refused deletion with 422 Unprocessable Entity.
Deleting a user or an organization deletes its states without these checks.
Package cleanup rules cannot select Terraform states.
Endpoints
Section titled “Endpoints”All paths start with /api/packages/{owner}/terraform/state/{name}.
| Method | Path | Purpose |
|---|---|---|
GET |
Get the latest state. 404 Not Found means there is no state yet. |
|
POST |
?ID=<lock-id> |
Upload a state. The ID parameter is needed while the state is locked. |
DELETE |
Delete the state with all its versions. | |
GET |
/versions/{serial} |
Get one version. |
DELETE |
/versions/{serial} |
Delete one version. |
POST |
/lock |
Lock the state, with the lock as the JSON body. |
DELETE |
/lock |
Remove the lock given in the JSON body. Without a body, remove any lock. |
Limits
Section titled “Limits”[packages] LIMIT_SIZE_TERRAFORM_STATE caps the size of one upload, such as 10 MiB.
The default -1 sets no cap.
State versions count toward the owner’s package storage and the quotas like every other package.