简体   繁体   English

如何使用 terraform 停止 GCP vm 实例

[英]How to stop GCP vm instances using terraform

I am new to Terraform.我是 Terraform 的新手。 How to stop GCP vm instances using terraform?如何使用 terraform 停止 GCP vm 实例? I have tried changing status of the vm instance, it's available for AWS but couldn't find the way to do it for GCP.我曾尝试更改 vm 实例的状态,它可用于 AWS,但找不到为 GCP 执行此操作的方法。

Edit编辑

Since version v3.11.0 of Google provider (released 2020/03/02), it is possible to shutdown and start a Compute instance with desired_status field :由于版本v3.11.0谷歌提供的(发布2020年3月2日),就可以关闭和启动一个计算实例desired_status领域:

  • compute: added the ability to manage the status of google_compute_instance resources with the desired_status field计算:添加了使用 desired_status 字段管理 google_compute_instance 资源状态的功能

Just declare in your Terraform resource :只需在您的 Terraform 资源中声明:

resource "google_compute_instance" "default" {
  name         = "test"
  machine_type = "n1-standard-1"
  zone         = "us-central1-a"

  [...]

  desired_status = "TERMINATED"
}

And apply your changes.并应用您的更改。 If your instance was running before, it should be shut down.如果您的实例之前正在运行,则应将其关闭。 This PR shows the modifications that have been added, if you are interested to take a look. 这个 PR展示了已经添加的修改,有兴趣的可以看看。 The desired_status can either take RUNNING or TERMINATED values. desired_status可以采用RUNNINGTERMINATED值。

Previous answer (as of 2019/10/26)上一个答案(截至 2019/10/26)

As of the time of the question (2019/09/18), with the latest Google provider available then (version v2.15.0 ), this is not possible to update the status of a Google Compute instance.截至提问时 (2019/09/18),使用最新的 Google 提供程序可用(版本v2.15.0 ),无法更新 Google Compute 实例的状态。

The following issue is opened on the Google Terraform provider on Github : 在 Github上的Google Terraform provider 上打开了以下问题:

There is also a Pull Request to add this feature :还有一个 Pull Request 来添加这个功能:

But unfortunately, this PR seems to be stale (not updated since 2019/03/13).但不幸的是,这个 PR 似乎是陈旧的(自 2019/03/13 以来没有更新)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM