导入操作时"pulumi import"不适用于 GCP 资源



我正在使用Pulumi Typescript在GCP中部署基础设施。

我的项目中已经部署了1个Google Kubernetes引擎资源。为了在Pulumi操作中使用现有资源,我找到了关于Pulumi导入的文档,在其中我探索了它的实际工作方式。通过引用该文档,我添加了导入配置如下:

import * as gcp from "@pulumi/gcp";
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
import * as infraJson from "../parameters/infrastructure-parameters.json"
export const gke = new gcp.container.Cluster(infraJson.clusterConfigs.CLUSTER_NAME,
{
name: infraJson.clusterConfigs.CLUSTER_NAME,
initialNodeCount: infraJson.clusterConfigs.CLUSTER_DEFAULT_NODEPOOL_NODE_COUNT,
removeDefaultNodePool: false,
location: infraJson.clusterConfigs.RESOURCE_LOCATION,
nodeConfig: {
preemptible: false,
machineType: infraJson.clusterConfigs.CLUSTER_MACHINE_TYPE,
oauthScopes: [
"https://www.googleapis.com/auth/service.management.readonly",
"https://www.googleapis.com/auth/devstorage.read_only",
"https://www.googleapis.com/auth/monitoring.write",
"https://www.googleapis.com/auth/servicecontrol",
"https://www.googleapis.com/auth/logging.write",
"https://www.googleapis.com/auth/trace.append"
]
}
}, {
import: "projects/myproject/locations/us-central1-c/clusters/test-cluster"
});

但是,当我运行命令">Pulumi向上";它向我显示警告:

gcp:container:Cluster (test-cluster):
warning: previously-imported resources that still specify an ID may not be replaced; please remove the `import` declaration from your program.

我到处寻找如何在GCP中做到这一点,但没有找到任何东西。

如果有人知道怎么做,请帮我解决这个问题。。!非常感谢。

Pulumi代码库中唯一包含该警告的地方是:

https://github.com/pulumi/pulumi/blob/272c4643b20d40113689475fd2f9fe3134e6d431/pkg/resource/deploy/step_generator.go#L540-L551

我从这段代码中了解到:您指定了一个要导入的现有集群的ID,作为Pulumi代码的一部分,描述为";成为";集群的情况。但是您现有的集群配置与代码中对集群配置的描述不同。这导致Pulumi想要更换您的集群,但您的import选项阻止了它,因此发出警告。

请运行pulumi preview --diff,查看代码中的配置与实际状态的不同之处。更改代码以匹配实际状态。此时,pulumi preview应该会告诉您没有任何更改。一旦有了这些,就应该能够毫无问题地运行pulumi up

最新更新