简体   繁体   中英

How to stop GCP vm instances using terraform

I am new to Terraform. How to stop GCP vm instances using terraform? 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.

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 :

  • compute: added the ability to manage the status of google_compute_instance resources with the desired_status field

Just declare in your Terraform resource :

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. The desired_status can either take RUNNING or TERMINATED values.

Previous answer (as of 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.

The following issue is opened on the Google Terraform provider on Github :

There is also a Pull Request to add this feature :

But unfortunately, this PR seems to be stale (not updated since 2019/03/13).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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