Terraform-provider-google: google_compute_instance_from_template ignores values defined in template

Created on 19 Feb 2019  ·  6Comments  ·  Source: hashicorp/terraform-provider-google


Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment
  • If an issue is assigned to the "modular-magician" user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned to "hashibot", a community member has claimed the issue already.

Terraform Version

$ terraform -v
Terraform v0.11.11
+ provider.google v2.0.0

Affected Resource(s)

  • google_compute_instance_template
  • google_compute_instance_from_template

Terraform Configuration Files

Config with the bug:

provider "google" {
  version = "~> 2.0"

  credentials = ""
  project     = ""
  region      = "us-west1"
}

resource "google_compute_instance_template" "default" {
  name_prefix  = "instance-template-"
  machine_type = "n1-standard-1"
  region       = "us-west1"

  disk {
    source_image = "ubuntu-1804-lts"
    disk_size_gb = 40
  }

  network_interface {
    network       = "default"
    access_config = {}
  }

  scheduling {
    preemptible       = true
    automatic_restart = false
  }

  lifecycle {
    create_before_destroy = true
  }
}

resource "google_compute_instance_from_template" "test" {
  name                     = "instance-from-template"
  zone                     = "us-west1-a"
  source_instance_template = "${google_compute_instance_template.default.self_link}"
}

Config without the bug (duplicates the scheduling block in the google_compute_instance_from_template resource):

provider "google" {
  version = "~> 2.0"

  credentials = ""
  project     = ""
  region      = "us-west1"
}

resource "google_compute_instance_template" "default" {
  name_prefix  = "instance-template-"
  machine_type = "n1-standard-1"
  region       = "us-west1"

  disk {
    source_image = "ubuntu-1804-lts"
    disk_size_gb = 40
  }

  network_interface {
    network       = "default"
    access_config = {}
  }

  scheduling {
    preemptible       = true
    automatic_restart = false
  }

  lifecycle {
    create_before_destroy = true
  }
}

resource "google_compute_instance_from_template" "test" {
  name                     = "instance-from-template"
  zone                     = "us-west1-a"
  source_instance_template = "${google_compute_instance_template.default.self_link}"

  scheduling {
    preemptible       = true
    automatic_restart = false
  }
}

Debug Output

See gist.

Notice that the request to create the template successfully returns on L55 and correctly sets scheduling.preemptible = true and scheduling.automatic_restart = false. Also, the request to retrieve the template on L155 returns the correct values in the scheduling block.

Then, the request to create the instance (presumably using the template) uses the incorrect values for the scheduling block on L192. It looks like it completely ignores the values in the template and uses defaults for creating an instance.

Expected Behavior

The instance created should have used the scheduling options defined in the template.

Actual Behavior

The Request to create the instance did not use the scheduling options defined in the template and instead used the default for creating an instance. Specifically, it should have set scheduling.automatic_restart = false because that is defined in the template, but it defaulted to use scheduling.automatic_restart = true, which conflicts with scheduling.preemptible = true.

Steps to Reproduce

Use the config above that has the bug:

  1. terraform apply
    and you will see the error

Use the config above that uses the work around of duplicating the scheduling block in the google_compute_instance_from_template resource and see that it runs without error.

bug

Most helpful comment

I ran into this as well. Duplicating the scheduling block in each instance from template worked around the issue, but it was confusing to not have the automatic_restart updated from the template.

All 6 comments

I ran into this as well. Duplicating the scheduling block in each instance from template worked around the issue, but it was confusing to not have the automatic_restart updated from the template.

Just ran into the same error a few minutes ago.

Took me a bit of time to figure out that the scheduling block is indeed overridden in google_compute_instance_template no matter what.

@conorgil we just had a fix for a similar issue https://github.com/terraform-providers/terraform-provider-google/issues/6050. Can you help verify if this works for you after the fix is released?

@edwardmedia Great to see this get fixed! Unfortunately, I have not been working with Terraform recently and I do not have time to help test.

@conorgil Please feel free to reopen it if you still see this is an issue. Thank you

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