首页 > 解决方案 > 如何在 Pulumi 中找到现有的 gitlab 项目集群?

问题描述

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

public static get(name: string, id: Input<ID>, state?: ProjectClusterState, opts?: CustomResourceOptions): ProjectCluster

我写

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

const cluster = gitlab.get("gitlabcicd", ???)

然后我收到一条错误消息:Property get dose not exit 如何使用 get API?我在哪里可以找到身份证?

标签: typescriptkubernetesgitlabpulumi

解决方案


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

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 程序中,然后你就可以开始管理它了。


推荐阅读