launchdarkly / terraform-provider-launchdarkly

Terraform LaunchDarkly provider
https://www.terraform.io/docs/providers/launchdarkly/
Mozilla Public License 2.0
22 stars 24 forks source link

Plugin crashes when trying to import a `launchdarkly_feature_flag_environment` #195

Open antoniogonca95 opened 6 months ago

antoniogonca95 commented 6 months ago

Hey,

When trying to import a launchdarkly_feature_flag_environment, I get the following error This error is happening on multiple flags, although I have imported a lot of them without any errors Any idea what could be causing this?

launchdarkly_feature_flag_environment.feature_flag_env["AB_REMOVE_DEPOSIT_BANNER_dev"]: Refreshing state... [id=default/dev/AB_REMOVE_DEPOSIT_BANNER]
╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to
│ the plugin.(*GRPCProvider).ReadResource call. The plugin
│ logs may contain more details.
╵

Stack trace from the terraform-provider-launchdarkly_v2.17.0 plugin:

panic: runtime error: index out of range [1] with length 1

goroutine 1658 [running]:
github.com/launchdarkly/terraform-provider-launchdarkly/launchdarkly.rolloutsToResourceData(...)
        github.com/launchdarkly/terraform-provider-launchdarkly/launchdarkly/rollout_helper.go:50
github.com/launchdarkly/terraform-provider-launchdarkly/launchdarkly.fallthroughToResourceData({0x0?, 0xc000502500?})
        github.com/launchdarkly/terraform-provider-launchdarkly/launchdarkly/fallthrough_helper.go:116 +0x34d
github.com/launchdarkly/terraform-provider-launchdarkly/launchdarkly.featureFlagEnvironmentRead({0x1185100?, 0xc000694090?}, 0x1832680?, {0xe2cfa0?, 0xc00026e0a0}, 0x0)
        github.com/launchdarkly/terraform-provider-launchdarkly/launchdarkly/feature_flag_environment_helper.go:155 +0x129f
github.com/launchdarkly/terraform-provider-launchdarkly/launchdarkly.resourceFeatureFlagEnvironmentRead({0x11850c8?, 0xc000a8d440?}, 0x0?, {0xe2cfa0?, 0xc00026e0a0?})
        github.com/launchdarkly/terraform-provider-launchdarkly/launchdarkly/resource_launchdarkly_feature_flag_environment.go:135 +0x30
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc0003b00e0, {0x1185100, 0xc000694090}, 0xd?, {0xe2cfa0, 0xc00026e0a0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/resource.go:750 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc0003b00e0, {0x1185100, 0xc000694090}, 0xc000517e10, {0xe2cfa0, 0xc00026e0a0})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/resource.go:1044 +0x59e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc0000113e0, {0x1185100?, 0xc00065ad20?}, 0xc00020cdc0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/grpc_provider.go:616 +0x4a5
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.muxServer.ReadResource({0xc0003dcc90, 0xc000505640, 0xc0003dccc0, 0xc0003dccf0, {0xc0003d4640, 0x2, 0x2}}, {0x1185100?, 0xc00065a9f0?}, 0xc00020cdc0)
        github.com/hashicorp/terraform-plugin-mux@v0.11.1/tf5muxserver/mux_server_ReadResource.go:29 +0x139
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc0003cf720, {0x1185100?, 0xc00065a030?}, 0xc000a8d140)
        github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/tf5server/server.go:751 +0x4b1
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0xf9d060?, 0xc0003cf720}, {0x1185100, 0xc00065a030}, 0xc0002d01c0, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:386 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001d01e0, {0x118a600, 0xc0003cd860}, 0xc0005f0ea0, 0xc00047cb40, 0x18240d0, 0x0)
        google.golang.org/grpc@v1.56.3/server.go:1335 +0xdf0
google.golang.org/grpc.(*Server).handleStream(0xc0001d01e0, {0x118a600, 0xc0003cd860}, 0xc0005f0ea0, 0x0)
        google.golang.org/grpc@v1.56.3/server.go:1712 +0xa2f
google.golang.org/grpc.(*Server).serveStreams.func1.1()
        google.golang.org/grpc@v1.56.3/server.go:947 +0xca
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.56.3/server.go:958 +0x15c

Error: The terraform-provider-launchdarkly_v2.17.0 plugin crashed!
antoniogonca95 commented 6 months ago

after some investigation, it seems like the problem resides in what the api returns: for this flag, it returns rollout.variations with a length of 1, but when it tries to create the transformed object here, it accesses a range that doesn't exist, as the variation value is set to 1 we have archived these flags as they aren't used anymore, so the problem was "solved", but perhaps it could still be helpful to investigate this

sunnyguduru commented 6 months ago

HI @antoniogonca95. Could you tell me more about the problematic flags you archived. Was it a boolean flag? How many variations did it have? Also in the rollout percentage was one one variation set to 100%? I tried all of these things on my end and was unable to reproduce it so far.

antoniogonca95 commented 5 months ago

hey, if I remember correctly it was a string feature flag, with three variations, with the rollout percentage set to 100% in one of them