datadrivers / terraform-provider-nexus

Terraform provider for Sonatype Nexus
https://registry.terraform.io/providers/datadrivers/nexus
Mozilla Public License 2.0
119 stars 53 forks source link

terraform plan fails #480

Open I-Would-Like-To-Report-A-Bug-Please opened 1 week ago

I-Would-Like-To-Report-A-Bug-Please commented 1 week ago

Is there an existing issue for this?

Community Note

Terraform Version

1.0.11

Nexus Provider Version

2.5.0

Nexus Version

3.70.2-01

Affected Resource(s)/Data Source(s)

3.70.2-01

Terraform Configuration Files

terraform {
  required_providers {
    nexus = {
      source  = "datadrivers/nexus"
      version = "2.5.0"
    }
  }
}

resource "nexus_blobstore_group" "it-releases" {
  fill_policy = "writeToFirst"
  members     = [
    nexus_blobstore_s3.s3_it_releases.name,
  ]
  name        = "it-releases"
}

Debug Output/Panic Output

nexus_blobstore_group.it-releases: Refreshing state... [id=it-releases]
╷
│ Error: Plugin did not respond
│ 
│   with nexus_blobstore_group.it-releases,
│   on nexus_blobstore.tf line 9, in resource "nexus_blobstore_group" "it-releases":
│    9: resource "nexus_blobstore_group" "it-releases" {
│ 
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵
╷
╷
│ Error: Request cancelled
│ 
│   with nexus_repository_maven_group.pp-maven2,
│   on nexus_repository.tf line 181, in resource "nexus_repository_maven_group" "pp-maven2":
│  181: resource "nexus_repository_maven_group" "pp-maven2" {
│ 
│ The plugin.(*GRPCProvider).UpgradeResourceState request was cancelled.
╵

...
<bunch of plugin did not respond or request cancelled errors for multiple repositories>
...
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵

Stack trace from the terraform-provider-nexus_v2.5.0 plugin:

panic: Error reading level state: strconv.ParseInt: parsing "9223372036854776000": value out of range

goroutine 1044 [running]:
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*ResourceData).get(0xc000598380, {0xc000841210, 0x1, 0x1}, 0x8?)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource_data.go:556 +0x319
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*ResourceData).State(0xc000598380)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource_data.go:354 +0x473
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ShimInstanceStateFromValue(0xc0003afb20, {{{0xe8c038?, 0xc00009c050?}}, {0xc4d420?, 0xc00028f110?}})
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/resource.go:698 +0x1d8
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xc00039e8b8, {0xe8c070?, 0xc00028eb10?}, 0xc000616240)
        github.com/hashicorp/terraform-plugin-sdk/v2@v2.34.0/helper/schema/grpc_provider.go:682 +0x41d
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xc000251180, {0xe8c070?, 0xc00028e270?}, 0xc000aa8000)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/tf5server/server.go:783 +0x309
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0xd29920, 0xc000251180}, {0xe8c070, 0xc00028e270}, 0xc000598000, 0x0)
        github.com/hashicorp/terraform-plugin-go@v0.23.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:482 +0x1a6
google.golang.org/grpc.(*Server).processUnaryRPC(0xc0001a6e00, {0xe8c070, 0xc00028e1e0}, {0xe90a60, 0xc000488000}, 0xc0001e6000, 0xc0003b9620, 0x1416f88, 0x0)
        google.golang.org/grpc@v1.66.0/server.go:1393 +0xe1a
google.golang.org/grpc.(*Server).handleStream(0xc0001a6e00, {0xe90a60, 0xc000488000}, 0xc0001e6000)
        google.golang.org/grpc@v1.66.0/server.go:1804 +0xe8b
google.golang.org/grpc.(*Server).serveStreams.func2.1()
        google.golang.org/grpc@v1.66.0/server.go:1029 +0x8b
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 8
        google.golang.org/grpc@v1.66.0/server.go:1040 +0x125

Error: The terraform-provider-nexus_v2.5.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.

Expected Behaviour

Terraform plan should work and not crash

Actual Behaviour

Plugin crashed

Steps to Reproduce

terraform plan

But I'm not sure what's specific about this blob store group that causes panic. Our repositories are quite huge, so maybe it's something related to size?

References

No response

chris-ruecker commented 1 week ago

Hi, do you happen to run a 32 bit version of Terraform? If yes, could you try a 64bit version?

With the error message, i came across this issue here which contains an explanation of why this happens: https://github.com/hashicorp/terraform-provider-google/issues/6518

xgcssch commented 1 week ago

Hi! Same problem for me. I'm using the Docker image hashicorp/terraform:1.9 on an 64Bit machine:

Terraform v1.9.8
on linux_amd64
+ provider registry.terraform.io/datadrivers/nexus v2.5.0

Message is

panic: Error reading level state: strconv.ParseInt: parsing "9223372036854776000": value out of range

BTW: the integer IS larger then the maximum signed 64 bit Integer. Max 9,223,372,036,854,775,807 (inclusive)

Maybe an signed/unsigned mismatch

xgcssch commented 1 week ago

Maybe one more bit of information:

I've not seen this behavior until we moved last week to a new Nexus HA Installation with 3 servers serving requests.

@I-Would-Like-To-Report-A-Bug-Please Is your installation HA too?

I-Would-Like-To-Report-A-Bug-Please commented 1 week ago

For us it is single docker-compose one node installation.

Just checked Terraform:

❯ terraform -version
Terraform v1.0.11
on linux_amd64

❯ file /var/lib/tfenv/versions/1.0.11/terraform 
/var/lib/tfenv/versions/1.0.11/terraform: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, Go BuildID=oLZBNGHz70skNEAdhSHD/wzJydTaLhLbxOzYAwDlf/515RIPkbNiteahNWSa8i/XpyGuWV_TATduTbYzSf9, stripped

So definitely x64.

xgcssch commented 6 days ago

One more information: If i recover the previous version of the terraform.tfstate the last change is as expected not seen by terraform, but there is also no crash anymore. After removing and re-importing the changed resources the state is still valid. No crash. Seems that the resulting state after a change is somehow corrupted.

xgcssch commented 6 days ago

Hi!

I think i found the root cause of my problem:

We use a S3 Blobstore with this definition:

resource "nexus_blobstore_s3" "PersistentS3" {
  name = "PersistentS3"

  bucket_configuration {
    bucket {
      name   = "nexus_bucket"
      region = "DEFAULT"
      expiration = 3
      prefix = "persistent"
    }

  advanced_bucket_connection {
    endpoint = "https://acme.de:9021"
  }

  bucket_security {
      access_key_id     = "top"
      secret_access_key = "secret"
    }
  }

  soft_quota {
    limit = 2831155200000
    type  = "spaceUsedQuota"
  }

  lifecycle {
    ignore_changes = all
  }  
}

and historically an Blobstore group

resource "nexus_blobstore_group" "LanBlobStore" {
  name = "LanBlobStore"
  fill_policy = "writeToFirst"
  members = [
    nexus_blobstore_s3.PersistentS3.name
  ]
}

The latter is imported into Terraform, as it was defined long ago and other - non terraform controlled - repositories are based on it.

This results in this part of the terraform state file

{
    "mode": "managed",
    "type": "nexus_blobstore_group",
    "name": "LanBlobStore",
    "provider": "provider[\"registry.terraform.io/datadrivers/nexus\"]",
    "instances": [
    {
        "schema_version": 0,
        "attributes": {
        "available_space_in_bytes": 9223372036854775807,
        "blob_count": 84445,
        "fill_policy": "writeToFirst",
        "id": "LanBlobStore",
        "members": [
            "PersistentS3"
        ],
        "name": "LanBlobStore",
        "soft_quota": [],
        "total_size_in_bytes": 410556515216
        },
        "sensitive_attributes": [],
        "private": "eyJzY2hlbWFfdmVyc2lvbiI6IjAifQ=="
    }
    ]
},

with the offending value in available_space_in_bytes.

So @I-Would-Like-To-Report-A-Bug-Please maybe you have a look at the statefile too and find the offending value there. If it's available_space_in_bytes we are one step further.

Best regards Sönke