pactflow / terraform-provider-pact

Terraform provider for Pact Broker (and Pactflow)
https://pactflow.io
MIT License
24 stars 4 forks source link

Feature request: order array items #21

Closed mefellows closed 2 years ago

mefellows commented 2 years ago

Any chance we can either persist changes when the order of elements change in an array, or ignore the order altogether? Things like this create a loop where terraform plan always displays this change, and apparently nothing happens after doing terraform apply, so the only way of fixing it is manually changing the order in the tf files to match it, which is not practical when using references instead of the plain uuids (i.e, going: pact_user.john_doe.uuid)

# pact_team.myTeam will be updated in-place
  ~ resource "pact_team" "myTeam" {
        id           = "b3a82ec1-a34e-4f82-845f-e41f9de3da78"
        name         = "MyTeam"
      ~ users        = [
            "967155a1-29a7-4aa3-8520-7bad949abad8",
          - "1e8c0d39-7937-4647-8886-9e40690e6886",
            "4e161b2b-b07a-4979-a69e-f5ed2727bfa4",
          - "50011c55-2fa0-4e70-b5e5-9592fc38e36a",
            "781a1bf2-9723-40c8-9cee-69ff9515c7f6",
          + "50011c55-2fa0-4e70-b5e5-9592fc38e36a",
          + "1e8c0d39-7937-4647-8886-9e40690e6886",
        ]
        # (2 unchanged attributes hidden)
    }

I believe it can be addressed if we sort items on store.

mefellows commented 2 years ago

re-opening due to https://pact-foundation.slack.com/archives/C02NN7XSHDM/p1649732362957959?thread_ts=1647571379.124189&cid=C02NN7XSHDM.

mefellows commented 2 years ago

Note on issue. Simple fix is to move from schema.TypeList to schema.TypeSet. The issue is that terraform change detection is performed internally, so any attempt to sort the arrays is unstable across versions and is cumbersome to address. Moving to a Set which is order independent solves the issue more natively. Tested on the roles attribute of a user in f3db0fb.