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

Cannot change a MIG from stateful to stateless #10266

Closed
st250475 opened this issue Oct 6, 2021 · 3 comments · Fixed by GoogleCloudPlatform/magic-modules#7254, hashicorp/terraform-provider-google-beta#5203 or #13737
Labels

Comments

@st250475
Copy link

st250475 commented Oct 6, 2021

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

  • provider registry.terraform.io/hashicorp/google v3.87.0

Affected Resource(s)

  • google_compute_instance_group_manager
  • google_compute_region_instance_group_manager

Terraform Configuration Files

The problem arises when the commented-out parts are applied (making the MIG stateful) and then removed (making it stateless).

resource "google_compute_instance_template" "poc" {
  name_prefix  = "poc-"
  machine_type = "e2-medium"
  region       = "europe-west2"

  disk {
    source_image      = "debian-cloud/debian-9"
    auto_delete       = true
    boot              = true
  }

#   disk {
#     device_name       = "stateful"
#     source_image      = "debian-cloud/debian-9"
#     auto_delete       = true
#     boot              = false
#   }

  network_interface {
    subnetwork = "subnet-01"
  }

  lifecycle {
    create_before_destroy = true
  }
}

resource "google_compute_instance_group_manager" "poc" {
  name = "poc"

  base_instance_name = "poc"
  zone               = "europe-west2-a"

  version {
    instance_template  = google_compute_instance_template.poc.id
  }

  target_size  = 1

#   stateful_disk {
#     device_name = "stateful"
#   }

}

Debug Output

This output is what we get when applying the Terraform above (with the stateful configuration removed). What we can see is that the PATCH to the MIG does not touch the Stateful Policy.

https://gist.github.com/srjturner/16505ed454e13d3956a3524031cbc52d

Expected Behavior

The MIG should have had its Stateful Policy removed so that it no longer was stateful, and so that it did not expect the Instance Template to have the (stateful) disk.

Actual Behavior

The MIG does not have its Stateful Policy removed, and it fails to accept the Instance Template because that has no longer got the expected disk.

Steps to Reproduce

  1. terraform apply -auto-approve with the commented lines uncommented to make the MIG stateful
  2. Comment the lines out (as shown above) to make the MIG stateless
  3. terraform apply -auto-approve

Note

If we issue a command line call to remove the SP:

gcloud compute instance-groups managed update poc --remove-stateful-disks stateful

then we can then successfully apply the Terraform without the SP and disk

@st250475 st250475 added the bug label Oct 6, 2021
@nat-henderson
Copy link
Contributor

Okay - I think I can see where this problem comes from, thanks for the report. I think we are probably not sending the empty StatefulPolicy (which is nil if the policy is empty), and we either need to use ForceSendFields, if available, or else return the empty object rather than nil from the expander. I'll try to get an integration test that repros this and see if that fixes it.

@nat-henderson nat-henderson self-assigned this Oct 8, 2021
@nat-henderson nat-henderson removed their assignment Jan 4, 2022
@askubis
Copy link

askubis commented Feb 8, 2023

I would like to fix this

@github-actions
Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants