Terraform-provider-google: google_compute_instance: Not able to change machine_type i.e. CPU platform N2 -> E2 and N2 -> N1

Created on 12 May 2020  ·  8Comments  ·  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 v0.12.24

  • provider.google v3.21.0

Affected Resource(s)

google_compute_instance

Terraform Configuration Files

# before machine_type change
resource "google_compute_instance" "instance" {
  name                      = "test-instance"
  zone                      = "europe-west1-b"
  allow_stopping_for_update = true
  machine_type              = "n2-standard-2"

  network_interface {
    subnetwork         = "test"
    subnetwork_project = "bla-network"
  }

  boot_disk {
    initialize_params {
      image = "centos-cloud/centos-7"
    }
  }
}
# after machine_type change
resource "google_compute_instance" "instance" {
  name                      = "test-instance"
  zone                      = "europe-west1-b"
  allow_stopping_for_update = true
  machine_type              = "e2-standard-2"

  network_interface {
    subnetwork         = "test"
    subnetwork_project = "bla-network"
  }

  boot_disk {
    initialize_params {
      image = "centos-cloud/centos-7"
    }
  }
}

Debug Output

https://gist.github.com/ilicmilan/5af1bbedcfa45cf60c90a4dd2ccb776b

Panic Output

Error: googleapi: Error 400: Setting minimum CPU platform is not supported for the selected machine type e2-standard-2., badRequest

  on main.tf line 2, in resource "google_compute_instance" "instance":
   2: resource "google_compute_instance" "instance" {

Expected Behavior

Machine type is changed from n2-standard-2 to e2-standard-2 and as a consequence machine was stopped and started again.

Actual Behavior

The machine was stopped, the new machine type setup failed due to min_cpu_platform and the machine remained stopped.

Steps to Reproduce

  1. terraform apply to create N2 instance
  2. Change instance's machine_type i.e. CPU platform to E2
  3. terraform apply to change the machine type
bug

All 8 comments

If I decide to do N2 -> N1 transition, the error is:

Error 400: The selected machine type (n1-standard-2) is not compatible with CPU platform cascadelake, badRequest

Provider can't validate the compatibility between machine types and cpu platforms. It relies on API and pass the response to the client.

@c2thorn your thoughts ?

The API is defaulting to min_cpu_platform = "Intel Cascade Lake" in this scenario. You can work around this by setting your min_cpu_platform = "Automatic" before transitioning the machine_type.

Unfortunately it looks like this cannot be done on the same terraform apply, as the provider currently attempts to modify the machine_type before modifying the min_cpu_platform. I'll have to check to see if this can be re-ordered without affecting any current use cases.

However the immediate work around would be to:

  1. Create the N2 instance
  2. When it is time to transition, set min_cpu_platform = "Automatic"
  3. Transition machine_type

Why have you closed this? Is it now fixed?

Sorry, I should have posted an explanation. I believe this interaction has changed upstream in the API (I can't find any relevant changes in the provider, but I could be wrong), as transitioning the machine type also changes cpu_platform to an acceptable value. When I retried the steps described in the original post, it was successful.

@kustodian do you still see this issue occuring? If so it would be helpful to see your debug output.

I just tested it with Terraform v0.13.0 and google provider v3.25.0 and it was successful, indeed.

Awesome! Then it was a good call for closing it :D

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