datadrivers/terraform-provider-nexus

Could not update repository: PARAMETER timeout must be greater than or equal to 1

fmereu-bics opened this issue ยท 9 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.0

Nexus Version

3.37.3-02

Affected Resource(s)/Data Source(s)

nexus_repository_maven_proxy

Terraform Configuration Files

resource "nexus_repository_maven_proxy" "this" {
  for_each = {
    for repository in var.repositories_maven :
    repository.name => repository
    if repository.type == "proxy"
  }

  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  = try(each.value.content_max_age, 1440)
    metadata_max_age = try(each.value.metadata_max_age, 1440)
  }

  negative_cache {
    enabled = true
    ttl     = 1440
  }

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

  maven {
    version_policy = try(each.value.version_policy, "RELEASE")
    layout_policy  = try(each.value.layout_policy, "STRICT")
  }
}

Debug Output/Panic Output

Terraform will perform the following actions:

  # nexus_repository_maven_proxy.this["maven-proxy"] will be updated in-place
  ~ resource "nexus_repository_maven_proxy" "this" {
        id     = "maven-proxy"
        name   = "maven-proxy"
        # (1 unchanged attribute hidden)




      ~ proxy {
          ~ remote_url       = "https://repo1.maven.org/maven2" -> "https://repo1.maven.org/maven2/"
            # (2 unchanged attributes hidden)
        }

        # (4 unchanged blocks hidden)
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Do you want to perform these actions in workspace "lab"?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

nexus_repository_maven_proxy.this["maven-proxy"]: Modifying... [id=maven-proxy]
โ•ท
โ”‚ Error: could not update repository 'maven-proxy': HTTP: 400, [ {
โ”‚   "id" : "PARAMETER timeout",
โ”‚   "message" : "must be greater than or equal to 1"
โ”‚ } ]
โ”‚ 
โ”‚   with nexus_repository_maven_proxy.this["maven-proxy"],
โ”‚   on repositories-maven.tf line 30, in resource "nexus_repository_maven_proxy" "this":
โ”‚   30: resource "nexus_repository_maven_proxy" "this" {
โ”‚

Expected Behaviour

Updating the maven2 proxy repository should be successful.

Actual Behaviour

The provider complains about the timeout parameter which must be equal or higher than 1; however by looking at the terraform state for this resource, we see the value is set to 0 (which probably stands for "no configured value" as default).

# nexus_repository_maven_proxy.this["maven-proxy"]:
resource "nexus_repository_maven_proxy" "this" {
    id     = "maven-proxy"
    name   = "maven-proxy"
    online = true

    http_client {
        auto_block = true
        blocked    = false

        connection {
            enable_circular_redirects = false
            enable_cookies            = false
            retries                   = 0
            timeout                   = 0
            use_trust_store           = false
        }
    }

    maven {
        layout_policy  = "STRICT"
        version_policy = "RELEASE"
    }

    negative_cache {
        enabled = true
        ttl     = 1440
    }

    proxy {
        content_max_age  = 1440
        metadata_max_age = 1440
        remote_url       = "https://repo1.maven.org/maven2/"
    }

    storage {
        blob_store_name                = "default"
        strict_content_type_validation = true
    }
}

Steps to Reproduce

No response

References

No response

FYI this seems to affect other repository types as well, got the same error when trying to update a Docker proxy repository.

And below some detailed output from the run:

2022-07-22T12:10:58.438Z [DEBUG] provider: starting plugin: path=.terraform/providers/registry.terraform.io/datadrivers/nexus/1.21.0/l
inux_amd64/terraform-provider-nexus_v1.21.0 args=[.terraform/providers/registry.terraform.io/datadrivers/nexus/1.21.0/linux_amd64/terr
aform-provider-nexus_v1.21.0]
2022-07-22T12:10:58.439Z [DEBUG] provider: plugin started: path=.terraform/providers/registry.terraform.io/datadrivers/nexus/1.21.0/li
nux_amd64/terraform-provider-nexus_v1.21.0 pid=622
2022-07-22T12:10:58.439Z [DEBUG] provider: waiting for RPC address: path=.terraform/providers/registry.terraform.io/datadrivers/nexus/
1.21.0/linux_amd64/terraform-provider-nexus_v1.21.0
2022-07-22T12:10:58.443Z [INFO]  provider.terraform-provider-nexus_v1.21.0: configuring server automatic mTLS: timestamp=2022-07-22T12
:10:58.442Z
2022-07-22T12:10:58.462Z [DEBUG] provider.terraform-provider-nexus_v1.21.0: plugin address: address=/tmp/plugin1035694543 network=unix
 timestamp=2022-07-22T12:10:58.462Z
2022-07-22T12:10:58.462Z [DEBUG] provider: using plugin: version=5
2022-07-22T12:10:58.525Z [WARN]  Provider "registry.terraform.io/datadrivers/nexus" produced an invalid plan for nexus_repository_dock
er_proxy.this["docker-hub"], but we are tolerating it because it is using the legacy plugin SDK.
    The following problems may be the cause of any confusing errors from downstream operations:
      - .docker[0].http_port: planned value cty.NumberIntVal(0) for a non-computed attribute
      - .docker[0].https_port: planned value cty.NumberIntVal(0) for a non-computed attribute
      - .docker_proxy[0].index_url: planned value cty.StringVal("") for a non-computed attribute
      - .http_client[0].connection: block count in plan (1) disagrees with count in config (0)
      - .proxy[0].content_max_age: planned value cty.NumberIntVal(1440) for a non-computed attribute
      - .proxy[0].metadata_max_age: planned value cty.NumberIntVal(1440) for a non-computed attribute
nexus_repository_docker_proxy.this["docker-hub"]: Modifying... [id=docker-hub]
2022-07-22T12:10:58.525Z [INFO]  Starting apply for nexus_repository_docker_proxy.this["docker-hub"]
2022-07-22T12:10:58.526Z [DEBUG] nexus_repository_docker_proxy.this["docker-hub"]: applying the planned Update change
2022-07-22T12:10:58.620Z [ERROR] vertex "nexus_repository_docker_proxy.this[\"docker-hub\"]" error: could not update repository 'docke
r-hub': HTTP: 400, [ {
  "id" : "PARAMETER timeout",
  "message" : "must be greater than or equal to 1"
} ]

Error: could not update repository 'docker-hub': HTTP: 400, [ {
  "id" : "PARAMETER timeout",
  "message" : "must be greater than or equal to 1"
} ]

  with nexus_repository_docker_proxy.this["docker-hub"],
  on repositories-docker.tf line 30, in resource "nexus_repository_docker_proxy" "this":
  30: resource "nexus_repository_docker_proxy" "this" {

2022-07-22T12:10:58.624Z [DEBUG] provider.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport
 is closing"
2022-07-22T12:10:58.626Z [DEBUG] provider: plugin process exited: path=.terraform/providers/registry.terraform.io/datadrivers/nexus/1.
21.0/linux_amd64/terraform-provider-nexus_v1.21.0 pid=622
2022-07-22T12:10:58.627Z [DEBUG] provider: plugin exited

From what I've seen, the REST API expects either a value (between 1 and 3600) or null (meaning 0) to disable the timeout. I tried to look into the code how this is being handled but couldn't find the relevant piece of code.

After some more digging, I found out this is due to the behavior of the Nexus Go client.
The Timeout field in the HTTPClientConnection struct is a pointer of int, meaning the omitempty JSON tag doesn't work as expected (it would omit if value is nil, not if it's 0).
I created a PR to address this, hopefully this is the right way to do it: datadrivers/go-nexus-client#100.

As a workaround until that PR is merged, setting timeout >= 1 works.

Any update on this one? Thanks.

fix is released in version v1.21.1

great, thanks a lot!

@fmereu-bics can you test it and reopen the issue if it is not working