如何在 Pulumi 中找到现有的 gitlab 项目集群?

问题描述

我已经在Gitlab中连接了一个Kubernetes集群作为项目集群 https://gitlab.com/steinKo/gitlabcicd/-/clusters/142291 我想访问 Pulumi 中的这个集群 按照我可以使用的文档查找现有的 ProjectCluster 资源 我可以使用 API 调用

dt_html[11]

我写的

dt_html

然后我收到一条错误消息:Property get do do not exit 如何使用获取 API? 我在哪里可以找到 ID?

解决方法

您可以使用以下代码访问集群:

import * as gitlab from "@pulumi/gitlab";

const projectCluster = gitlab.ProjectCluster.get("mycluster","clusterid");

其中 mycluster 是您在 Pulumi 程序中为其指定的名称,clusterid 是集群的 GitLab 中的 ID。

您可以使用 GitLab API 获取集群的 ID:https://docs.gitlab.com/ee/api/project_clusters.html

请注意,这将不允许您对集群进行更改(因为您不会将其导入 Pulumi 程序),但它会为您提供有关集群本身的信息。

如果您想在您的 Pulumi 程序中开始管理集群,那么您可以通过运行以下命令使用 CLI 导入它:pulumi import gitlab:index/projectCluster:ProjectCluster bar projectid:clusterid 这将为您提供正确的代码以复制并粘贴到您的 Pulumi 程序中您可以从哪一点开始管理它。

,

阅读 pulumi 文档以检索项目的正确语法如下:

import * as pulumi from "@pulumi/pulumi";
import * as gitlab from "@pulumi/gitlab";

const example = pulumi.output(gitlab.getProject({
    id: "gitlabcicd",},{ async: true }));

参考:https://www.pulumi.com/docs/reference/pkg/gitlab/getproject/