labd / terraform-provider-commercetools

Terraform provider for commercetools
https://registry.terraform.io/providers/labd/commercetools/latest/docs
Mozilla Public License 2.0
64 stars 68 forks source link

dynamic values causes huge diff without real changes after upgrade #465

Closed lorenzosfarra closed 2 months ago

lorenzosfarra commented 6 months ago

Hi,

I am currently in the process of updating the plugin version from 1.0 to 1.13. I have also tried a "safer" jump, from 1.0 to 1.4, but with the same result.

Basically, before the migration, I had this syntax:

attribute {
    name  = "fake-name"
    label = {
      it-IT = "<label here>"
      en-US = "<other label here>"
    }
    input_tip = {
      it-IT = "<tip here>"
      en-US = "<other tip here>"
    }
    required   = false
    constraint = "SameForAll"
    type {
      name = "set"
      element_type {
        name   = "enum"
        values = jsondecode(file("${path.module}/benefits.json"))
      }
    }
    searchable = true
  }

where benefits.json was:

{
  "key-one": "Label one",
  "key-two": "Label two",
  "key-three": "Label three",
  "key-four": "Label four"
}

I have migrated the benefits.json to:

{
  "values": [
    { "key": "key-one", "label": "Label one" },
    { "key": "key-two", "label": "Label two" },
    { "key": "key-three", "label": "Label three" },
    { "key": "key-four", "label": "Label four" }
  ]
}

and the tf code to:

locals {
 # [...]
  benefits = jsondecode(file("${path.module}/benefits.json"))
}

resource "commercetools_product_type" "tree" {
# [....]
attribute {
    name  = "fake-name"
    label = {
      it-IT = "<label here>"
      en-US = "<other label here>"
    }
    input_tip = {
      it-IT = "<tip here>"
      en-US = "<other tip here>"
    }
    required   = false
    constraint = "SameForAll"
    type {
      name = "set"
      element_type {
        name   = "enum"
        dynamic "value" {
          for_each = local.benefits.values
          content {
            key   = value.value.key
            label = value.value.label
          }
        }
      }
    }
    searchable = true
  }
# [...]
}

Anyway I have this diff:

 ~ attribute {
            name       = "fake-name"
            # (6 unchanged attributes hidden)

          ~ type {
                name = "set"

              ~ element_type {
                    name = "enum"

                  ~ value {
                      ~ key   = "key-four" -> "key-one"
                      ~ label = "Label four" -> "Label one"
                    }
                  ~ value {
                      ~ key   = "key-one" -> "key-three"
                      ~ label = "Label one" -> "Label three"
                    }
                  ~ value {
                      ~ key   = "key-three" -> "key-four"
                      ~ label = "Label three" -> "Label four"
                    }

                    # (1 unchanged block hidden)
                }
            }
        }

        # (22 unchanged blocks hidden)
    }

Anyway I see that there is a closed bug report that states that this problem should be solved.

Any hints? Thanks!

demeyerthom commented 5 months ago

Hi @lorenzosfarra! Appologies for the late reply.

I have tried to reproduce this with your code example, but it does not seem to make any diff for me when rerunning (with the latest provider version). What version of terraform are you using?