datadrivers/terraform-provider-nexus

Unable to import pypi-proxy: java.lang.ClassCastException: Cannot cast java.lang.String to java.lang.Number

fmereu-bics opened this issue ยท 4 comments

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a ๐Ÿ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

1.2.2

Nexus Provider Version

1.21.1

Nexus Version

3.38.1-01

Affected Resource(s)/Data Source(s)

nexus_repository_pypi_proxy

Terraform Configuration Files

n/a, importing a resource.

Debug Output/Panic Output

2022-10-17T08:24:25.430Z [INFO]  CLI args: []string{"terraform", "import", "-var-file", "production.json", "-var-file", "production.creds.json", "nexus_repository_pypi_proxy.this[\"pypi-proxy\"]", "pypi-proxy"}
2022-10-17T08:24:25.431Z [INFO]  CLI command args: []string{"import", "-var-file", "production.json", "-var-file", "production.creds.json", "nexus_repository_pypi_proxy.this[\"pypi-proxy\"]", "pypi-proxy"}
2022-10-17T08:24:25.556Z [DEBUG] ProviderTransformer: "nexus_repository_pypi_proxy.this[\"pypi-proxy\"] (import id \"pypi-proxy\")" (*terraform.graphNodeImportState) needs provider["registry.terraform.io/datadrivers/nexus"]
2022-10-17T08:24:25.655Z [DEBUG] ReferenceTransformer: "nexus_repository_pypi_proxy.this" references: [var.repositories_pypi]
2022-10-17T08:24:25.657Z [DEBUG] ReferenceTransformer: "var.repositories_pypi" references: []
2022-10-17T08:24:25.657Z [DEBUG] ReferenceTransformer: "nexus_repository_pypi_proxy.this[\"pypi-proxy\"] (import id \"pypi-proxy\")" references: []
nexus_repository_pypi_proxy.this["pypi-proxy"]: Importing from ID "pypi-proxy"...
nexus_repository_pypi_proxy.this["pypi-proxy"]: Import prepared!
  Prepared nexus_repository_pypi_proxy for import
nexus_repository_pypi_proxy.this["pypi-proxy"]: Refreshing state... [id=pypi-proxy]
2022-10-17T08:24:25.785Z [ERROR] provider.terraform-provider-nexus_v1.21.1: Response contains error diagnostic: @module=sdk.proto diagnostic_detail= tf_proto_version=5.3 tf_provider_addr=provider tf_rpc=ReadResource @caller=github.com/hashicorp/terraform-plugin-go@v0.14.0/tfprotov5/internal/diag/diagnostics.go:55 diagnostic_severity=ERROR diagnostic_summary="could not read repository 'pypi-proxy': HTTP: 500, ERROR: (ID e4e3f566-2c14-473c-a367-5381df879a6d) java.lang.ClassCastException: Cannot cast java.lang.String to java.lang.Number" tf_req_id=d2896f58-af2f-d136-7130-43010f84cefe tf_resource_type=nexus_repository_pypi_proxy timestamp=2022-10-17T08:24:25.784Z
2022-10-17T08:24:25.785Z [ERROR] vertex "import nexus_repository_pypi_proxy.this[\"pypi-proxy\"] result" error: could not read repository 'pypi-proxy': HTTP: 500, ERROR: (ID e4e3f566-2c14-473c-a367-5381df879a6d) java.lang.ClassCastException: Cannot cast java.lang.String to java.lang.Number
2022-10-17T08:24:25.785Z [ERROR] vertex "nexus_repository_pypi_proxy.this[\"pypi-proxy\"] (import id \"pypi-proxy\")" error: could not read repository 'pypi-proxy': HTTP: 500, ERROR: (ID e4e3f566-2c14-473c-a367-5381df879a6d) java.lang.ClassCastException: Cannot cast java.lang.String to java.lang.Number
โ”‚ Error: could not read repository 'pypi-proxy': HTTP: 500, ERROR: (ID e4e3f566-2c14-473c-a367-5381df879a6d) java.lang.ClassCastException: Cannot cast java.lang.String to java.lang.Number

Expected Behaviour

Repository should be imported successfully.

Actual Behaviour

Repository is not imported, Nexus throws a ClassCastException (HTTP/500).

Steps to Reproduce

terraform import -var-file myvars.json nexus_repository_pypi_proxy.this["pypi-proxy"] pypi-proxy

References

No response

Hi @fmereu-bics ,

i can not reproduce this problem.
image

can you send me your configuration/code example?

Thx for the quick feedback!
The config of the repo should be standard I guess, I don't think we customized it:
image
And here's the code I'm trying to import into (which is used for other repository types and works Ok):

resource "nexus_repository_pypi_proxy" "this" {
  for_each = {
    for repository in var.repositories_pypi :
    repository.name => repository
    if(
      repository.type == "proxy" &&
      lookup(repository, "create_repository", true)
    )
  }

  name   = each.value.name
  online = true

  storage {
    blob_store_name                = try(each.value.blob_store_name, "default")
    strict_content_type_validation = try(each.value.strict_content_type_validation, true)
  }

  proxy {
    remote_url       = each.value.remote_url
    content_max_age  = 1440
    metadata_max_age = 1440
  }

  negative_cache {
    enabled = true
    ttl     = 1440
  }

  http_client {
    blocked    = try(each.value.http_client_blocked, false)
    auto_block = try(each.value.http_client_auto_block, true)
  }
}

The variable file would look like this after the import is done (in JSON):

{
  "repositories_pypi": [
    {
      "name": "python-releases",
      "type": "hosted"
    },
    {
      "name": "python-snapshots",
      "type": "hosted",
      "cleanup": ["all-30d-age"]
    },
    {
      "name": "pypi-proxy",
      "type": "proxy",
      "remote_url": "https://pypi.org/"
    }
  ]
}

Kr,
Fred

Hi Fred,

thanks for your code example.
But it is not possible to reproduce your error for me.
can you test this command and send me the error message if exists
curl -v -X GET -u user:password 'https://bcnexus.bc/service/rest/v1/repositories/pypi/proxy/pypi-proxy'

Hi @anmoel,

I had the exact same error message while doing the curl.. I tried on another similar instance and that one was OK..
So I ended up changing a setting in the pypi-proxy repo (e.g. the timeout value) and changing it back to the original value. After this I was able to run the curl command successfully, and import it in Terraform.

I suppose something was wrong in Nexus itself (maybe some kind of corrupted data).. anyway many thanks for your help with this!

Fred