Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address enum fails to update #569

Closed
webwiebe opened this issue Feb 19, 2025 · 2 comments · Fixed by #571
Closed

address enum fails to update #569

webwiebe opened this issue Feb 19, 2025 · 2 comments · Fixed by #571
Assignees
Labels
bug Something isn't working

Comments

@webwiebe
Copy link

Version information

  • terraform: Please specify the version of Terraform you are using.
    terraform_version: 1.5.7

  • terraform provider: Please specify the version of the provider you are using.

commercetools: 1.11.2

Describe the bug

Removing an item from an enum in a type results in an error

│ Error: The given keys must be equal to the existing enum keys.
│ 
│   with module.commercetools-config-sdmy.commercetools_type.delivery_manager_address,
│   on .terraform/modules/commercetools-config-sdmy/address.tf line 1, in resource "commercetools_type" "delivery_manager_address":
│    1: resource "commercetools_type" "delivery_manager_address" {

While the plan output showed it wanting to remove the item (also note the ordering):

 # module.commercetools-config-sdmy.commercetools_type.delivery_manager_address will be updated in-place
  ~ resource "commercetools_type" "delivery_manager_address" {
        id                = "46deb58a-b08a-4edc-8c86-9df51054580e"
        name              = {
            "en" = "Custom Address with Delivery Manager attributes"
        }
        # (4 unchanged attributes hidden)

      ~ field {
            name       = "carrierCode"
            # (3 unchanged attributes hidden)

          ~ type {
                name = "Enum"

              ~ value {
                  ~ key   = "TODO" -> "DPD"
                  ~ label = "To Do" -> "Express delivery by Dynamic Parcel Distribution"
                }
              ~ value {
                  ~ key   = "DPD" -> "HERMESPOS"
                  ~ label = "Express delivery by Dynamic Parcel Distribution" -> "Express delivery by Hermes"
                }
              ~ value {
                  ~ key   = "HERMESPOS" -> "DHL"
                  ~ label = "Express delivery by Hermes" -> "Express delivery by DHL"
                }
              ~ value {
                  ~ key   = "DHL" -> "EVRI"
                  ~ label = "Express delivery by DHL" -> "Express delivery by Evri"
                }
              ~ value {
                  ~ key   = "EVRI" -> "YODEL"
                  ~ label = "Express delivery by Evri" -> "Express delivery by Yodel"
                }
              - value {
                  - key   = "YODEL" -> null
                  - label = "Express delivery by Yodel" -> null
                }
            }
        }

        # (2 unchanged blocks hidden)
    }

To Reproduce

Steps to reproduce the behavior.

Have a commercetools type defined for address

resource "commercetools_type" "delivery_manager_address" {
  key = "delivery-manager-address"
  name = {
    en = "Custom Address with Delivery Manager attributes"
  }
  resource_type_ids = ["address"]
 
  field {
    name = "carrierCode"
    label = {
      en = "Carrier Code"
    }

    type {
      name = "Enum"
      value {
        key   = "TODO"
        label = "To Do"
      }
      value {
        key   = "foo"
        label = "foo delivery"
      }
      value {
        key   = "bar"
        label = "bar delivery"
      }
    }
  }

then try to remove the TODO item

Expected behavior

The enum should be updated to only contain the foo and bar carrierCodes

Additional context

https://github.com/frasers-group/ec-fx-mach-config/actions/runs/13414512251/job/37472017464 -- the failing run

https://github.com/frasers-group/ec-fx-components/pull/5599 -- the code

@webwiebe webwiebe added bug Something isn't working triage Needs triage labels Feb 19, 2025
@demeyerthom demeyerthom removed the triage Needs triage label Feb 21, 2025
@demeyerthom demeyerthom self-assigned this Feb 21, 2025
@demeyerthom
Copy link
Member

demeyerthom commented Feb 21, 2025

Hi @webwiebe interesting case! Looks like commercetools does not support removing an enum value from a type: https://docs.commercetools.com/api/projects/types.

I don't think we want to cause a replace of the whole resource when a change happens here, as that would accidentally throw away all the previously stored data. So only thing I can do is add a better error message here

@webwiebe
Copy link
Author

Hi @demeyerthom, thanks for looking into this! I was afraid it would be a commercetools limitation, implementing cascading logic would be a big ask. We'll have to learn to live with the TODO enum value, unfortunate but not a big deal. :)

I left one comment on the PR, other than that I'm fine with closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants