Terraform-provider-google: GCE instances being created with automatic_restart set to OFF

Created on 27 Aug 2018  ·  12Comments  ·  Source: hashicorp/terraform-provider-google

Terraform Version

Terraform v0.11.8

  • provider.google v1.16.2

Affected Resource(s)

  • google_compute_instance

Affects multiple resources.

Terraform Configuration Files

data "google_compute_image" "memcache_image" {
  project = "terraform-sandbox"
  family  = "${ var.base_disk_image }"
}

data "google_compute_subnetwork" "primary" {
  name    = "primary"
  project = "sharedvpc-prod"
}

resource "google_compute_instance" "memcache-deploy" {
  count            = "${ var.size }"
  name             = "${ var.keyspace }${ format("%03d", count.index + 1) }"
  machine_type     = "${ var.machine_type }"
  min_cpu_platform = "${ var.min_cpu_platform }"
  zone             = "${ count.index % 2 == 0 ? lookup(var.region_zone, 0) : lookup(var.region_zone, 1) }"

  tags = "${ var.tags }"

  boot_disk {
    initialize_params {
      size  = "${ var.disk_size }"
      type  = "pd-standard"
      image = "${ data.google_compute_image.memcache_image.self_link }"
    }
  }

  allow_stopping_for_update = "true"

  lifecycle {
    ignore_changes = ["boot_disk"]
  }

  network_interface {
    subnetwork         = "${ data.google_compute_subnetwork.primary.self_link }"
    access_config      = []
  }
}

Debug Output

Not sure how to do this

Expected Behavior

Newly created instances are instantiated with "Automatic Restart: On (true)"

Actual Behavior

Newly created instances are coming up with "Automatic Restart: Off (false)"

Steps to Reproduce

  1. terraform apply

Important Factoids

Nothing to mention, mostly vanilla Terraform

References

None

bug documentation upstream-terraform

Most helpful comment

This is a critical bug, as automatic_restart is an important feature. Any update on this?

All 12 comments

You can obtain debug logs by setting some environment variables.

I'd love to see some debug logs for this, because 1.16.2 has the default set to true. So it's very bizarre that they're getting set to false, if you're not specifying any value.

Huh... It's indeed off (we use Private TFE). I'll try to check locally later...

With super-minimal config:

resource "google_compute_instance" "test" {
  name         = "test-autorestart"
  machine_type = "g1-small"

  boot_disk {
    initialize_params {
      image = "ubuntu-minimal-1804-lts"
      type  = "pd-ssd"
      size  = "10"
    }
  }

  network_interface {
    network = "default"
  }
}

I have this:

Terraform v0.11.8
+ provider.google v1.17.1

$ terraform apply
<...>
  + google_compute_instance.test
<...>
      scheduling.#:                           <computed>
<...>

Plan: 1 to add, 0 to change, 0 to destroy.

google_compute_instance.test: Creating...
<...>
  scheduling.#:                           "" => "<computed>"
<...>
google_compute_instance.test: Still creating... (10s elapsed)
google_compute_instance.test: Creation complete after 16s (ID: test-autorestart)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

$ terraform show
google_compute_instance.test:
<...>
  scheduling.# = 1
  scheduling.0.automatic_restart = false
  scheduling.0.on_host_maintenance = MIGRATE
  scheduling.0.preemptible = false
<...>

Here's the debug log if you really need it: https://gist.github.com/Chupaka/eec6bb056fff05614c6369104f78c4a9

Any update here? Just looking to see if I need to do anything else or if this is an active issue.

I have a reproduction of the issue, and we're working on figuring out why it's happening. Sorry for the delay. :(

Not a problem, just wanted to make sure it was in queue.

So, I'm still looking into this, but I wanted to provide an update on what I've learned:

  • We are explicitly asking the API to set Automatic Restart to off when we create the instance.
  • This shouldn't be happening, because Automatic Restart is set to default to on, and has been like that for the last year.

I can't explain how these are both true at the same time, but there we are. I'm going to continue looking into this and see if I can figure out what's going on, but it's entirely possible we've run into a bug in Terraform core, and I'll have to get inventive about how to work around it.

So, good news and bad news. I don't actually have a fix for this just yet, and I'm not sure there _can_ be one until Terraform 0.12.

Good news is there's a straightforward workaround: add scheduling {} to your config, and it suddenly works as intended.

I am seeing the same thing today (2018-10-29).

Using 1.19.1 of the google provider. I had not entered any scheduling block.
I see that the default is ON
https://github.com/terraform-providers/terraform-provider-google/blob/v1.19.1/google/resource_compute_instance.go#L482

Still my freshly created instance has automatic_restart set to OFF (yielding an unexpected outage in production).

Setting explicitly

+  scheduling {
+    automatic_restart = true
+  }

triggers an update and now the setting is correct:

scheduling:
  automaticRestart: true
  onHostMaintenance: MIGRATE
  preemptible: false

This is a critical bug, as automatic_restart is an important feature. Any update on this?

Right now, the only update that we have available is to set a scheduling {} block in your config, which will work around this issue. We're currently waiting for 0.12 of Terraform, to see if we get any new options for how to handle this. If we don't, we'll discuss some way to work around this on our end, though it will likely be a bit ugly.

I'll flag this as a documentation update for the moment, so we can at least surface it better.

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

Was this page helpful?
0 / 5 - 0 ratings