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

Terraform plan inaccurate output when removing attributes to product types #508

Open
elachance1 opened this issue Jul 11, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@elachance1
Copy link

Version information

  • terraform: 1.9.2
  • terraform provider: 1.14.3

Describe the bug

There seems to be a bug with the terraform plan when removing attributes of product type when they are not the last one in the file. (I haven't tried with other ressources)

To Reproduce

  1. Execute terraform apply with the following product type :
resource "commercetools_product_type" "my-product-type" {
  key         = "my-product-type"
  name        = "My Product Type"
  description = "My Product Type Description"
 
  attribute {
    name = "my-first-attribute"
    label = {
      en-US = "My First Attribute"
    }
    required = true
    type {
      name = "text"
    }
    constraint = "SameForAll"
    searchable = true
    input_hint = "SingleLine"
  }
 
  attribute {
    name = "my-second-attribute"
    label = {
      en-US = "My Second Attribute"
    }
    required = true
    type {
      name = "text"
    }
    constraint = "SameForAll"
    searchable = true
    input_hint = "SingleLine"
  }
}
  1. Remove the first attribute. You should end up with a file like this :
resource "commercetools_product_type" "my-product-type" {
  key         = "my-product-type"
  name        = "My Product Type"
  description = "My Product Type Description"
 
  attribute {
    name = "my-second-attribute"
    label = {
      en-US = "My Second Attribute"
    }
    required = true
    type {
      name = "text"
    }
    constraint = "SameForAll"
    searchable = true
    input_hint = "SingleLine"
  }
}
  1. Execute a terraform plan

  2. Terraform will give the following output :

Terraform will perform the following actions:
  # commercetools_product_type.my-product-type will be updated in-place
  ~ resource "commercetools_product_type" "my-product-type" {
        id          = "NOT_IMPORTANT_GENERATED_UUID_FOR_MY_RESSOURCE"
        name        = "My Product Type"
        # (3 unchanged attributes hidden)
      ~ attribute {
          ~ label      = {
              ~ "en-US" = "My First Attribute" -> "My Second Attribute"
            }
          ~ name       = "my-first-attribute" -> "my-second-attribute"
            # (5 unchanged attributes hidden)
            # (1 unchanged block hidden)
        }
      - attribute {
          - constraint = "SameForAll" -> null
          - input_hint = "SingleLine" -> null
          - input_tip  = {} -> null
          - label      = {
              - "en-US" = "My Second Attribute"
            } -> null
          - name       = "my-second-attribute" -> null
          - required   = true -> null
          - searchable = true -> null
          - type {
              - name = "text" -> null
            }
        }
    }
Plan: 0 to add, 1 to change, 0 to destroy.

The plan is misleading. It does not rename the first attribute into the second attribute. Otherwise, there should be inconsistencies with the data after the apply (second attribute should end up with the first attribute data) if the plan was accurate. But, it actually remove the first attribute as expected on CommerceTools.

Expected behavior

I would expect the same behaviour as we remove the last attribute of the file. Here is an example of the output we get when we remove the last attribute :

Terraform will perform the following actions:
  # commercetools_product_type.my-product-type will be updated in-place
  ~ resource "commercetools_product_type" "my-product-type" {
        id          = "NOT_IMPORTANT_GENERATED_UUID_FOR_MY_RESSOURCE"
        name        = "My Product Type"
        # (3 unchanged attributes hidden)
      - attribute {
          - constraint = "SameForAll" -> null
          - input_hint = "SingleLine" -> null
          - input_tip  = {} -> null
          - label      = {
              - "en-US" = "My Second Attribute"
            } -> null
          - name       = "my-second-attribute" -> null
          - required   = true -> null
          - searchable = true -> null
          - type {
              - name = "text" -> null
            }
        }
        # (1 unchanged block hidden)
    }
Plan: 0 to add, 1 to change, 0 to destroy.
@elachance1 elachance1 added bug Something isn't working triage Needs triage labels Jul 11, 2024
@demeyerthom
Copy link
Member

Hi @elachance1 I think this happens because we store the attributes as a slice of structs, so when storing the data terraform sees that the attribute at position 0 (was first attribute, now second attribute) has changed instead of correctly deducing that the attribute at 0 was removed.

I will have to dive in to this to see how to fix it

@demeyerthom demeyerthom removed the triage Needs triage label Jul 19, 2024
@sgoian
Copy link

sgoian commented Sep 26, 2024

Do you happen to have any updates on this one? It's a nasty one causing us serious headaches.

@rawwebdesign
Copy link

Also looking for an update on this one. Thank you!

@demeyerthom demeyerthom self-assigned this Oct 22, 2024
@stanislavhordiyenko
Copy link
Contributor

Hello, started a POC with this terraform provider and also faced with this issue. Decided to postpone all activities until this issue is resolved.

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

When branches are created from issues, their pull requests are automatically linked.

5 participants