-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Ignore values in enums types in product type, named attributes #486
Comments
Hi @piran-cabiri thanks for reaching out! So if I can summarize your situation:
With regards to your additional points:
My main question here would be why use an enum at all? It sounds like (from the standpoint of Commercetools) this value is a simple text field. Is there a reason you want the extra check on allowed input here? Would it not be easier to just sync updates from this external system as text? |
Hi @demeyerthom. Your summary is accurate. W.r.t. to your main question: The principal reason is that these values are used to drive promotions. With a large number of values, it's easy for merchandisers make mistakes in setting up promotion rules. Storing as enums or a set of enums means that the promotions UI in Merchant Centre provides a searchable&clickable set of values and prevents mistakes: e.g., someone typing "addidas" instead of "adidas" (or in deed "Adidas"). We're less concerned about how a product itself appears in the Merchant Centre, as product data is managed in another system. I have been through Commercetools support to confirm they are happy with their end of the solution in terms of the number of enums and the frequency of update; they only worry was the effect on indexing for projections, but we use an external search tool. W.r.t. point 2, based on your description, if you moved the order to be a new property of the attribute in the terraform stored state, you could reconstruct the ordering, and perhaps allow reference by either name or number? I do not know enough of the TF internals to answer that. (Perhaps https://github.com/labd/terraform-provider-commercetools/blob/main/commercetools/resource_product_type.go#L273 and elsewhere?) |
Ok, the usecase is clear to me! I delved a bit further in the code to see what it was doing. Firstly we are comparing the names of attributes to get the right change sets, so the ordering should not be an issue as I implied earlier. We check the old and new list for existing attribute names, and process the changes accordingly. I tried out creating the resources with the An additional fix here to make it even more specific might be the following: lifecycle {
ignore_changes = [
attribute.0.type.0.value, # brand
attribute.1.type.0.element_type.0.value, # collections
]
} This should let you track everything except for the values of the fields With regards to the last one: changing this would change the API of the configuration, as the objects we specify are directly related to the way terraform stores the data. Changing these in any structural way basically means that the configuration would not be backwards compatible (unless we start hacking around it with migrations, something I don't want to do) |
We have a product type with some enums in them. The product data is fed by an external system, and so we add enum values to the product type when a new value appears.
Currently I define my product type like this:
Then if I add enum types via the API, with:
Now if I reapply the Terraform, the
ignore_changes
ignores the fact that I've added or deleted enum values. Brilliant!But there are a few niggles:
When I first create the attributes, I have to leave out the
lifecycle
segment. Somehow the attributes seems to get created correctly, and getting the product type it looks good, but the API call above gives the complaint that their ltext and not enums. Commenting out thelifecycle
fixes this.It'd be much nicer if I could name rather than number attributes, see below. Currently that fails to work correctly. I also tried
attribute["brand"].type
but it starts ignoring a lot more than just the type then. Using numbers makes it all very sensitive to someone else putting attributes in the wrong place.attribute.brand.type.value
), so I could see changes of type such as enum to/from set.I'm using commercetools provider 1.14.1, terraform 1.8.1, and terragrunt v0.55.5
The text was updated successfully, but these errors were encountered: