Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google_compute_instance_from_template ignores values defined in template #3076

Closed
conorgil opened this issue Feb 19, 2019 · 6 comments
Closed
Assignees
Labels
bug forward/review In review; remove label to forward service/compute-instances

Comments

@conorgil
Copy link
Contributor

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.

@ghost ghost added the bug label Feb 19, 2019
@billyfoss
Copy link

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.

@BastienM
Copy link

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.

modular-magician added a commit to modular-magician/terraform-provider-google that referenced this issue Feb 12, 2020
* GKE Cluster Autoscaling profile

* autoscaling profile and tests

* fix sqladmin api usage

* fixes

* update documentation

* fix sql api url and base path

* merge upstream changes to sql

* fix indentation character

Signed-off-by: Modular Magician <[email protected]>
modular-magician added a commit that referenced this issue Feb 12, 2020
* GKE Cluster Autoscaling profile

* autoscaling profile and tests

* fix sqladmin api usage

* fixes

* update documentation

* fix sql api url and base path

* merge upstream changes to sql

* fix indentation character

Signed-off-by: Modular Magician <[email protected]>
@edwardmedia edwardmedia self-assigned this Apr 7, 2020
@edwardmedia
Copy link
Contributor

edwardmedia commented Apr 8, 2020

@conorgil we just had a fix for a similar issue #6050. Can you help verify if this works for you after the fix is released?

@conorgil
Copy link
Contributor Author

conorgil commented Apr 8, 2020

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

@ghost ghost removed the waiting-response label Apr 8, 2020
@edwardmedia
Copy link
Contributor

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

@ghost
Copy link

ghost commented May 9, 2020

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!

@ghost ghost locked and limited conversation to collaborators May 9, 2020
@github-actions github-actions bot added forward/review In review; remove label to forward service/compute-instances labels Jan 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug forward/review In review; remove label to forward service/compute-instances
Projects
None yet
Development

No branches or pull requests

4 participants