Help us learn about your current experience with the documentation. Take the survey.

Terraform 模块仓库 API

  • 版本:Free, Premium, Ultimate
  • 产品:GitLab.com, GitLab Self-Managed, GitLab Dedicated

这是 Terraform 模块仓库 的 API 文档。

此 API 供 Terraform CLI 使用,通常不建议手动调用。未来可能会移除未在文档中说明的认证方法。

有关如何从 GitLab Terraform 模块仓库上传和安装 Terraform 模块的说明,请参阅 Terraform 模块仓库文档

列出特定模块的可用版本

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

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

示例响应:

{
  "modules": [
    {
      "versions": [
        {
          "version": "1.0.0",
          "submodules": [],
          "root": {
            "dependencies": [],
            "providers": [
              {
                "name": "local",
                "version":""
              }
            ]
          }
        },
        {
          "version": "0.9.3",
          "submodules": [],
          "root": {
            "dependencies": [],
            "providers": [
              {
                "name": "local",
                "version":""
              }
            ]
          }
        }
      ],
      "source": "https://gitlab.example.com/group/hello-world"
    }
  ]
}

特定模块的最新版本

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

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

示例响应:

{
  "name": "hello-world/local",
  "provider": "local",
  "providers": [
    "local"
  ],
  "root": {
    "dependencies": []
  },
  "source": "https://gitlab.example.com/group/hello-world",
  "submodules": [],
  "version": "1.0.0",
  "versions": [
    "1.0.0"
  ]
}

获取特定模块的指定版本

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

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

示例响应:

{
  "name": "hello-world/local",
  "provider": "local",
  "providers": [
    "local"
  ],
  "root": {
    "dependencies": []
  },
  "source": "https://gitlab.example.com/group/hello-world",
  "submodules": [],
  "version": "1.0.0",
  "versions": [
    "1.0.0"
  ]
}

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

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

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

示例响应:

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。

GET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/:module_version/download
属性 类型 必需 描述
module_namespace string Terraform 模块项目所属的组。
module_name string 模块名称。
module_system string 模块系统或 provider 的名称。
module_version string 要下载的指定模块版本。
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"

示例响应:

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

下载模块

从命名空间下载

GET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/:module_version/file
属性 类型 必需 描述
module_namespace string Terraform 模块项目所属的组。
module_name string 模块名称。
module_system string 模块系统或 provider 的名称。
module_version string 要下载的指定模块版本。
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"

要将输出写入文件:

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

从项目下载

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

要将输出写入文件:

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

上传模块

PUT /projects/:id/packages/terraform/modules/:module-name/:module-system/:module-version/file
属性 类型 必需 描述
id integer or string 项目的 ID 或 URL 编码的路径。
module-name string 模块名称。
module-system string 模块系统或 provider 的名称。
module-version string 要上传的指定模块版本。
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 作业令牌

示例响应:

{
  "message": "201 Created"
}