我正在按照官方指南开始一个新的 terraform 项目:
我设法让它运行。(我将它作为提交时触发的谷歌云构建任务的一部分运行)
但是,如果我更改资源中的某些内容(例如,我将“gke_num_nodes”默认值从 2 替换为 1),当我terraform apply
再次运行时,这就是我得到的:
Plan: 4 to add, 0 to change, 0 to destroy.
Changes to Outputs:
+ kubernetes_cluster_host = (known after apply)
+ kubernetes_cluster_name = "workspace-auto-gke"
+ project_id = "workspace-auto"
+ region = "europe-west4"
google_compute_network.vpc: Creating...
╷
│ Error: Error creating Network: googleapi: Error 409: The resource 'projects/workspace-auto/global/networks/workspace-auto-vpc' already exists, alreadyExists
│
│ with google_compute_network.vpc,
│ on vpc.tf line 15, in resource "google_compute_network" "vpc":
│ 15: resource "google_compute_network" "vpc" {
│
╵
有没有办法让它不尝试重新创建现有的未触及资源?
我cloudbuild.json
的如下:
{
"steps": [
{
"name": "hashicorp/terraform",
"entrypoint": "/bin/sh",
"args": [
"./cloudbuild/prepare-terraform.sh"
]
}
],
"logsBucket": "gs://my-bucket/logdir",
"serviceAccount": "projects/my-proj/serviceAccounts/[email protected]"
}
prepare-terraform.sh
简单地
terraform init
terraform plan
terraform apply -auto-approve