跳转到内容
Try Gitea Cloud ☁️ for 30 days → Accelerate your Development & Deploys!
这是下一个版本的文档,仍在开发中。查看最新发布版本

Terraform State Registry

当前中文文档翻译不是最新版,访问英文版本查看最新内容,或帮助我们翻译

Publish terraform states to sync it between multiple users or CI system.

To work with the Terraform State registry, you need to use Terraform or OpenTofu.

To use the Gitea Terraform State registry, you need to configure the http backend in your Terraform configuration.

terraform {
backend "http" {
address = "https://gitea.example.com/api/packages/{owner}/terraform/state/{name}"
lock_address = "https://gitea.example.com/api/packages/{owner}/terraform/state/{name}/lock"
unlock_address = "https://gitea.example.com/api/packages/{owner}/terraform/state/{name}/lock"
lock_method = "POST"
unlock_method = "DELETE"
username = "{username}"
password = "{password_or_token}"
}
}
Placeholder Description
owner The owner of the state (user or organization).
name The name of the state.
username Your Gitea username.
password Your Gitea password or personal access token.

If you are using 2FA or OAuth use a personal access token instead of the password.

After configuring the backend, you can initialize it with:

Terminal window
terraform init

Terraform will prompt you to migrate your state if you already have one locally.

Gitea supports state locking to prevent concurrent modifications. The lock_address and unlock_address should point to the /lock sub-route of your state URL.

  • Locking: Performed via a POST request to {address}/lock.
  • Unlocking: Performed via a DELETE request to {address}/lock.

Terraform handles these requests automatically when configured as shown above.

The state registry supports encrypted state.

Gitea keeps track of your Terraform state versions. You can use the API to retrieve or delete specific versions.

To fetch the latest version of a state:

Terminal window
curl --user {username}:{password_or_token} \
https://gitea.example.com/api/packages/{owner}/terraform/state/{name}

To fetch a specific version by its serial number:

Terminal window
curl --user {username}:{password_or_token} \
https://gitea.example.com/api/packages/{owner}/terraform/state/{name}/versions/{serial}

To delete the entire state and all its versions:

Terminal window
curl --user {username}:{password_or_token} -X DELETE \
https://gitea.example.com/api/packages/{owner}/terraform/state/{name}

To delete a specific version by its serial number:

Terminal window
curl --user {username}:{password_or_token} -X DELETE \
https://gitea.example.com/api/packages/{owner}/terraform/state/{name}/versions/{serial}