DataDog / terraform-provider-datadog

Terraform Datadog provider
https://www.terraform.io/docs/providers/datadog/
Mozilla Public License 2.0
403 stars 379 forks source link

[Bug] `datadog_dashboard.slo_list_defintion` panics on plan, apply when in a`group_definition ` #1637

Closed dbanetto closed 2 years ago

dbanetto commented 2 years ago

Terraform Version

terraform 1.2.3 and terraform-provider-datadog v3.17.0

Affected Resource(s)

Please list the resources as a list, for example:

If this issue affects multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

resource "datadog_dashboard" "board" {
  layout_type = "ordered"
  notify_list = []
  reflow_type = "auto"
  title       = "test"

  widget {
    group_definition {
      layout_type = "ordered"
      widget {
        slo_list_definition {
          title = "SLOs"
          request {
            request_type = "slo_list"
            query {
              query_string = "env:prod"
              limit        = 10
            }
          }
        }
      }
    }
  }
}

Debug Output

When running a terraform import for a dashboard that includes the slo_list_definition widget

│ Error: object contains unparsed element: map[requests:[map[query:map[limit:10 query_string:env:prod] request_type:slo_list]] title:SLOs type:slo_list]

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Crash output from terraform (1.2.3) with terraform-provider-datadog v3.17.0 ```log Stack trace from the terraform-provider-datadog_v3.17.0 plugin: panic: [widget 0 group_definition 0 widget 0 slo_list_definition 0] doesn't end with [widget 0] goroutine 194 [running]: github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils.(*ResourceDataKey).Remove(0xc000c36f10, {0x1de92c0, 0xc001474a30}) github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils/key.go:63 +0x214 github.com/terraform-providers/terraform-provider-datadog/datadog.buildTerraformGroupDefinition({0x0, 0x0, {0xc000b79058, 0x7}, 0xc000b79075, 0xc0013c4190, 0x0, {0xc000b79070, 0x5}, {0xc0007d6700, ...}, ...}, ...) github.com/terraform-providers/terraform-provider-datadog/datadog/resource_datadog_dashboard.go:1353 +0x54a github.com/terraform-providers/terraform-provider-datadog/datadog.buildTerraformWidget({{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xc000b0cbd0, ...}, ...}, ...) github.com/terraform-providers/terraform-provider-datadog/datadog/resource_datadog_dashboard.go:1110 +0x29a5 github.com/terraform-providers/terraform-provider-datadog/datadog.buildTerraformWidgets(0xc000c372f8, 0xc0006f1380) github.com/terraform-providers/terraform-provider-datadog/datadog/resource_datadog_dashboard.go:1077 +0x225 github.com/terraform-providers/terraform-provider-datadog/datadog.updateDashboardState(0x2029ee0, 0xc000c37220) github.com/terraform-providers/terraform-provider-datadog/datadog/resource_datadog_dashboard.go:266 +0x31e github.com/terraform-providers/terraform-provider-datadog/datadog.resourceDatadogDashboardRead({0x2290160, 0xc00129a780}, 0xc0006f1380, {0x1d73be0, 0xc000908870}) github.com/terraform-providers/terraform-provider-datadog/datadog/resource_datadog_dashboard.go:312 +0x397 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0xc00019b880, {0x2290160, 0xc00129a780}, 0xd, {0x1d73be0, 0xc000908870}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.16.0/helper/schema/resource.go:724 +0x12e github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0xc00019b880, {0x2290160, 0xc00129a780}, 0xc00148e0d0, {0x1d73be0, 0xc000908870}) github.com/hashicorp/terraform-plugin-sdk/v2@v2.16.0/helper/schema/resource.go:1015 +0x585 github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc0003ca000, {0x22900b8, 0xc000c0c6c0}, 0xc000c0c740) github.com/hashicorp/terraform-plugin-sdk/v2@v2.16.0/helper/schema/grpc_provider.go:613 +0x574 github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc0003a4d20, {0x2290160, 0xc00129a1b0}, 0xc000a540c0) github.com/hashicorp/terraform-plugin-go@v0.9.0/tfprotov5/tf5server/server.go:746 +0x48c github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x1fdf660, 0xc0003a4d20}, {0x2290160, 0xc00129a1b0}, 0xc000a54060, 0x0) github.com/hashicorp/terraform-plugin-go@v0.9.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:349 +0x170 google.golang.org/grpc.(*Server).processUnaryRPC(0xc000230c40, {0x229f3a0, 0xc0007029c0}, 0xc00129c000, 0xc00058f650, 0x2de6870, 0x0) google.golang.org/grpc@v1.45.0/server.go:1282 +0xccf google.golang.org/grpc.(*Server).handleStream(0xc000230c40, {0x229f3a0, 0xc0007029c0}, 0xc00129c000, 0x0) google.golang.org/grpc@v1.45.0/server.go:1619 +0xa2a google.golang.org/grpc.(*Server).serveStreams.func1.2() google.golang.org/grpc@v1.45.0/server.go:921 +0x98 created by google.golang.org/grpc.(*Server).serveStreams.func1 google.golang.org/grpc@v1.45.0/server.go:919 +0x294 Error: The terraform-provider-datadog_v3.17.0 plugin crashed! ```

Expected Behavior

What should have happened?

Actual Behavior

What actually happened?

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

From the example terraform code above,

  1. terraform apply
    • Find the Dashboard in Datadog
  2. terraform plan
  3. terraform import datadog_dashboard.board <id>

Important Factoids

N/A

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

skarimo commented 2 years ago

Thanks, this is closed by https://github.com/DataDog/terraform-provider-datadog/pull/1624 and we just released 3.18.0 which includes this fix