Terraform 模块仓库 API

  • Tier: 基础版, 专业版, 旗舰版
  • Offering: JihuLab.com, 私有化部署

这是 Terraform 模块注册表 的 API 文档。

该 API 被 [Terraform CLI](https://www.terraform.io/) 使用,通常不用于手动消费。未记录的身份验证方法可能会在未来被移除。

关于如何从极狐GitLab Terraform 模块注册表上传和安装 Terraform 模块的说明,请参阅 Terraform 模块注册表文档

列出特定模块的可用版本#

获取特定模块的可用版本列表。

plaintext
GET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/versions
属性类型必需描述
module_namespacestringyesTerraform 模块的项目或子群组所属的顶级群组(命名空间)。
module_namestringyes模块名称。
module_systemstringyes模块系统或提供商的名称。
shell
curl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local/versions"

示例响应:

json
1{ 2 "modules": [ 3 { 4 "versions": [ 5 { 6 "version": "1.0.0", 7 "submodules": [], 8 "root": { 9 "dependencies": [], 10 "providers": [ 11 { 12 "name": "local", 13 "version":"" 14 } 15 ] 16 } 17 }, 18 { 19 "version": "0.9.3", 20 "submodules": [], 21 "root": { 22 "dependencies": [], 23 "providers": [ 24 { 25 "name": "local", 26 "version":"" 27 } 28 ] 29 } 30 } 31 ], 32 "source": "https://gitlab.example.com/group/hello-world" 33 } 34 ] 35}

获取特定模块的最新版本#

获取给定模块的最新版本的信息。

plaintext
GET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system
属性类型必需描述
module_namespacestringyesTerraform 模块的项目所属的群组。
module_namestringyes模块名称。
module_systemstringyes模块系统或提供商的名称。
shell
curl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local"

示例响应:

json
1{ 2 "name": "hello-world/local", 3 "provider": "local", 4 "providers": [ 5 "local" 6 ], 7 "root": { 8 "dependencies": [] 9 }, 10 "source": "https://gitlab.example.com/group/hello-world", 11 "submodules": [], 12 "version": "1.0.0", 13 "versions": [ 14 "1.0.0" 15 ] 16}

获取特定模块的特定版本#

获取给定模块的特定版本的信息。

plaintext
GET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/1.0.0
属性类型必需描述
module_namespacestringyesTerraform 模块的项目所属的群组。
module_namestringyes模块名称。
module_systemstringyes模块系统或提供商的名称。
shell
curl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local/1.0.0"

示例响应:

json
1{ 2 "name": "hello-world/local", 3 "provider": "local", 4 "providers": [ 5 "local" 6 ], 7 "root": { 8 "dependencies": [] 9 }, 10 "source": "https://gitlab.example.com/group/hello-world", 11 "submodules": [], 12 "version": "1.0.0", 13 "versions": [ 14 "1.0.0" 15 ] 16}

获取下载最新模块版本的 URL#

X-Terraform-Get 头部获取最新模块版本的下载 URL。

plaintext
GET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/download
属性类型必需描述
module_namespacestringyesTerraform 模块的项目所属的群组。
module_namestringyes模块名称。
module_systemstringyes模块系统或提供商的名称。
shell
curl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local/download"

示例响应:

plaintext
HTTP/1.1 204 No Content Content-Length: 0 X-Terraform-Get: /api/v4/packages/terraform/modules/v1/group/hello-world/local/1.0.0/file?token=&archive=tgz

在底层,此 API 端点重定向到 packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/:module_version/download

获取下载特定模块版本的 URL#

X-Terraform-Get 头部获取特定模块版本的下载 URL。

plaintext
GET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/:module_version/download
属性类型必需描述
module_namespacestringyesTerraform 模块的项目所属的群组。
module_namestringyes模块名称。
module_systemstringyes模块系统或提供商的名称。
module_versionstringyes要下载的特定模块版本。
shell
curl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local/1.0.0/download"

示例响应:

plaintext
HTTP/1.1 204 No Content Content-Length: 0 X-Terraform-Get: /api/v4/packages/terraform/modules/v1/group/hello-world/local/1.0.0/file?token=&archive=tgz

下载模块#

从命名空间#

plaintext
GET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/:module_version/file
属性类型必需描述
module_namespacestringyesTerraform 模块的项目所属的群组。
module_namestringyes模块名称。
module_systemstringyes模块系统或提供商的名称。
module_versionstringyes要下载的特定模块版本。
shell
curl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local/1.0.0/file"

将输出写入文件:

shell
curl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local/1.0.0/file" --output hello-world-local.tgz

从项目#

plaintext
GET /projects/:id/packages/terraform/modules/:module_name/:module_system/:module_version
属性类型必需描述
idinteger/stringyes项目的 ID 或 URL 编码路径。
module_namestringyes模块名称。
module_systemstringyes模块系统或提供商的名称。
module_versionstringno要下载的特定模块版本。如果省略,则下载最新版本。
shell
curl --user "<username>:<personal_access_token>" "https://gitlab.example.com/api/v4/projects/1/packages/terraform/modules/hello-world/local/1.0.0"

将输出写入文件:

shell
curl --user "<username>:<personal_access_token>" "https://gitlab.example.com/api/v4/projects/1/packages/terraform/modules/hello-world/local/1.0.0" --output hello-world-local.tgz

上传模块#

plaintext
PUT /projects/:id/packages/terraform/modules/:module-name/:module-system/:module-version/file
属性类型必需描述
idinteger or stringyes项目的 ID 或 URL 编码路径。
module-namestringyes模块名称。
module-systemstringyes模块系统或提供商的名称。
module-versionstringyes要上传的特定模块版本。
shell
curl --fail-with-body \ --header "PRIVATE-TOKEN: <your_access_token>" \ --upload-file path/to/file.tgz \ --url "https://gitlab.example.com/api/v4/projects/<your_project_id>/packages/terraform/modules/my-module/my-system/0.0.1/file"

可以用于身份验证的令牌:

头部
PRIVATE-TOKEN一个具有 api 范围的 个人访问令牌
DEPLOY-TOKEN一个具有 write_package_registry 范围的 部署令牌
JOB-TOKEN一个 作业令牌

示例响应:

json
{ "message": "201 Created" }