OpenTofu ORAS 后端:在 GitHub Container Registry (GHCR) 中存储状态
发布: (2025年12月28日 GMT+8 16:52)
2 分钟阅读
原文: Dev.to
Source: Dev.to
介绍
OpenTofu 1.10 为提供者加入了 OCI 支持,但对状态存储仍未给出方案。
对于许多项目来说,在 S3 + DynamoDB 中存放一个 153 MB 的 tfstate(并使用 DynamoDB 进行锁定)显得过于繁重,尤其是当团队已经在使用:
- OCI 注册表(例如 GHCR)
- GitHub Actions 来部署 Terraform 代码
下面的 fork 提供了一个原生 ORAS 后端,将状态以 OCI 架构的可寻址制品(content‑addressable)形式存储。
ORAS 后端配置
terraform {
backend "oras" {
repository = "ghcr.io/org/project-state"
compression = "gzip"
versioning {
enabled = true
max_versions = 5
}
}
}
加密(可选)
terraform {
backend "oras" {
repository = "ghcr.io/my-org/tf-state"
}
encryption {
key_provider "pbkdf2" "main" {
passphrase = var.state_passphrase
}
method "aes_gcm" "main" {
key_provider = key_provider.pbkdf2.main
}
state {
method = method.aes_gcm.main
}
}
}
安装
# Installs as `tofu-oras`
curl -sSL https://raw.githubusercontent.com/vmvarela/opentofu/develop/install.sh | sh
从源码构建
git clone https://github.com/vmvarela/opentofu
cd opentofu
go build -o tofu-oras ./cmd/tofu
完整文档
请参阅 ORAS Backend README 以获取详细使用说明。
使用场景
- 资源紧张的初创公司,采用轻量化的基础设施即代码
- 个人或副业项目(使用免费 GHCR 配额)
- 使用注册表镜像的 air‑gapped 环境
- 已经在 OCI 生态系统中投入的团队
- 多云项目
未来计划(若社区兴趣增长)
- 提升测试覆盖率
- 为不同场景添加更多示例
- 在除 GHCR 之外的 OCI 注册表上进行测试
社区反馈
你怎么看?会选择在 OCI 注册表中存储状态而不是 S3 吗?为了采用这种方式,你还需要哪些功能?
Repository: (branch/tag v1.11.2-oras, etc.)