elastic / terraform-provider-elasticstack

Terraform provider for Elastic Stack
https://registry.terraform.io/providers/elastic/elasticstack/latest/docs
Apache License 2.0
173 stars 93 forks source link

[Bug] Defend for Containers - The terraform-provider-elasticstack_v0.11.9 plugin crashed #907

Open doom160 opened 3 weeks ago

doom160 commented 3 weeks ago

Describe the bug I am trying to create defend for container integration with default settings and it is throwing these errors. I went to the UI, the integration was created successfully. doesnt look like i have passed the wrong variables?

To Reproduce Steps to reproduce the behavior:

  1. terraform apply
  2. See the error in the output '...'

Expected behavior

resource "elasticstack_fleet_integration" "defend" {
  name    = "cloud_defend"
  version = "1.2.6"
  force   = true
  skip_destroy = true
}

resource "elasticstack_fleet_integration_policy" "defend" {
  name                = "test"
  namespace           = "default"
  description         = "test"
  enabled             = true
  agent_policy_id     = var.agent_policy_id
  integration_name    = elasticstack_fleet_integration.defend.name
  integration_version = elasticstack_fleet_integration.defend.version

  input {
    input_id = "cloud_defend-cloud_defend/control"
    enabled  = true
    vars_json = jsonencode({"configuration": var.integration_yaml})
    streams_json = jsonencode({
        "cloud_defend.alerts": {
         "enabled": true
        },
        "cloud_defend.file": {
          "enabled": true
        },
        "cloud_defend.heartbeat": {
          "enabled":  true,
          "vars": {
            "period": "30m"
          }
        },
        "cloud_defend.metrics": {
          "enabled": true,
          "vars": {
            "period": "24h"
          }
        },
        "cloud_defend.process": {
          "enabled": true
        }
      })
  }
}

variable "integration_yaml"{
    default = <<EOF
process:
  selectors:
    - name: allProcesses
      operation: [fork, exec]
  responses:
    - match: [allProcesses]
      actions: [log]
file:
  selectors:
    - name: executableChanges
      operation: [createExecutable, modifyExecutable]
  responses:
    - match: [executableChanges]
      actions: [alert]
EOF
    type = string
    description = "Defend for Elastic YAML Configuration"
}

Debug output Run terraform command with TF_LOG=trace and provide extended information on TF operations. Please ensure you redact any base64 encoded credentials from your output. eg

╷
│ Error: Plugin did not respond
│ 
│ The plugin encountered an error, and failed to respond to the plugin6.(*GRPCProvider).ApplyResourceChange call. The plugin logs may contain
│ more details.
╵
Stack trace from the terraform-provider-elasticstack_v0.11.9 plugin:

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

goroutine 177 [running]:
github.com/elastic/terraform-provider-elasticstack/internal/fleet/integration_policy.HandleRespSecrets({0x5062058, 0xc000825950}, 0xc000372070, {0x505d1e8, 0xc0001ec030})
        github.com/elastic/terraform-provider-elasticstack/internal/fleet/integration_policy/secrets.go:108 +0x306
github.com/elastic/terraform-provider-elasticstack/internal/fleet/integration_policy.(*integrationPolicyResource).Read(0xc0001ec008, {0x5062058, 0xc000825950}, {{{{0x50688f8, 0xc000811b30}, {0x4e57bc0, 0xc000811770}}, {0x506b960, 0xc0008260f0}}, 0xc0001ec030, ...}, ...)
        github.com/elastic/terraform-provider-elasticstack/internal/fleet/integration_policy/read.go:37 +0x2b9
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ReadResource(0xc00026e1e0, {0x5062058, 0xc000825950}, 0xc0008259b0, 0xc000053590)
        github.com/hashicorp/terraform-plugin-framework@v1.12.0/internal/fwserver/server_readresource.go:117 +0x84e
github.com/hashicorp/terraform-plugin-framework/internal/proto6server.(*Server).ReadResource(0xc00026e1e0, {0x5062058?, 0xc000825860?}, 0xc000516480)
        github.com/hashicorp/terraform-plugin-framework@v1.12.0/internal/proto6server/server_readresource.go:55 +0x38e
github.com/hashicorp/terraform-plugin-mux/tf6muxserver.(*muxServer).ReadResource(0xc000372460, {0x5062058?, 0xc000825590?}, 0xc000516480)
        github.com/hashicorp/terraform-plugin-mux@v0.16.0/tf6muxserver/mux_server_ReadResource.go:35 +0x193
github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server.(*server).ReadResource(0xc000366780, {0x5062058?, 0xc0008241b0?}, 0xc00021e070)
        github.com/hashicorp/terraform-plugin-go@v0.24.0/tfprotov6/tf6server/server.go:784 +0x2f3
github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6._Provider_ReadResource_Handler({0x4ffefa0, 0xc000366780}, {0x5062058, 0xc0008241b0}, 0xc00079a000, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.24.0/tfprotov6/internal/tfplugin6/tfplugin6_grpc.pb.go:509 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc00019d200, {0x5062058, 0xc000824120}, {0x5069fa0, 0xc00035b6c0}, 0xc00089cc60, 0xc000426480, 0x5d153e8, 0x0)
        google.golang.org/grpc@v1.66.2/server.go:1394 +0xe2b
google.golang.org/grpc.(*Server).handleStream(0xc00019d200, {0x5069fa0, 0xc00035b6c0}, 0xc00089cc60)
        google.golang.org/grpc@v1.66.2/server.go:1805 +0xe8b
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.66.2/server.go:1029 +0x7f
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 17
        google.golang.org/grpc@v1.66.2/server.go:1040 +0x125

Error: The terraform-provider-elasticstack_v0.11.9 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.

Screenshots If applicable, add screenshots to help explain your problem.

Versions (please complete the following information):

Additional context Add any other context about the problem here.