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

Discrepancy in different CI pipeline when it comes to adding category #460

Closed
zoeyzou opened this issue Nov 28, 2023 · 2 comments · Fixed by #474
Closed

Discrepancy in different CI pipeline when it comes to adding category #460

zoeyzou opened this issue Nov 28, 2023 · 2 comments · Fixed by #474
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@zoeyzou
Copy link

zoeyzou commented Nov 28, 2023

There’s some bug in the TF registry as I noticed and hopefully can get some support from you. I created a new type def for category, it has a field that’s Set of String. The bug I encountered is, when I create a PR in our repo, GH actions keeps complaining element needs to be String, so I changed it to String, but in the master CI it then complains element needs to be Array. I have tried every possible way but maybe either I still did it wrong, or there is indeed some bug.

Type def

resource "commercetools_type" "category-exclusive-group-type" {
  key         = "category-exclusive-group-type"
  name        = { en = "Category exclusive group type" }
  description = { en = "Add exclusive group field to category" }

  resource_type_ids = ["category"]

  field {
    name = "exclusiveGroups"
    label = {
      en = "Exclusive group tags"
    }
    type {
      name = "Set"
      element_type {
        name = "String"
      }
    }
  }
}

I’ve tried the following way to define custom field when actually define category:

custom {
    type_id = "type"
    fields = {
      exclusiveGroups = ["genesis:Unity Editor"]
    }
  }

or

custom {
    type_id = commercetools_type.category-exclusive-group-type.id
    fields = {
      exclusiveGroups = ["genesis:Unity Editor"]
    }
  }

or

data "commercetools_type" "category-exclusive-group-type" {
  key = "category-exclusive-group-type"
}

custom {
    type_id = data.commercetools_type.category-exclusive-group-type.id
    fields = {
      exclusiveGroups = ["genesis:Unity Editor"]
    }
  }

None of them works. However using API or UI to create works, and the new type def is there:

{
  "name" : {
    "en" : "test"
  },
  "slug" : {
    "en" : "test"
  },
  "orderHint" : "1",
  "custom": {
      "type": {
          "typeId": "type",
          "key": "category-exclusive-group-type"
      },
      "fields": {
          "exclusiveGroups": ["genesis:Unity Editor"]
      }
  }
}

Let me know if you need more info

Screenshot 2023-11-24 at 13 54 33 Screenshot 2023-11-24 at 13 54 54
@zoeyzou zoeyzou added bug Something isn't working triage Needs triage labels Nov 28, 2023
@demeyerthom demeyerthom removed the triage Needs triage label Dec 15, 2023
@demeyerthom
Copy link
Member

Hi @zoeyzou thanks for reaching out!

Yeah, you ran into something we need to document a bit better here; because we don't know to what to encode a custom type in the provider we only allow for a map of key values as inputs in terraform. However, the way to work around this is to provide the input value as a json string instead. So in your case that would look like this:

resource "commercetools_category" "my-category" {
 key = "my-category-key"

 name = {
   en = "My category"
 }
 description = {
   en = "Standard description"
 }
 slug = {
   en = "my_category"
 }
 meta_title = {
   en = "Meta title"
 }

 custom {
   type_id = commercetools_type.category-exclusive-group-type.id
   fields  = {
     exclusiveGroups = jsonencode(["group1", "group2"])
   }
 }
}

I will expand on the documentation to make this a bit more clear.

@demeyerthom demeyerthom added documentation Improvements or additions to documentation and removed bug Something isn't working labels Dec 15, 2023
@zoeyzou
Copy link
Author

zoeyzou commented Jan 4, 2024

@demeyerthom Thanks Thomas, it works perfect now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
2 participants