launchdarkly / terraform-provider-launchdarkly

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

Cannot create flag_trigger that is enabled #81

Closed jeffWelling closed 2 years ago

jeffWelling commented 2 years ago

Hello there!

If I create a trigger as such:

resource "launchdarkly_flag_trigger" "example1" {
    project_key = data.launchdarkly_project.project.key
    env_key = data.launchdarkly_environment.env.key
    flag_key = launchdarkly_feature_flag.flag.key
    integration_key = "generic-trigger"
    instructions {
        kind = "turnFlagOn"
    }
    enabled = false
}

Then the trigger is created as expected in the disabled state. However, if I try to create an enabled trigger, I get a panic and a stacktrace.

│ 
│   with module.test.launchdarkly_flag_trigger.example1,
│   on ../../main.tf line 16, in resource "launchdarkly_flag_trigger" "example1":
│   16: resource "launchdarkly_flag_trigger" "example1" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain more details.
╵

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

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

goroutine 60 [running]:
github.com/launchdarkly/terraform-provider-launchdarkly/launchdarkly.resourceFlagTriggerCreate(0x1c71d48, 0xc000111260, 0xc000145280, 0x19b9760, 0xc0001d0440, 0xc000285d10, 0x16b406a, 0xc000145100)
    github.com/launchdarkly/terraform-provider-launchdarkly/launchdarkly/resource_launchdarkly_flag_trigger.go:64 +0x890
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc000235ea0, 0x1c71cd8, 0xc000316740, 0xc000145280, 0x19b9760, 0xc0001d0440, 0x0, 0x0, 0x0)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.0/helper/schema/resource.go:341 +0x17f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc000235ea0, 0x1c71cd8, 0xc000316740, 0xc00022e750, 0xc000145100, 0x19b9760, 0xc0001d0440, 0x0, 0x0, 0x0, ...)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.0/helper/schema/resource.go:467 +0x67b
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00000d320, 0x1c71cd8, 0xc000316740, 0xc0002dc320, 0x1b4c5e1, 0x12, 0x0)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.10.0/helper/schema/grpc_provider.go:977 +0xacf
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc000056780, 0x1c71d80, 0xc000316740, 0xc0003a2000, 0x0, 0x0, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/tf5server/server.go:603 +0x465
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x1afe8e0, 0xc000056780, 0x1c71d80, 0xc0001b80f0, 0xc000110360, 0x0, 0x1c71d80, 0xc0001b80f0, 0xc00010c380, 0x1a7)
    github.com/hashicorp/terraform-plugin-go@v0.5.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:380 +0x214
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00041fdc0, 0x1c79398, 0xc000103200, 0xc000224000, 0xc000458570, 0x21cdf60, 0x0, 0x0, 0x0)
    google.golang.org/grpc@v1.42.0/server.go:1282 +0x52b
google.golang.org/grpc.(*Server).handleStream(0xc00041fdc0, 0x1c79398, 0xc000103200, 0xc000224000, 0x0)
    google.golang.org/grpc@v1.42.0/server.go:1616 +0xd0c
google.golang.org/grpc.(*Server).serveStreams.func1.2(0xc00040e1d0, 0xc00041fdc0, 0x1c79398, 0xc000103200, 0xc000224000)
    google.golang.org/grpc@v1.42.0/server.go:921 +0xab
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.42.0/server.go:919 +0x1fd

Error: The terraform-provider-launchdarkly_v2.4.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.

2022-01-20T17:14:22.090-0800 [DEBUG] provider: plugin exited

It looks like the enabled line can be omitted because it defaults to an enabled state, but when I try that I'm told the enabled argument is not optional.

│ 
│   on ../../main.tf line 16, in resource "launchdarkly_flag_trigger" "example1":
│   16: resource "launchdarkly_flag_trigger" "example1" {
│ 
│ The argument "enabled" is required, but no definition was found.

Is it possible to create a trigger filter via terraform that is enabled from the start? Through trial and error I've found that I can create a disabled trigger and then enable it through a second run of terraform but the ideal use case would be for one terraform apply to be sufficient hehe.

My versions: Terraform v1.0.0 on darwin_amd64

I'm on MacOS 11.6.1

Thank you kindly in advance for your help!

sloloris commented 2 years ago

Hi @jeffWelling,

Thank you so much for bringing this to our attention! We will be looking into this ASAP.

ldhenry commented 2 years ago

Hey @jeffWelling, we just released a fix for this issue in v2.4.1. Thanks for bringing this to our attention.