jfrog / terraform-provider-xray

Terraform provider to manage JFrog Xray
https://jfrog.com/xray/
Apache License 2.0
149 stars 12 forks source link

xray_violations report crashes without a security_filters nested block #95

Closed RobertBlumen closed 1 year ago

RobertBlumen commented 1 year ago

Describe the bug terraform documentation indicates that the security_filters nested block in the filters block of xray_violations_report is optional. Without a security_filters the provider crashes,

Requirements for and issue Code snippet

resource "xray_violations_report" "report" {
  name = "violations"
  resources {
    dynamic "repository" {
      for_each = local.repos_watched_local
      content {
        name                  = repository.value
        include_path_patterns = [".*"]
        exclude_path_patterns = []
      }
    }
  }

  filters {
    type           = "security"
    severities     = ["High", "Medium"]
    watch_patterns = [".*"]
    policy_names = [
      "my-policy"
    ]

    updated {
      start = local.scan_start_date
      end   = local.scan_end_date
    }

    license_filters {
      unknown      = true
      unrecognized = true
    }
  }
}

Expected behavior

Additional context

Error: Plugin did not respond
│ 
│   with xray_violations_report.report,
│   on xray-reports.tf line 53, in resource "xray_violations_report" "report":
│   53: resource "xray_violations_report" "report" {
│ 
│ 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-xray_v1.9.5 plugin:

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

goroutine 16 [running]:
github.com/jfrog/terraform-provider-xray/pkg/xray.unpackViolationsSecurityFilters(0x100e5bae0?)
    github.com/jfrog/terraform-provider-xray/pkg/xray/reports.go:481 +0x324
github.com/jfrog/terraform-provider-xray/pkg/xray.unpackViolationsFilters(0x140004d4db8?)
    github.com/jfrog/terraform-provider-xray/pkg/xray/reports.go:533 +0x598
github.com/jfrog/terraform-provider-xray/pkg/xray.unpackReport(0x140004d4e38?, {0x100c96d4b, 0xa})
    github.com/jfrog/terraform-provider-xray/pkg/xray/reports.go:305 +0x2f0
github.com/jfrog/terraform-provider-xray/pkg/xray.createReport({0x100c96d4b, 0xa}, 0x100689b70?, {0x100f28660?, 0x140002d8000})
    github.com/jfrog/terraform-provider-xray/pkg/xray/reports.go:672 +0x54
github.com/jfrog/terraform-provider-xray/pkg/xray.resourceXrayViolationsReportCreate({0x100c99489?, 0xe?}, 0x140004d4ef8?, {0x100f28660?, 0x140002d8000?})
    github.com/jfrog/terraform-provider-xray/pkg/xray/reports.go:620 +0x34
github.com/jfrog/terraform-provider-shared/util.applyTelemetry.func1({0x100f38d90?, 0x140004d6960}, 0x0?, {0x100f28660?, 0x140002d8000})
    github.com/jfrog/terraform-provider-shared@v1.8.0/util/util.go:225 +0x1d4
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).create(0x140004982a0, {0x100f38dc8, 0x14000268510}, 0xd?, {0x100f28660, 0x140002d8000})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.14.0/helper/schema/resource.go:707 +0xec
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).Apply(0x140004982a0, {0x100f38dc8, 0x14000268510}, 0x1400049d2b0, 0x14000320500, {0x100f28660, 0x140002d8000})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.14.0/helper/schema/resource.go:837 +0x874
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ApplyResourceChange(0x140001219b0, {0x100f38d20?, 0x1400021ddc0?}, 0x14000125f90)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.14.0/helper/schema/grpc_provider.go:1021 +0xb94
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ApplyResourceChange(0x140003b1860, {0x100f38dc8?, 0x1400001dc20?}, 0x140000b27e0)
    github.com/hashicorp/terraform-plugin-go@v0.9.0/tfprotov5/tf5server/server.go:812 +0x38c
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ApplyResourceChange_Handler({0x100f04380?, 0x140003b1860}, {0x100f38dc8, 0x1400001dc20}, 0x14000081e60, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.9.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:385 +0x174
google.golang.org/grpc.(*Server).processUnaryRPC(0x14000138700, {0x100f3b768, 0x14000314680}, 0x140002a2000, 0x140004905a0, 0x1013b2920, 0x0)
    google.golang.org/grpc@v1.45.0/server.go:1282 +0xb3c
google.golang.org/grpc.(*Server).handleStream(0x14000138700, {0x100f3b768, 0x14000314680}, 0x140002a2000, 0x0)
    google.golang.org/grpc@v1.45.0/server.go:1619 +0x840
google.golang.org/grpc.(*Server).serveStreams.func1.2()
    google.golang.org/grpc@v1.45.0/server.go:921 +0x88
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.45.0/server.go:919 +0x298