{{< details >}}

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

{{< /details >}}

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

{{< alert type=”warning” >}}

该 API 被 Terraform CLI 使用,通常不用于手动消费。未记录的身份验证方法可能会在未来被移除。

{{< /alert >}}

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

列出特定模块的可用版本

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

GET packages/terraform/modules/v1/:module_namespace/:module_name/:module_system/versions
属性 类型 必需 描述
module_namespace string yes Terraform 模块的项目或子群组所属的顶级群组(命名空间)。
module_name string yes 模块名称。
module_system string yes 模块系统或提供商的名称。
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 yes Terraform 模块的项目所属的群组。
module_name string yes 模块名称。
module_system string yes 模块系统或提供商的名称。
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 yes Terraform 模块的项目所属的群组。
module_name string yes 模块名称。
module_system string yes 模块系统或提供商的名称。
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 yes Terraform 模块的项目所属的群组。
module_name string yes 模块名称。
module_system string yes 模块系统或提供商的名称。
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 yes Terraform 模块的项目所属的群组。
module_name string yes 模块名称。
module_system string yes 模块系统或提供商的名称。
module_version string yes 要下载的特定模块版本。
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 yes Terraform 模块的项目所属的群组。
module_name string yes 模块名称。
module_system string yes 模块系统或提供商的名称。
module_version string yes 要下载的特定模块版本。
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 yes 项目的 ID 或 URL 编码路径。
module_name string yes 模块名称。
module_system string yes 模块系统或提供商的名称。
module_version string no 要下载的特定模块版本。如果省略,则下载最新版本。
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 yes 项目的 ID 或 URL 编码路径。
module-name string yes 模块名称。
module-system string yes 模块系统或提供商的名称。
module-version string yes 要上传的特定模块版本。
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"
}