jfrog / terraform-provider-xray

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

Crashes when importing xray_repository_config #134

Closed marcosdiez closed 1 year ago

marcosdiez commented 1 year ago

if one types

terraform import xray_repository_config.xray-repo-config collection-container-prod-local

one gets

xray_repository_config.xray-repo-config: Importing from ID "collection-container-prod-local"...
xray_repository_config.xray-repo-config: Import prepared!
  Prepared xray_repository_config for import
xray_repository_config.xray-repo-config: Refreshing state... [id=collection-container-prod-local]
╷
│ Error: Request cancelled
│
│ The plugin.(*GRPCProvider).ReadResource request was cancelled.
╵

Stack trace from the terraform-provider-xray_v1.15.0 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x1052d3290]

goroutine 41 [running]:
github.com/jfrog/terraform-provider-xray/pkg/xray.resourceXrayRepositoryConfig.func8(0x140001111d0, {0x14000452f00, 0x6}, {0x14000307aa0, 0x6})
    github.com/jfrog/terraform-provider-xray/pkg/xray/resource_xray_repository_config.go:376 +0x170
github.com/jfrog/terraform-provider-xray/pkg/xray.resourceXrayRepositoryConfig.func12({0x1400051a3c0?, 0x14000338160?}, {{0x140001bf9c0?, 0x10530030b?}, 0x140001111d0?, 0x0?}, 0xd?, {0x14000452f00, 0x6}, {0x14000307aa0, ...})
    github.com/jfrog/terraform-provider-xray/pkg/xray/resource_xray_repository_config.go:429 +0x108
github.com/jfrog/terraform-provider-xray/pkg/xray.resourceXrayRepositoryConfig.func14({0x1055b2268, 0x140005485a0}, 0x140001e0900, {0x105526d00?, 0x1400047e870})
    github.com/jfrog/terraform-provider-xray/pkg/xray/resource_xray_repository_config.go:482 +0x568
github.com/jfrog/terraform-provider-shared/util/sdk.applyTelemetry.func1({0x1055b2268?, 0x140005485a0}, 0x0?, {0x105526d00?, 0x1400047e870})
    github.com/jfrog/terraform-provider-shared@v1.18.0/util/sdk/sdk.go:234 +0x200
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x14000498c40, {0x1055b22a0, 0x140002e8fc0}, 0xd?, {0x105526d00, 0x1400047e870})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/resource.go:750 +0xec
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x14000498c40, {0x1055b22a0, 0x140002e8fc0}, 0x140001971e0, {0x105526d00, 0x1400047e870})
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/resource.go:1044 +0x494
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0x14000317968, {0x1055b22a0?, 0x140002e8ea0?}, 0x140004b2b80)
    github.com/hashicorp/terraform-plugin-sdk/v2@v2.27.0/helper/schema/grpc_provider.go:616 +0x40c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0x140004b4000, {0x1055b22a0?, 0x140002e8360?}, 0x140005482a0)
    github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/tf5server/server.go:751 +0x3ec
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x10557b900?, 0x140004b4000}, {0x1055b22a0, 0x140002e8360}, 0x140001dc070, 0x0)
    github.com/hashicorp/terraform-plugin-go@v0.18.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:386 +0x174
google.golang.org/grpc.(*Server).processUnaryRPC(0x1400046e000, {0x1055b4ee0, 0x140002a89c0}, 0x140004f2000, 0x1400047f3b0, 0x105a4df50, 0x0)
    google.golang.org/grpc@v1.56.1/server.go:1337 +0xc7c
google.golang.org/grpc.(*Server).handleStream(0x1400046e000, {0x1055b4ee0, 0x140002a89c0}, 0x140004f2000, 0x0)
    google.golang.org/grpc@v1.56.1/server.go:1714 +0x840
google.golang.org/grpc.(*Server).serveStreams.func1.1()
    google.golang.org/grpc@v1.56.1/server.go:959 +0x88
created by google.golang.org/grpc.(*Server).serveStreams.func1
    google.golang.org/grpc@v1.56.1/server.go:957 +0x170

Error: The terraform-provider-xray_v1.15.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.

The terraform for it is trivial:

terraform {
  required_providers {
    xray = {
      source = "jfrog/xray"
      version = "1.15.0"
    }
  }
}

provider "xray" {
   url = "https://XXXXX.jfrog.io"
}

resource "xray_repository_config" "xray-repo-config" {
  repo_name = "anyname"
}
alexhung commented 1 year ago

@marcosdiez It's not valid for the repository configuration to have no config or path_config attribute. I'll update the provider to enforce that rule. In the meantime, you need to include either/or both attributes (depending on the package type).

marcosdiez commented 1 year ago

Hi @alexhung

I think the problem is something else. I think it's by repository type. I tried with multiple times and I got deterministic results. Check it out !

I could successfully import:

I could NOT import (stacktrace):

Please take a look and let me know

Marcos

alexhung commented 1 year ago

@marcosdiez Exactly! For those package types, you will need to include config or path_config attributes in order for import to be successful. Similarly if you are to create new repo config for those package types.