segmentio / terraform-provider-segment

Terraform provider for Segment, using the Public API
https://registry.terraform.io/providers/segmentio/segment/latest
MIT License
25 stars 3 forks source link

Crash when creating a resource from import block #52

Closed sco-at-scg closed 9 months ago

sco-at-scg commented 9 months ago

Description

Crash when creating a resource from import block

╷
│ Error: Plugin did not respond
│
│ The plugin encountered an error, and failed to respond to the plugin6.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-segment_v0.1.0 plugin:

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

goroutine 205 [running]:
github.com/segmentio/terraform-provider-segment/internal/provider/models.(*DestinationMetadataState).getActions(0x140001f47e0?, {0x14000170f00?, 0x6, 0x14000a97b50?})
        github.com/segmentio/terraform-provider-segment/internal/provider/models/destination_metadata.go:292 +0x178
github.com/segmentio/terraform-provider-segment/internal/provider/models.(*DestinationMetadataState).Fill(_, {{0x14000038ff0, 0x18}, {0x140005bae40, 0x1a}, {0x140005ea4e0, 0x2e}, {0x14000039008, 0x13}, {{0x140009544c0, ...}, ...}, ...})
        github.com/segmentio/terraform-provider-segment/internal/provider/models/destination_metadata.go:401 +0x170
github.com/segmentio/terraform-provider-segment/internal/provider/models.(*DestinationState).Fill(0x14000272380, 0x14000bacfe0)
        github.com/segmentio/terraform-provider-segment/internal/provider/models/destination.go:31 +0x7c
github.com/segmentio/terraform-provider-segment/internal/provider.(*destinationResource).Read(0x1400056e408, {0x102aede40, 0x14000510b40}, {{{{0x102af21b8, 0x14000593260}, {0x1029bd840, 0x140005dddd0}}, {0x102af4bb8, 0x140004ca000}}, 0x140004a4060, ...}, ...)
        github.com/segmentio/terraform-provider-segment/internal/provider/destination_resource.go:601 +0x338
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ReadResource(0x140002214a0, {0x102aede40, 0x14000510b40}, 0x14000510bd0, 0x14000bad5e0)
        github.com/hashicorp/terraform-plugin-framework@v1.4.0/internal/fwserver/server_readresource.go:101 +0x4a4
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ReadResource(0x140002214a0, {0x102aede40?, 0x14000510120?}, 0x14000bdc700)
        github.com/hashicorp/terraform-plugin-framework@v1.4.0/internal/proto6server/server_readresource.go:55 +0x1a4
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ReadResource(0x1400021b180, {0x102aede40?, 0x140006e3680?}, 0x140006510e0)
        github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov6/tf6server/server.go:787 +0x3e8
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ReadResource_Handler({0x102aae720?, 0x1400021b180}, {0x102aede40, 0x140006e3680}, 0x14000472310, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:431 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0x1400028e1e0, {0x102af3278, 0x140002a1a00}, 0x14000a10240, 0x140003f4030, 0x1030b7448, 0x0)
        google.golang.org/grpc@v1.57.0/server.go:1360 +0xc88
google.golang.org/grpc.(*Server).handleStream(0x1400028e1e0, {0x102af3278, 0x140002a1a00}, 0x14000a10240, 0x0)
        google.golang.org/grpc@v1.57.0/server.go:1737 +0x82c
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        google.golang.org/grpc@v1.57.0/server.go:982 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.57.0/server.go:980 +0x16c

Error: The terraform-provider-segment_v0.1.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.

To Reproduce

import {
  id = "123"
  to = segment_destination.dest1
}

resource "segment_destination" "dest1" {
  name      = "dest1"
  enabled   = true
  source_id = "456abc"

  metadata = {
    id = "abc123"
  }
  settings = jsonencode({
    "api_key" : "abcd-efgh"
  })
}
yaeba commented 9 months ago

similar issue, apparently it crashes when the existing destination has non-empty "actions"

deanhuynh commented 9 months ago

Thanks for raising our first issue! It should be fixed now 🙂

sco-at-scg commented 9 months ago

With the latest commit ff7bc07, the issue is still persisting, i.e.: for the destination: Google Analytics 4

goroutine 274 [running]:
github.com/segmentio/terraform-provider-segment/internal/provider/models.(*DestinationMetadataState).getContacts(0x0?, {0x140003d2780?, 0x1, 0x14000902230?})
        /tmp/dl/dev/github.com/segmentio/terraform-provider-segment/internal/provider/models/destination_metadata.go:240 +0x9c
github.com/segmentio/terraform-provider-segment/internal/provider/models.(*DestinationMetadataState).Fill(_, {{0x1400069acf0, 0x18}, {0x1400069ad50, 0x16}, {0x14000912780, 0x264}, {0x140007440c0, 0x1e}, {{0x14000780000, ...}, ...}, ...})
        /tmp/dl/dev/github.com/segmentio/terraform-provider-segment/internal/provider/models/destination_metadata.go:412 +0x334
github.com/segmentio/terraform-provider-segment/internal/provider/models.(*DestinationState).Fill(0x14000748070, 0x1400091f050)
        /tmp/dl/dev/github.com/segmentio/terraform-provider-segment/internal/provider/models/destination.go:31 +0x8c
github.com/segmentio/terraform-provider-segment/internal/provider.(*destinationResource).Read(0x14000702288, {0x1011d8ea8, 0x14000464f00}, {{{{0x1011dd430, 0x140007996b0}, {0x10109afc0, 0x14000799050}}, {0x1011e0168, 0x140000b8320}}, 0x14000088760, ...}, ...)
        /tmp/dl/dev/github.com/segmentio/terraform-provider-segment/internal/provider/destination_resource.go:600 +0x2e8
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ReadResource(0x1400018f080, {0x1011d8ea8, 0x14000464f00}, 0x14000464f90, 0x1400091f630)
        /tmp/go/pkg/mod/github.com/hashicorp/terraform-plugin-framework@v1.4.1/internal/fwserver/server_readresource.go:101 +0x514
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ReadResource(0x1400018f080, {0x1011d8ea8?, 0x14000464d80?}, 0x14000585000)
        /tmp/go/pkg/mod/github.com/hashicorp/terraform-plugin-framework@v1.4.1/internal/proto6server/server_readresource.go:55 +0x314
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ReadResource(0x140001f0780, {0x1011d8ea8?, 0x14000464510?}, 0x140004b24e0)
        /tmp/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov6/tf6server/server.go:787 +0x390
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ReadResource_Handler({0x101198060?, 0x140001f0780}, {0x1011d8ea8, 0x14000464510}, 0x140001d41c0, 0x0)
        /tmp/go/pkg/mod/github.com/hashicorp/terraform-plugin-go@v0.19.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:431 +0x164
google.golang.org/grpc.(*Server).processUnaryRPC(0x140001e81e0, {0x1011de998, 0x1400033a1a0}, 0x1400021d0e0, 0x1400032a0f0, 0x1017e9848, 0x0)
        /tmp/go/pkg/mod/google.golang.org/grpc@v1.57.0/server.go:1360 +0xc04
google.golang.org/grpc.(*Server).handleStream(0x140001e81e0, {0x1011de998, 0x1400033a1a0}, 0x1400021d0e0, 0x0)
        /tmp/go/pkg/mod/google.golang.org/grpc@v1.57.0/server.go:1737 +0x7c4
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        /tmp/go/pkg/mod/google.golang.org/grpc@v1.57.0/server.go:982 +0x84
created by google.golang.org/grpc.(*Server).serveStreams.func1 in goroutine 13
        /tmp/go/pkg/mod/google.golang.org/grpc@v1.57.0/server.go:980 +0x154

Error: The terraform-provider-segment.v0.1.0 plugin crashed!