sysdiglabs / terraform-provider-sysdig

Sysdig Terraform provider. Allow to handle Sysdig Secure policies as code.
https://registry.terraform.io/providers/sysdiglabs/sysdig/latest/docs
Mozilla Public License 2.0
47 stars 48 forks source link

sysdig_monitor_alert_metric crashes when using notification_channels #24

Closed logdnalf closed 4 years ago

logdnalf commented 4 years ago

The 0.2.0 Sysdig provider crashes when using the following Terraform code on macOS Catalina:

$ terraform version
Terraform v0.12.24
+ provider.sysdig v0.2.0

The code:

provider "sysdig" {
  sysdig_secure_api_token  = var.sysdig_api_token
  sysdig_monitor_api_token = var.sysdig_api_token
  version                  = "~> 0.2"
}

resource "sysdig_secure_notification_channel" "pagerduty" {
  enabled              = true
  name                 = "[TEST] PagerDuty integration with Sysdig"
  type                 = "PAGER_DUTY"
  account              = "account"
  service_key          = "XXXXXXXXXX..."
  service_name         = "sysdig"
  notify_when_ok       = true
  notify_when_resolved = true
}

resource "sysdig_monitor_alert_metric" "test_baremetal_buzzsaw_active_batches_high" {
  enabled               = true
  name                  = "[TEST] alert"
  description           = "Alert"
  severity              = 6
  metric                = "sum(min(X)) > 100000"
  scope                 = "kubernetes.cluster.name in (\"foo\")"
  trigger_after_minutes = 20
  notification_channels = [
    sysdig_secure_notification_channel.pagerduty.id,
  ]
  multiple_alerts_by = [
    "kubernetes.cluster.name",
    "group",
  ]
}

It crashes like this:

Plan: 1 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

sysdig_monitor_alert_metric.test_baremetal_buzzsaw_active_batches_high: Creating...

Error: rpc error: code = Unavailable desc = transport is closing

panic: interface conversion: interface {} is []interface {}, not []int
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: 
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: goroutine 15 [running]:
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: github.com/draios/terraform-provider-sysdig/sysdig.alertFromResourceData(0xc0000aabd0, 0xc0000ca3d0, 0xc0000ca3e0, 0x1a1ab80)
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0:   /home/fede/Documentos/Sysdig/terraform-provider-sysdig/sysdig/resource_sysdig_monitor_alert_common.go:102 +0x66a
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: github.com/draios/terraform-provider-sysdig/sysdig.metricAlertFromResourceData(0xc0000aabd0, 0xc0005dd1f0, 0x9, 0x252b718)
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0:   /home/fede/Documentos/Sysdig/terraform-provider-sysdig/sysdig/resource_sysdig_monitor_alert_metric.go:108 +0x40
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: github.com/draios/terraform-provider-sysdig/sysdig.resourceSysdigAlertMetricCreate(0xc0000aabd0, 0x19e9b20, 0xc000606400, 0x2, 0x252e600)
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0:   /home/fede/Documentos/Sysdig/terraform-provider-sysdig/sysdig/resource_sysdig_monitor_alert_metric.go:43 +0x7a
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Apply(0xc000122980, 0xc00008b9f0, 0xc0004572a0, 0x19e9b20, 0xc000606400, 0x1a7f501, 0xc0002bfeb8, 0xc000547ce0)
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0:   /home/fede/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.0.0/helper/schema/resource.go:305 +0x365
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Apply(0xc000122d00, 0xc0005dd8e0, 0xc00008b9f0, 0xc0004572a0, 0xc00012b948, 0xc00000e488, 0x1a81240)
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0:   /home/fede/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.0.0/helper/schema/provider.go:289 +0x99
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0xc000118048, 0x1e03860, 0xc000546210, 0xc000081080, 0xc000118048, 0xc000546210, 0xc000096a48)
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0:   /home/fede/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.0.0/internal/helper/plugin/grpc_provider.go:885 +0x882
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler(0x1b8b480, 0xc000118048, 0x1e03860, 0xc000546210, 0xc000081020, 0x0, 0x1e03860, 0xc000546210, 0xc0000c8c00, 0x3e2)
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0:   /home/fede/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk@v1.0.0/internal/tfplugin5/tfplugin5.pb.go:3189 +0x217
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000ac000, 0x1e0dea0, 0xc000702480, 0xc0000ee500, 0xc0003b9ef0, 0x24f4b80, 0x0, 0x0, 0x0)
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0:   /home/fede/go/pkg/mod/google.golang.org/grpc@v1.23.0/server.go:995 +0x460
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: google.golang.org/grpc.(*Server).handleStream(0xc0000ac000, 0x1e0dea0, 0xc000702480, 0xc0000ee500, 0x0)
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0:   /home/fede/go/pkg/mod/google.golang.org/grpc@v1.23.0/server.go:1275 +0xd3d
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc00011c040, 0xc0000ac000, 0x1e0dea0, 0xc000702480, 0xc0000ee500)
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0:   /home/fede/go/pkg/mod/google.golang.org/grpc@v1.23.0/server.go:710 +0xa1
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0: created by google.golang.org/grpc.(*Server).serveStreams.func1
2020-04-23T16:50:51.815+0200 [DEBUG] plugin.terraform-provider-sysdig_v0.2.0:   /home/fede/go/pkg/mod/google.golang.org/grpc@v1.23.0/server.go:708 +0xa1
2020/04/23 16:50:51 [DEBUG] sysdig_monitor_alert_metric.test_baremetal_buzzsaw_active_batches_high: apply errored, but we're indicating that via the Error pointer rather than returning it: rpc error: code = Unavailable desc = transport is closing
2020/04/23 16:50:51 [TRACE] <root>: eval: *terraform.EvalMaybeTainted
2020/04/23 16:50:51 [TRACE] EvalMaybeTainted: sysdig_monitor_alert_metric.test_baremetal_buzzsaw_active_batches_high encountered an error during creation, so it is now marked as tainted
2020/04/23 16:50:51 [TRACE] <root>: eval: *terraform.EvalWriteState
2020/04/23 16:50:51 [TRACE] EvalWriteState: removing state object for sysdig_monitor_alert_metric.test_baremetal_buzzsaw_active_batches_high
2020/04/23 16:50:51 [TRACE] <root>: eval: *terraform.EvalApplyProvisioners
2020/04/23 16:50:51 [TRACE] EvalApplyProvisioners: sysdig_monitor_alert_metric.test_baremetal_buzzsaw_active_batches_high has no state, so skipping provisioners
2020/04/23 16:50:51 [TRACE] <root>: eval: *terraform.EvalMaybeTainted
2020/04/23 16:50:51 [TRACE] EvalMaybeTainted: sysdig_monitor_alert_metric.test_baremetal_buzzsaw_active_batches_high encountered an error during creation, so it is now marked as tainted
2020/04/23 16:50:51 [TRACE] <root>: eval: *terraform.EvalWriteState
2020/04/23 16:50:51 [TRACE] EvalWriteState: removing state object for sysdig_monitor_alert_metric.test_baremetal_buzzsaw_active_batches_high
2020/04/23 16:50:51 [TRACE] <root>: eval: *terraform.EvalIf
2020/04/23 16:50:51 [TRACE] <root>: eval: *terraform.EvalIf
2020/04/23 16:50:51 [TRACE] <root>: eval: *terraform.EvalWriteDiff
2020/04/23 16:50:51 [TRACE] <root>: eval: *terraform.EvalApplyPost
2020/04/23 16:50:51 [ERROR] <root>: eval: *terraform.EvalApplyPost, err: rpc error: code = Unavailable desc = transport is closing
2020/04/23 16:50:51 [ERROR] <root>: eval: *terraform.EvalSequence, err: rpc error: code = Unavailable desc = transport is closing
2020/04/23 16:50:51 [TRACE] [walkApply] Exiting eval tree: sysdig_monitor_alert_metric.test_baremetal_buzzsaw_active_batches_high
2020-04-23T16:50:51.816+0200 [DEBUG] plugin: plugin process exited: path=/Users/solana/.terraform.d/plugins/terraform-provider-sysdig_v0.2.0 pid=23896 error="exit status 2"
2020/04/23 16:50:51 [TRACE] vertex "sysdig_monitor_alert_metric.test_baremetal_buzzsaw_active_batches_high": visit complete
2020/04/23 16:50:51 [TRACE] dag/walk: upstream of "provider.sysdig (close)" errored, so skipping
2020/04/23 16:50:51 [TRACE] dag/walk: upstream of "meta.count-boundary (EachMode fixup)" errored, so skipping
2020/04/23 16:50:51 [TRACE] dag/walk: upstream of "root" errored, so skipping
2020-04-23T16:50:51.817+0200 [DEBUG] plugin: plugin exited

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Terraform crashed! This is always indicative of a bug within Terraform.
A crash log has been placed at "crash.log" relative to your current
working directory. It would be immensely helpful if you could please
report the crash with Terraform[1] so that we can fix this.

When reporting bugs, please include your terraform version. That
information is available on the first line of crash.log. You can also
get it by running 'terraform --version' on the command line.

SECURITY WARNING: the "crash.log" file that was created may contain 
sensitive information that must be redacted before it is safe to share 
on the issue tracker.

[1]: https://github.com/hashicorp/terraform/issues

!!!!!!!!!!!!!!!!!!!!!!!!!!! TERRAFORM CRASH !!!!!!!!!!!!!!!!!!!!!!!!!!!!
make: *** [apply] Error 1
tembleking commented 4 years ago

Thanks for your feedback @logdnalf, I'll take a look at it asap

logdnalf commented 4 years ago

Please keep in mind that expanding the sysdig_secure_notification_channel.pagerduty.id expression to its integer ID extracted by running terraform show yields the same error. So it does not seem a problem that the channel ID is not an array of integers. It should be.