rancher / terraform-provider-rancher2

Terraform Rancher2 provider
https://www.terraform.io/docs/providers/rancher2/
Mozilla Public License 2.0
253 stars 216 forks source link

Fix the issue where the for_each in rancher2_registry keeps changing the order of the list that has not changed #1268

Closed jiaqiluo closed 7 months ago

jiaqiluo commented 7 months ago

Issue:

https://github.com/rancher/terraform-provider-rancher2/issues/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