cyralinc / terraform-provider-cyral

Cyral Terraform Provider
https://registry.terraform.io/providers/cyralinc/cyral/latest
Apache License 2.0
13 stars 3 forks source link

cyral_datamap always wants to update-in-place to change the order of attributes #187

Closed ewall closed 2 years ago

ewall commented 2 years ago

Every time I do a new terraform plan (or apply) on a module that uses the cyral_datamap component, terraform wants to update that resource with the same list of mapping.data_location.attributes, but in a different order, like this (simplified for visibility):

Terraform will perform the following actions:

  # module.blahblah.cyral_datamap[0] will be updated in-place
  ~ resource "cyral_datamap" "blahblah" {
        id           = "datamap"
        # (1 unchanged attribute hidden)
      + mapping {
          + label = "LABELONE"

          + data_location {
              + attributes = [
                  - "this.a",
                  - "this.b",
                  - "this.c",
                  - "this.d",
                ]
              + repo       = "blahblah"
            }
        }
      - mapping {
          - label = "LABELONE" -> null

          - data_location {
              - attributes = [
                  - "this.c",
                  - "this.a",
                  - "this.b",
                  - "this.d",
                ] -> null
              - repo       = "blahblah" -> null
            }
        }
        # (2 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

It seems that each time terraform plans it shows a different order for the current state of the attributes lists that it wants to remove. For example, if I plan again it may suggest that the old state it wants to overwrite it now something like this:

              - attributes = [
                  - "this.d",
                  - "this.a",
                  - "this.b",
                  - "this.c",
                ] -> null

I find this extra confusing since the schema.TypeList that I see in the code should be ordered, according to the terraform developer documentation.

(I do understand that terraform maps do not guarantee order, but that doesn't seem to be the problem here -- it's the order within the list of attributes.)

Presumably we could use terraform's lifecycle ignore_changes option to prevent this reordering every time, but that's counter-intuitive here as these datamaps will need to change over time as the database changes.

I have observed this issue on the current version of the Cyral provider available at this time (2.5.1) and an older one (2.0.1).

wcmjunior commented 2 years ago

Thanks for the feedback @ewall. We appreciate the detailed description and possible solution. We had a similar issue in the past that was fixed in #27 , but this seems to not have fixed the whole problem. We will check this one and get back to you.

wcmjunior commented 2 years ago

Fix available in v2.5.2.

ewall commented 2 years ago

Much appreciated! 💯