aritra
aritra

Reputation: 31

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.

Upvotes: 3

Views: 5981

Answers (1)

norbjd
norbjd

Reputation: 11237

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).

Upvotes: 3

Related Questions