hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.29k stars 1.72k forks source link

server-side reordering on stateful_external_ip of google_compute_region_instance_group_manager #13430

Open edwardmedia opened 1 year ago

edwardmedia commented 1 year ago

Affected Resource(s)

=== CONT  TestAccRegionInstanceGroupManager_stateful
    provider_test.go:315: Step 1/6 error: After applying this test step, the plan was not empty.
        stdout:

        Terraform used the selected providers to generate the following execution
        plan. Resource actions are indicated with the following symbols:
          ~ update in-place

        Terraform will perform the following actions:

          # google_compute_region_instance_group_manager.igm-basic will be updated in-place
          ~ resource "google_compute_region_instance_group_manager" "igm-basic" {
                id                               = "projects/ci-test-project-188019/regions/us-central1/instanceGroupManagers/tf-test-rigm-u86rw6989b"
                name                             = "tf-test-rigm-u86rw6989b"
                # (14 unchanged attributes hidden)

              ~ stateful_external_ip {
                  ~ interface_name = "nic1" -> "nic0"
                    # (1 unchanged attribute hidden)
                }
              ~ stateful_external_ip {
                  ~ interface_name = "nic0" -> "nic1"
                    # (1 unchanged attribute hidden)
                }

                # (4 unchanged blocks hidden)
            }

        Plan: 0 to add, 1 to change, 0 to destroy.
--- FAIL: TestAccRegionInstanceGroupManager_stateful (191.75s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-google-beta/google-beta 191.789s
FAIL

b/340204874

rileykarson commented 1 year ago

Depending on the rules of the API we may be able to fix this in a backwards compatible way by following the state setting protocol (https://github.com/hashicorp/terraform-provider-google/issues/4328) and reordering the values as we're writing them in to state (during Read) to match the old state (and presumably the user's configuration).

If the values are returned in insertion order by the API- indicating this is an ordered list, not an unordered one- we will want to avoid doing so. However, given we're getting a diff, insertion order seems unlikely.

askubis commented 1 year ago

I have a fix for that in my pull request. I am happy to be the owner of this bug

roaks3 commented 1 year ago

This one is causing a lot of noise in our PRs, and fails in our nightly tests. Since we have this bug to capture the failure, I think we should skip the test while we work out a solution. It looks to be a little more involved than simply changing the fields from List to Set.

askubis commented 1 year ago

I don't think it's more than that. Set is unordered, list is. based on the output from the failure it's a matter of ordering (nic0 became nic1 and vice-versa). I also reran the test several times after and before this change.

I don't mind skipping it though.

edwardmedia commented 1 year ago

https://github.com/hashicorp/terraform-provider-google/issues/13735

melinath commented 10 months ago

@askubis are you still planning to work on this issue?

askubis commented 10 months ago

yes, I the PR is ready, https://github.com/GoogleCloudPlatform/magic-modules/pull/7205 but it's a breaking change ( I want to change a List to a Set), and thus I have to wait for a major release window

melinath commented 10 months ago

@askubis We just shipped the 5.0 major release in September - the next one will be in about a year. As described in https://github.com/hashicorp/terraform-provider-google/issues/13430#issuecomment-1412645376 it may be possible to fix this in a backwards-compatible way as well (without needing to wait for the next major release)

askubis commented 10 months ago

Yes, I'm aware I've missed it this time :( I'm happy to see someone else fix this if there's a volunteer. P.S. Do you have an example PR that would show how such server-side reordering can be implemented?

melinath commented 10 months ago

The way to implement this would be in the Read function by adding code to rewrite the field's value before setting it in state - if it's possible, using the field's flattener for this would be preferred. I did a quick survey but wasn't able to find an example PR.

SarahFrench commented 9 months ago

Would it be possible for me to pick up the short-term fix where we manipulate the stateful_external_ip ordering in the Read function? I'm sorry to potentially remove your first contribution @askubis but a customer has escalated this issue, meaning that we'd like a fix put in place as soon as possible.

We could close this issue with that short-term fix, and open a new issue that describes swapping to the correct fix of swapping to a Set, and link your PR to that issue

askubis commented 9 months ago

Sure, I don't mind someone else doing that. please assign to yourself @SarahFrench And sorry for missing the major release window, that would have fixed it :(

SarahFrench commented 9 months ago

No worries at all- this issue not being flagged for the v5.0.0 major release was an oversight on our part not yours! 😅

This GH issue has been marked as part of the Future Major Release milestone now so it'll be on our radar when we plan for v6.0.0, and we can get your PR merged then.

When I make a PR for the short-term fix I'll make sure it doesn't close this issue prematurely.

askubis commented 9 months ago

Great, thank you very much! :)

SarahFrench commented 8 months ago

My PR above is merged, but the work in there should be pulled out and replaced with changing the stateful_external_ip and stateful_internal_ip fields to Sets in the next major release

SarahFrench commented 5 months ago

I'm going to unassign myself, as this issue now represents changing this field to a Set. The immediate problem was addressed by adding logic to reorder items in the List to address diffs, but that logic should be removed and replaced with Sets.