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 the issue where the for_each in rancher2_registry keeps changing the order of the list that has not changed #1268

Merged
merged 1 commit into from
Nov 27, 2023

Conversation

jiaqiluo
Copy link
Member

Issue:

#923

Problem

When we keep invoking terraform apply multiple times, Terraform may report changes in the rancher2_registry resource when we do not change anything.
Please check the linked GH issue for detailed examples.

It happens because when terraform-provider-rancher2 flattens the registry credential, it needs to convert a Map into a List, Golang does not guarantee the order of returned objects when traversing a Map, and terraform-provider-rancher2 saves items in the order of receiving, so the order of items in the final List may change even though it is the same set of items. Therefore, Terraform detects and reports changes.

Solution

Preserve the order of existing items in the final List can prevent Terraform from reporting such changes

Testing

Engineering Testing

Manual Testing

This fix is tested locally by adding extra logging lines which show that the order of existing items is preserved.

Automated Testing

The existing test case is updated.

QA Testing Considerations

the same case as the GH issue provides.

Regressions Considerations

none

@jiaqiluo jiaqiluo requested review from a-blender and a team November 22, 2023 20:12
rancher2/structure_registry.go Show resolved Hide resolved
rancher2/structure_registry_test.go Show resolved Hide resolved
@jiaqiluo jiaqiluo requested review from a-blender and a team November 27, 2023 16:49
@a-blender a-blender changed the title fix the issue where the for_each in rancher2_registry keeps changing the order of the list that has not changed Fix the issue where the for_each in rancher2_registry keeps changing the order of the list that has not changed Nov 27, 2023
@jiaqiluo jiaqiluo requested a review from a team November 27, 2023 18:15
@a-blender a-blender merged commit daae17b into rancher:master Nov 27, 2023
@jiaqiluo jiaqiluo deleted the fix-registry-order branch November 27, 2023 19:28
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.

3 participants