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

Fix permadiff that reorders stateful_external_ip blocks on google_compute_instance_group_manager and google_compute_region_instance_group_manager resources #1833

Conversation

modular-magician
Copy link
Collaborator

Relates to (but doesn't close!) this issue : hashicorp/terraform-provider-google#13430

This PR updates code related to stateful_external_ip blocks in the google_compute_instance_group_manager & google_compute_region_instance_group_manager resources to address a permadiff that proposes re-ordering those blocks. The root of this problem is that the API returns those blocks in a sorted order that doesn't match the user's config. The state will contain data returned from the API, so there's always a plan trying to return to the config-defined order.

Prior to this PR, the flattener function for stateful_external_ip blocks performs a conversion from a map (how the data from the API is presented by the compute Go client library) to an array (how the data is stored in state).

This PR updates the flattener function to also re-order data returned by the API so it matches the user's Terraform configuration. This is achieved by passing the schema.ResourceData data for the resource into the flattener, to act as a source of information about the order of those fields in the user's config.

Release Note Template for Downstream PRs (will be copied)

compute: fixed a permadiff that reordered `stateful_external_ip` and `stateful_internal_ip` blocks on `google_compute_instance_group_manager` and `google_compute_region_instance_group_manager` resources

Derived from GoogleCloudPlatform/magic-modules#9577

…compute_instance_group_manager` and `google_compute_region_instance_group_manager` resources (#9577)

* Make `flattenStatefulPolicyStatefulExternalIps` reorder `stateful_external_ip` fields from API to match user's config

* Add unit test for new ordering behaviour of `flattenStatefulPolicyStatefulExternalIps`

* Whitespace fix

* Update test file to be templated to use GA or Beta version of compute client library

* Add new test cases where the config contains no `stateful_external_ip` blocks vs 0 or 1+ in API data

* Refactor `flattenStatefulPolicyStatefulExternalIps` to make data ordering and data transformation occur in same loop

* Add test case for when nic in TF config is missing in the API response, update code to pass

* Remove unused test step

* Refactor IP sorting code to be reusable

* Update `flattenStatefulPolicyStatefulInternalIps` to reorder IPs

* Update unit and acceptance tests following refactor
[upstream:de43d7035e08ae2494db0b9e91376ec9aa6f5ae0]

Signed-off-by: Modular Magician <[email protected]>
@modular-magician modular-magician requested a review from a team as a code owner January 4, 2024 19:07
@modular-magician modular-magician requested review from melinath and removed request for a team January 4, 2024 19:07
@modular-magician modular-magician merged commit 13bd52d into GoogleCloudPlatform:main Jan 4, 2024
3 checks passed
Copy link

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

@modular-magician modular-magician deleted the downstream-pr-de43d7035e08ae2494db0b9e91376ec9aa6f5ae0 branch November 18, 2024 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant