jfrog / terraform-provider-artifactory

Terraform provider to manage JFrog Artifactory
https://jfrog.com/artifactory
Apache License 2.0
273 stars 101 forks source link

v7.10.0 causing SIGSEGV errors during plan #731

Closed mattmooree closed 1 year ago

mattmooree commented 1 year ago

When running a terraform plan with provider version 7.10.0 - a SIGSEGV is thrown and the plan fails:

Stack trace from the terraform-provider-artifactory_v7.10.0 plugin:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x98 pc=0xb7f15d]

goroutine 62 [running]:
github.com/go-resty/resty/v2.(*Request).Execute(0xc000664820, {0xe163b1?, 0xc000048e00?}, {0xe31ba9, 0x1f})
github.com/go-resty/resty/v2@v2.7.0/request.go:756 +0x21d
github.com/go-resty/resty/v2.(*Request).Get(...)
github.com/go-resty/resty/v2@v2.7.0/request.go:689
github.com/jfrog/terraform-provider-shared/util/sdk.GetArtifactoryVersion(0x0)
github.com/jfrog/terraform-provider-shared@v1.15.0/util/sdk/sdk.go:335 +0x218
github.com/jfrog/terraform-provider-artifactory/v7/pkg/artifactory/provider.(*ArtifactoryProvider).Configure(0x0?, {0xfad820, 0xc000651140}, {{0xc0007d9ff8, 0x5}, {{{0xfb1350, 0xc000654db0}, {0xd1aa60, 0xc000651f20}}, {0xfb2330, ...}}}, ...)
github.com/jfrog/terraform-provider-artifactory/v7/pkg/artifactory/provider/framework.go:139 +0x885
github.com/hashicorp/terraform-plugin-framework/internal/fwserver.(*Server).ConfigureProvider(0xc0000c6160, {0xfad820, 0xc000651140}, 0xc0007d1ec0, 0xc0007d1e40)
github.com/hashicorp/terraform-plugin-framework@v1.2.0/internal/fwserver/server_configureprovider.go:15 +0x10f
github.com/hashicorp/terraform-plugin-framework/internal/proto5server.(*Server).ConfigureProvider(0xc0000c6160, {0xfad820?, 0xc000650ff0?}, 0x3?)
github.com/hashicorp/terraform-plugin-framework@v1.2.0/internal/proto5server/server_configureprovider.go:36 +0x292
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.muxServer.ConfigureProvider({0xc00042a3c0, 0xc00042a420, {0xc00007a4a0, 0x2, 0x2}, {0x0, 0x0, 0x0}, {0x0, 0x0, ...}, ...}, ...)
github.com/hashicorp/terraform-plugin-mux@v0.9.0/tf5muxserver/mux_server_ConfigureProvider.go:25 +0x1b3
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).Configure(0xc000326b40, {0xfad820?, 0xc000645830?}, 0xc0007d1b00)
github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/tf5server/server.go:556 +0x2ce
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_Configure_Handler({0xde4800?, 0xc000326b40}, {0xfad820, 0xc000645830}, 0xc000800b60, 0x0)
github.com/hashicorp/terraform-plugin-go@v0.14.3/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:331 +0x170
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0000001e0, {0xfb1520, 0xc00047aea0}, 0xc00084bb00, 0xc000689500, 0x151a478, 0x0)
google.golang.org/grpc@v1.51.0/server.go:1340 +0xd13
google.golang.org/grpc.(*Server).handleStream(0xc0000001e0, {0xfb1520, 0xc00047aea0}, 0xc00084bb00, 0x0)
google.golang.org/grpc@v1.51.0/server.go:1713 +0xa1b
google.golang.org/grpc.(*Server).serveStreams.func1.2()
google.golang.org/grpc@v1.51.0/server.go:965 +0x98
created by google.golang.org/grpc.(*Server).serveStreams.func1
google.golang.org/grpc@v1.51.0/server.go:963 +0x28a
Error: The terraform-provider-artifactory_v7.10.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.
danielmkn commented 1 year ago

@mattmooree, we've seen this error twice in our CI after we started the migration from SDK v2 to Plugin Framework. It never happened on local and we still trying to reproduce it. Do you see it consistently?

chb0github commented 1 year ago

@danielmkn you're testing local on Mac? The CI runs on Linux. @mattmooree what os are you running on? What chip architecture? X86? Arm?

Go is supposed to make such cross platform issues a relic of the past, but might not live up to the ideal

danielmkn commented 1 year ago

Yup, I'm on Mac M1, and CI is Ubuntu 20. But even on Ubuntu, I don't see the issue on 7.10.0 today. All runs are green.

mattmooree commented 1 year ago

I can consistently reproduce the issue when changing my provider version to 7.10.0.

I confirmed that going back to 7.7.0 does not produce the same issue - everything runs smoothly.

Unfortunately I am running on terraform cloud - so I don't really have any insight into the OS architecture.

danielmkn commented 1 year ago

You bump the version in the provider configuration and run terraform init -upgrade?

mattmooree commented 1 year ago

Yeap - done that.

- Installing jfrog/artifactory v7.10.0...
- Installed jfrog/artifactory v7.10.0 (signed by a HashiCorp partner
danielmkn commented 1 year ago
  1. terraform init on
    artifactory = {
      source  = "registry.terraform.io/jfrog/artifactory"
      version = "7.7.0"
    }
  2. terraform apply on my configuration with 120+ resources.
  3. Bump the version to 7.10.0
  4. terraform init -upgrade Terraform has been successfully initialized!

Interesting...

mattmooree commented 1 year ago

For clarity - the upgrade works fine. Terraform Cloud has been successfully initialized!

It's the subsequent plan that fails.

danielmkn commented 1 year ago

I ran plan and apply right after the upgrade, successful.

danielmkn commented 1 year ago

Can you share what kind of resources you have?

mattmooree commented 1 year ago

Although there are many resources in the workspace - the only artifactory resource is a data resource of type "artifactory_file".

data "artifactory_file" "artifact" {
   ...
}
danielmkn commented 1 year ago

It's not a resource, but data source.

danielmkn commented 1 year ago

The file data source was added successfully as well. I've tried the same path - apply, upgrade, plan, apply. What version of Terraform do you use?

data "artifactory_file" "my-file" {
  repository   = "local-data-source"
  path         = "artifact.zip"
  output_path  = "tmp/artifact.zip"
}
JBurtnett commented 1 year ago

I am also experiencing this issue with version 7.10.0. I'm running in the cloud (linux_amd64) with terraform version 1.4.6

alexhung commented 1 year ago

I try to reproduce this issue on HCP. Setup everything (account, org, workspace, project)and then execute a run (using 7.10.1 provider) that creates 101 users on one of our test Artifactory SaaS instance. No issue at all. 😞 ?

alexhung commented 1 year ago

FYI this is the HCL I used for the test:

# Required for Terraform 0.13 and up (https://www.terraform.io/upgrade-guides/0-13.html)
terraform {
  cloud {
    organization = "jfrog-partnership-engineering"

    workspaces {
      name = "alexh"
    }
  }

  required_providers {
    artifactory = {
      source  = "jfrog/artifactory"
      version = "7.10.1"
    }
  }
}

provider "artifactory" {
  //  supply ARTIFACTORY_ACCESS_TOKEN / JFROG_ACCESS_TOKEN / ARTIFACTORY_API_KEY and ARTIFACTORY_URL / JFROG_URL as env vars
}

resource "artifactory_user" "new_user" {
  name   = "new_user"
  email  = "new_user@somewhere.com"
  groups = ["readers"]
}

locals {
  user_names = ["new_user1", "new_user2", "new_user3", "new_user4", "new_user5", "new_user6", "new_user7", "new_user8", "new_user9", "new_user10", "new_user11", "new_user12", "new_user13", "new_user14", "new_user15", "new_user16", "new_user17", "new_user18", "new_user19", "new_user20", "new_user21", "new_user22", "new_user23", "new_user24", "new_user25", "new_user26", "new_user27", "new_user28", "new_user29", "new_user30", "new_user31", "new_user32", "new_user33", "new_user34", "new_user35", "new_user36", "new_user37", "new_user38", "new_user39", "new_user40", "new_user41", "new_user42", "new_user43", "new_user44", "new_user45", "new_user46", "new_user47", "new_user48", "new_user49", "new_user50", "new_user51", "new_user52", "new_user53", "new_user54", "new_user55", "new_user56", "new_user57", "new_user58", "new_user59", "new_user60", "new_user61", "new_user62", "new_user63", "new_user64", "new_user65", "new_user66", "new_user67", "new_user68", "new_user69", "new_user70", "new_user71", "new_user72", "new_user73", "new_user74", "new_user75", "new_user76", "new_user77", "new_user78", "new_user79", "new_user80", "new_user81", "new_user82", "new_user83", "new_user84", "new_user85", "new_user86", "new_user87", "new_user88", "new_user89", "new_user90", "new_user91", "new_user92", "new_user93", "new_user94", "new_user95", "new_user96", "new_user97", "new_user98", "new_user99", "new_user100"]
}
resource "artifactory_user" "user_names" {
  for_each = toset(local.user_names)
  email = "new_user@somewhere.com"
  name  = each.value
  groups = ["readers"]
}
danielmkn commented 1 year ago

Ok, we found an issue. In this case, Terraform Cloud doesn't have JFROG_URL and/or JFROG_ACCESS_TOKEN env variables set. This is why the client gets "" as a URL/Access token and panics. First, please set the env variable correctly, second, we handling a missing configuration in a different way now, so it will complain right away if there is no URL/Access token supplied. In the new version, when a situation like this occurs, the provider will throw the following error:

Planning failed. Terraform encountered an error while generating this plan.

╷
│ Error: Missing URL Configuration
│ 
│   with provider["registry.terraform.io/jfrog/artifactory"],
│   on sample.tf line 11, in provider "artifactory":
│   11: provider "artifactory" {

The change will be released in v7.11.0

danielmkn commented 1 year ago

Note: the issue is related to the migration form SDK v2 to Plugin Framework.

danielmkn commented 1 year ago

Released in v7.11.0