$ terraform -v
Terraform v0.11.11
+ provider.google v2.0.0
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
}
}
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.
The instance created should have used the scheduling options defined in the template.
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.
Use the config above that has the bug:
terraform applyUse 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.
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!
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.