labd / terraform-provider-commercetools

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

commercetools_shipping_zone_rate breaks with nilpointer exception #518

Closed demeyerthom closed 2 months ago

demeyerthom commented 2 months ago

Example terraform

resource "commercetools_tax_category" "standard" {
  name = "Standard tax rates"
  key  = "standard-tax-rate"
}

resource "commercetools_shipping_method" "tiered" {
  name            = "Tiered shipping method"
  key             = "TIERED"
  description     = "Tiered shipping method"
  is_default      = false
  tax_category_id = commercetools_tax_category.standard.id
  predicate       = "1 = 1"
}

resource "commercetools_shipping_zone" "shipping_zone" {
  name = "Netherlands"
  location {
    country = "DE"
  }
}

resource "commercetools_shipping_zone_rate" "tiered" {
  shipping_method_id = commercetools_shipping_method.tiered.id
  shipping_zone_id   = commercetools_shipping_zone.shipping_zone.id
  price {
    cent_amount   = 5000
    currency_code = "EUR"
  }

  shipping_rate_price_tier {
    type                = "CartValue"
    minimum_cent_amount = 50000
    price {
      cent_amount   = 9500
      currency_code = "EUR"
    }
  }
}
Stack trace from the terraform-provider-commercetools_v1.15.0 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x114f809]

goroutine 114 [running]:
github.com/labd/terraform-provider-commercetools/commercetools.setShippingZoneRateState(0xc000517000, 0x17bf520?)
        github.com/labd/terraform-provider-commercetools/commercetools/resource_shipping_zone_rate.go:448 +0x2e9
github.com/labd/terraform-provider-commercetools/commercetools.resourceShippingZoneRateRead({0x17bf520, 0xc00031b5e0}, 0xc000517000, {0x16095c0?, 0xc00013d698})
        github.com/labd/terraform-provider-commercetools/commercetools/resource_shipping_zone_rate.go:251 +0x33c
github.com/labd/terraform-provider-commercetools/commercetools.resourceShippingZoneRateCreate({0x17bf520?, 0xc00031b5e0}, 0x0?, {0x16095c0?, 0xc00013d698})
        github.com/labd/terraform-provider-commercetools/commercetools/resource_shipping_zone_rate.go:235 +0xa07
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc00032f500, {0x17bf478, 0xc000545ad0}, 0xd?, {0x16095c0, 0xc00013d698})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:806 +0x11b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc00032f500, {0x17bf478, 0xc000545ad0}, 0xc0000d64e0, 0xc000516e80, {0x16095c0, 0xc00013d698})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:937 +0xa89
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc0000119b0, {0x17bf478?, 0xc0005459e0?}, 0xc0002a14a0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:1153 +0xdbc
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(*muxServer).ApplyResourceChange(0x17bf4b0?, {0x17bf478?, 0xc000545650?}, 0xc0002a14a0)
        github.com/hashicorp/terraform-plugin-mux@v0.16.0/tf5muxserver/mux_server_ApplyResourceChange.go:36 +0x193
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0002a9ea0, {0x17bf478?, 0xc000544d20?}, 0xc00031aee0)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/tf5server/server.go:865 +0x3d0
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x15cd200?, 0xc0002a9ea0}, {0x17bf478, 0xc000544d20}, 0xc000516b00, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:518 +0x169
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001d1000, {0x17bf478, 0xc000544c90}, {0x17c5560, 0xc0004fc000}, 0xc00054e6c0, 0xc000353ec0, 0x20b84b8, 0x0)
        google.golang.org/grpc@v1.63.2/server.go:1369 +0xe23
google.golang.org/grpc.(*Server).handleStream(0xc0001d1000, {0x17c5560, 0xc0004fc000}, 0xc00054e6c0)
        google.golang.org/grpc@v1.63.2/server.go:1780 +0x1016
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.63.2/server.go:1019 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 35
        google.golang.org/grpc@v1.63.2/server.go:1030 +0x135

Error: The terraform-provider-commercetools_v1.15.0 plugin crashed!

This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
vladide commented 2 months ago

Seems mine is similar : https://github.com/labd/terraform-provider-commercetools/issues/519