AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1084620
Accepted
mangusbrother
mangusbrother
Asked: 2021-11-26 13:31:40 +0800 CST2021-11-26 13:31:40 +0800 CST 2021-11-26 13:31:40 +0800 CST

terraform apply error alreadyExists on untouched resources

  • 772

我正在按照官方指南开始一个新的 terraform 项目:

https://learn.hashicorp.com/tutorials/terraform/gke?in=terraform/kubernetes&utm_source=WEBSITE&utm_medium=WEB_IO&utm_offer=ARTICLE_PAGE&utm_content=DOCS&_ga=2.91746777.2118895439.1637849824-960084622.1637849824

我设法让它运行。(我将它作为提交时触发的谷歌云构建任务的一部分运行)

但是,如果我更改资源中的某些内容(例如,我将“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
google-cloud-platform google-compute-engine terraform google-kubernetes-engine
  • 2 2 个回答
  • 4299 Views

2 个回答

  • Voted
  1. John Hanley
    2021-11-26T13:49:07+08:002021-11-26T13:49:07+08:00

    如果您使用 Terraform 创建资源,请不要在 Terraform 之外修改它们。

    如果您手动更改某些内容,Terraform 将尝试将其放回 HCL 声明它的方式以及 Terraform 保存它的方式。

    这称为声明性。您正在尝试使 Terraform 动态化,这首先会击败使用 Terraform。

    • 2
  2. Best Answer
    mangusbrother
    2021-11-26T23:30:07+08:002021-11-26T23:30:07+08:00

    terraform 状态需要存储在所有构建都可以访问的位置。例如在谷歌云存储桶中,如下所示:https ://www.terraform.io/docs/language/settings/backends/gcs.html

    • 1

相关问题

  • 带有 OpenVPN 的 Google Compute Engine 上的 VPN 服务器

  • 云有多大?[关闭]

  • 谷歌应用引擎中的 joomla

  • 无需短信即可注册 Google AppEngine?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve