nobl9/terraform-provider-nobl9

Plugin crashes while creating nobl9_slo

jon-rei opened this issue · 1 comments

Hey, I'm trying to create a new SLO with the nobl9_slo resource using terraform v1.4:

resource "nobl9_slo" "error_5xx" {
  name = "frontend-errors-5xx"
  display_name = "Frontend - Errors 5xx"
  service = "my-service"
  project = "my-project"
  budgeting_method = "Occurrences"


  label {
    key    = "team"
    values = ["my-team"]
  }

  time_window {
    unit       = "Day"
    count      = 14
    is_rolling = true
  }

  objective {
    display_name = "Good"
    target       = 0.99
    value        = 3
    op           = "lte"
    count_metrics {
      incremental = false
      good {
        cloudwatch {
          region      = "us-east-1"
          namespace   = "AWS/CloudFront"
          metric_name = "5xxErrorRate"
          stat        = "Average"
          dimensions {
            name  = "Region"
            value = "Global"
          }
          dimensions {
            name  = "DistrubutionId"
            value = "A1234567890"
          }
        }
      }
    }
  }

  indicator {
    name    = "my-name"
    kind    = "Direct"
    project = "my-project"
  }
}

After executing terraform the following error appears:

nobl9_slo.frontend_error_5xx: Creating...
╷
│ Error: Plugin did not respond
│ 
│   with nobl9_slo.frontend_error_5xx,
│   on slo.frontend.error-5xx.tf line 1, in resource "nobl9_slo" "frontend_error_5xx":
│    1: resource "nobl9_slo" "frontend_error_5xx" {
│ 
│ 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-nobl9_v0.9.0 plugin:

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

goroutine 42 [running]:
github.com/nobl9/terraform-provider-nobl9/nobl9.marshalCountMetrics(0x1780e00?)
        github.com/nobl9/terraform-provider-nobl9/nobl9/resource_slo.go:618 +0x25a
github.com/nobl9/terraform-provider-nobl9/nobl9.marshalThresholds(0x0?)
        github.com/nobl9/terraform-provider-nobl9/nobl9/resource_slo.go:582 +0x2e7
github.com/nobl9/terraform-provider-nobl9/nobl9.marshalSLO(0x186c7dc?)
        github.com/nobl9/terraform-provider-nobl9/nobl9/resource_slo.go:474 +0x245
github.com/nobl9/terraform-provider-nobl9/nobl9.resourceSLOApply({0x198d250, 0xc00010dec0}, 0x0?, {0x1822400?, 0xc00035e620})
        github.com/nobl9/terraform-provider-nobl9/nobl9/resource_slo.go:328 +0x15f
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0xc00044b7a0, {0x198d288, 0xc0003b48a0}, 0xd?, {0x1822400, 0xc00035e620})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.19.0/helper/schema/resource.go:707 +0x12e
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0xc00044b7a0, {0x198d288, 0xc0003b48a0}, 0xc0002149c0, 0xc00047e280, {0x1822400, 0xc00035e620})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.19.0/helper/schema/resource.go:837 +0xa7a
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0xc00042a228, {0x198d288?, 0xc0003b4780?}, 0xc0007303c0)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.19.0/helper/schema/grpc_provider.go:1021 +0xe3c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0xc0003dab40, {0x198d288?, 0xc00017dc50?}, 0xc0001b8070)
        github.com/hashicorp/terraform-plugin-go@v0.12.0/tfprotov5/tf5server/server.go:813 +0x4fc
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x1830840?, 0xc0003dab40}, {0x198d288, 0xc00017dc50}, 0xc0001b8000, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.12.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc000408000, {0x19902f0, 0xc0004824e0}, 0xc000012000, 0xc000421d70, 0x1e2e140, 0x0)
        google.golang.org/grpc@v1.48.0/server.go:1295 +0xb0b
google.golang.org/grpc.(*Server).handleStream(0xc000408000, {0x19902f0, 0xc0004824e0}, 0xc000012000, 0x0)
        google.golang.org/grpc@v1.48.0/server.go:1636 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        google.golang.org/grpc@v1.48.0/server.go:932 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
        google.golang.org/grpc@v1.48.0/server.go:930 +0x28a

Error: The terraform-provider-nobl9_v0.9.0 plugin crashed!

This error was my bad and I've incorrectly configured the terraform resource.
After changing the objective object to the following it worked correctly:

  objective {
    display_name = "Good"
    target       = 0.99
    value        = 3
    op           = "lte"
    raw_metric {
      query {
        cloudwatch {
          region      = "us-east-1"
          namespace   = "AWS/CloudFront"
          metric_name = "5xxErrorRate"
          stat        = "Average"
          dimensions {
            name  = "Region"
            value = "Global"
          }
          dimensions {
            name  = "DistrubutionId"
            value = "A1234567890"
          }
        }
      }
    }
  }