Terraform 模块仓库 API
- Tier: 基础版, 专业版, 旗舰版
- Offering: JihuLab.com, 私有化部署
这是 Terraform 模块注册表 的 API 文档。
该 API 被 [Terraform CLI](https://www.terraform.io/) 使用,通常不用于手动消费。未记录的身份验证方法可能会在未来被移除。
关于如何从极狐GitLab Terraform 模块注册表上传和安装 Terraform 模块的说明,请参阅 Terraform 模块注册表文档。
列出特定模块的可用版本
获取特定模块的可用版本列表。
plaintextGET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/versions
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| module_namespace | string | yes | Terraform 模块的项目或子群组所属的顶级群组(命名空间)。 |
| module_name | string | yes | 模块名称。 |
| module_system | string | yes | 模块系统或提供商的名称。 |
shellcurl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local/versions"
示例响应:
json1{ 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}
获取特定模块的最新版本
获取给定模块的最新版本的信息。
plaintextGET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| module_namespace | string | yes | Terraform 模块的项目所属的群组。 |
| module_name | string | yes | 模块名称。 |
| module_system | string | yes | 模块系统或提供商的名称。 |
shellcurl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local"
示例响应:
json1{ 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}
获取特定模块的特定版本
获取给定模块的特定版本的信息。
plaintextGET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/1.0.0
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| module_namespace | string | yes | Terraform 模块的项目所属的群组。 |
| module_name | string | yes | 模块名称。 |
| module_system | string | yes | 模块系统或提供商的名称。 |
shellcurl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local/1.0.0"
示例响应:
json1{ 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。
plaintextGET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/download
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| module_namespace | string | yes | Terraform 模块的项目所属的群组。 |
| module_name | string | yes | 模块名称。 |
| module_system | string | yes | 模块系统或提供商的名称。 |
shellcurl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local/download"
示例响应:
plaintextHTTP/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。
plaintextGET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/:module_version/download
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| module_namespace | string | yes | Terraform 模块的项目所属的群组。 |
| module_name | string | yes | 模块名称。 |
| module_system | string | yes | 模块系统或提供商的名称。 |
| module_version | string | yes | 要下载的特定模块版本。 |
shellcurl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local/1.0.0/download"
示例响应:
plaintextHTTP/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
下载模块
从命名空间
plaintextGET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/:module_version/file
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| module_namespace | string | yes | Terraform 模块的项目所属的群组。 |
| module_name | string | yes | 模块名称。 |
| module_system | string | yes | 模块系统或提供商的名称。 |
| module_version | string | yes | 要下载的特定模块版本。 |
shellcurl --header "Authorization: Bearer <personal_access_token>" "https://gitlab.example.com/api/v4/packages/terraform/modules/v1/group/hello-world/local/1.0.0/file"
将输出写入文件:
shellcurl --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
从项目
plaintextGET /projects/:id/packages/terraform/modules/:module_name/:module_system/:module_version
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer/string | yes | 项目的 ID 或 URL 编码路径。 |
| module_name | string | yes | 模块名称。 |
| module_system | string | yes | 模块系统或提供商的名称。 |
| module_version | string | no | 要下载的特定模块版本。如果省略,则下载最新版本。 |
shellcurl --user "<username>:<personal_access_token>" "https://gitlab.example.com/api/v4/projects/1/packages/terraform/modules/hello-world/local/1.0.0"
将输出写入文件:
shellcurl --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
上传模块
plaintextPUT /projects/:id/packages/terraform/modules/:module-name/:module-system/:module-version/file
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| id | integer or string | yes | 项目的 ID 或 URL 编码路径。 |
| module-name | string | yes | 模块名称。 |
| module-system | string | yes | 模块系统或提供商的名称。 |
| module-version | string | yes | 要上传的特定模块版本。 |
shellcurl --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"
可以用于身份验证的令牌:
示例响应:
json{ "message": "201 Created" }