SumoLogic / terraform-provider-sumologic

Terraform provider for Sumo Logic
https://www.terraform.io/docs/providers/sumologic/
Mozilla Public License 2.0
36 stars 52 forks source link

How can we use default values for Monitor resolution block instead of having to explicitly define them? #661

Open rc-marina opened 2 weeks ago

rc-marina commented 2 weeks ago

Hello,

I am trying to do a minimal translation to convert old scheduled searches to the newer monitors. As such, I want to simply define the alerting threshold, threshold_type, and time_range fields and use the default resolution values that Monitor would come up with.

For example, in the web interface, the recovery/resolution values default based on the alerting conditions:

image

However, The SumoLogic provider (version 2.30.0) appears to force me to explicitly set the resolution values myself. If I do not specify a resolution block, I get the following error when I run terraform plan:

│
│   on test-monitor.tf line 18, in resource "sumologic_monitor" "TestMonitor":
│   18:         critical {
│
│ At least 1 "resolution" blocks are required.

If I provide an empty resolution block, I get a plugin error when I run terraform apply:

sumologic_monitor.Monitor_Infra_Alert_Test: Creating...
╷
│ Error: Plugin did not respond
│
│   with sumologic_monitor.TestMonitor,
│   on test-monitor.tf line 1, in resource "sumologic_monitor" "TestMonitor":
│    1: resource "sumologic_monitor" "TestMonitor" {
│
│ 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-sumologic_v2.30.0 plugin:

panic: interface conversion: interface {} is nil, not map[string]interface {}

goroutine 35 [running]:
github.com/SumoLogic/terraform-provider-sumologic/sumologic.fromSingletonArray(0x14000c04fc0, {0x1031a61a9, 0xa})
    github.com/SumoLogic/terraform-provider-sumologic/sumologic/resource_sumologic_monitors_library_monitor.go:1802 +0x2d4
github.com/SumoLogic/terraform-provider-sumologic/sumologic.TriggerCondition.cloneReadingFromNestedBlocks({{0x0, 0x0}, {0x0, 0x0}, 0x0, {0x0, 0x0}, {0x0, 0x0}, 0x0, ...}, ...)
    github.com/SumoLogic/terraform-provider-sumologic/sumologic/resource_sumologic_monitors_library_monitor.go:1720 +0x1d0
github.com/SumoLogic/terraform-provider-sumologic/sumologic.logsStaticConditionBlockToJson(...)
    github.com/SumoLogic/terraform-provider-sumologic/sumologic/resource_sumologic_monitors_library_monitor.go:1102
github.com/SumoLogic/terraform-provider-sumologic/sumologic.triggerConditionsBlockToJson(0x14000c04d80)
    github.com/SumoLogic/terraform-provider-sumologic/sumologic/resource_sumologic_monitors_library_monitor.go:1070 +0x10c
github.com/SumoLogic/terraform-provider-sumologic/sumologic.getTriggers(0x1400044d420)
    github.com/SumoLogic/terraform-provider-sumologic/sumologic/resource_sumologic_monitors_library_monitor.go:1043 +0xd0
github.com/SumoLogic/terraform-provider-sumologic/sumologic.resourceToMonitorsLibraryMonitor(0x1400044d420)
    github.com/SumoLogic/terraform-provider-sumologic/sumologic/resource_sumologic_monitors_library_monitor.go:1550 +0x68
github.com/SumoLogic/terraform-provider-sumologic/sumologic.resourceSumologicMonitorsLibraryMonitorCreate(0x1400044d420, {0x10372ec80, 0x1400010d4a0})
    github.com/SumoLogic/terraform-provider-sumologic/sumologic/resource_sumologic_monitors_library_monitor.go:741 +0xe0
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).Apply(0x1400061b680, 0x14000db3180, 0x140005a2f80, {0x10372ec80, 0x1400010d4a0})
    github.com/hashicorp/terraform-plugin-sdk@v1.17.2/helper/schema/resource.go:320 +0x528
github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).Apply(0x140000e4580, 0x14000369960, 0x14000db3180, 0x140005a2f80)
    github.com/hashicorp/terraform-plugin-sdk@v1.17.2/helper/schema/provider.go:294 +0x88
github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ApplyResourceChange(0x14000116760, {0x103765190, 0x140008f6510}, 0x1400044c0e0)
    github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/helper/plugin/grpc_provider.go:895 +0x8cc
github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x1036f51c0, 0x14000116760}, {0x103765190, 0x140008f6510}, 0x1400044c070, 0x0)
    github.com/hashicorp/terraform-plugin-sdk@v1.17.2/internal/tfplugin5/tfplugin5.pb.go:3305 +0x1c0
google.golang.org/grpc.(*Server).processUnaryRPC(0x1400055a000, {0x1037771c0, 0x14000703040}, 0x14000986000, 0x140008c7a70, 0x103f903a0, 0x0)
    google.golang.org/grpc@v1.57.1/server.go:1358 +0xeb8
google.golang.org/grpc.(*Server).handleStream(0x1400055a000, {0x1037771c0, 0x14000703040}, 0x14000986000, 0x0)
    google.golang.org/grpc@v1.57.1/server.go:1735 +0xa34
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.57.1/server.go:970 +0xd8
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.57.1/server.go:981 +0x198

Error: The terraform-provider-sumologic_v2.30.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.

According to the API docs, LogsStaticCondition does not appear to require resolution specific threshold or thresholdType value, so I was hoping I could ommit them in Terraform: Pasted_Image_6_12_24__1_00_PM

Is there any way I can create a Monitor through Terraform without having to work out the resolution threshold and thresholdType? (There are multiple Schedule Searches I am trying to convert into Monitor)