Fix the issue where the for_each in rancher2_registry keeps changing the order of the list that has not changed #1268
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue:
#923
Problem
When we keep invoking
terraform apply
multiple times, Terraform may report changes in therancher2_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