Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider failed with terraform 1.5.3 #79

Closed
3 tasks
samuev opened this issue Aug 1, 2023 · 5 comments · Fixed by #82
Closed
3 tasks

provider failed with terraform 1.5.3 #79

samuev opened this issue Aug 1, 2023 · 5 comments · Fixed by #82
Assignees
Labels
bug Something isn't working

Comments

@samuev
Copy link

samuev commented Aug 1, 2023

Describe the bug
Managing a project via terraform 1.4.6 works fine.
same code with terraform 1.5.3 produce the following error:

C:\terraform_1.5.3\Modules>..\terraform apply
module.Artifactory.artifactory_user.build-user: Refreshing state... [id=mydemo-build-system]
module.Artifactory.artifactory_user.admin-user: Refreshing state... [id=e175409]

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # module.Artifactory.project.terraform-project will be created
  + resource "project" "terraform-project" {
      + block_deployments_on_limit = true
      + description                = "mydemo project admin: Terraform Project"
      + display_name               = "mydemo Project"
      + email_notification         = true
      + id                         = (known after apply)
      + key                        = "mydemo"
      + max_storage_in_gibibytes   = 10

      + admin_privileges {
          + index_resources  = true
          + manage_members   = true
          + manage_resources = true
        }

      + member {
          + name  = "e175409"
          + roles = [
              + "Project Admin",
            ]
        }
      + member {
          + name  = "mydemo-build-system"
          + roles = [
              + "Contributor",
            ]
        }
    }

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

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

  Enter a value: yes

module.Artifactory.project.terraform-project: Creating...
╷
│ Error:
│ 400 POST https://artifactory-dev.amat.com/access/api/v1/projects
│ {
│   "errors" : [ {
│     "code" : "BAD_REQUEST",
│     "message" : "Project Quota cannot be lower than `1073741824` bytes. Input: -2147483648"
│   } ]
│ }
│
│   with module.Artifactory.project.terraform-project,
│   on ..\Artifactory_Project\main.tf line 51, in resource "project" "terraform-project":
│   51: resource "project" "terraform-project" {

Requirements for and issue

  • A fully functioning terraform snippet that can be copy&pasted (no outside files or ENV vars unless that's part of the issue)
  • Your version of artifactory (you can curl it at $host/artifactory/api/system/version 7.59.9
  • Your version of terraform 1.5.3

Expected behavior
should work as terraform 1.4.6.
changes to max_storage_in_gibibytes produce the same error again

Additional context
Add any other context about the problem here.

@samuev samuev added the bug Something isn't working label Aug 1, 2023
@alexhung alexhung assigned danielmkn and unassigned alexhung Aug 1, 2023
@alexhung
Copy link
Member

alexhung commented Aug 24, 2023

@samuev Using terraform 1.5.2, I was able to create the follow project with no error:

alexh@alexh-mac terraform-provider-project % terraform apply

Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # project.myproject will be created
  + resource "project" "myproject" {
      + block_deployments_on_limit = false
      + description                = "My Project"
      + display_name               = "My Project"
      + email_notification         = true
      + id                         = (known after apply)
      + key                        = "myproj"
      + max_storage_in_gibibytes   = 10

      + admin_privileges {
          + index_resources  = true
          + manage_members   = true
          + manage_resources = true
        }
    }

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

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

  Enter a value: yes

project.myproject: Creating...
project.myproject: Creation complete after 0s [id=myproj]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
alexh@alexh-mac terraform-provider-project % terraform -v
Terraform v1.5.2
on darwin_amd64
+ provider registry.terraform.io/jfrog/project v1.1.17

Your version of Terraform is out of date! The latest version
is 1.5.6. You can update by downloading from https://www.terraform.io/downloads.html

@alexhung
Copy link
Member

@samuev I upgraded terraform to latest 1.5.6 and still no error when creating new project.

@alexhung alexhung added the question Further information is requested label Aug 24, 2023
@alexhung alexhung assigned alexhung and unassigned danielmkn Aug 24, 2023
@chb0github
Copy link
Contributor

chb0github commented Aug 25, 2023

"message" : "Project Quota cannot be lower than 1073741824 bytes. Input: -2147483648"

@alexhung - that value is suspicious: It's The maximum negative 32 bit value

Looking at this line

You can see that, any value greater than 3 for gigibytes will overwhelm a 32 bit number.

@samuev - is your machine running a 32 bit chip/os? I see you're running windows. If you were to put 10 for gigibytes, I don't know how go would behave since the value type for this code is int and not int32 - this means it will go with the platform definition of an int, which on a 32bit system, the max value is 2.14gb

Here's my theory: The client is 32 bits, and 10gb overflows with; the result of which I can't find a clear answer on (in go). I don't have access to a 32 bit system to try it

There is an easy test for @samuev - try running this again, except set the quota to 1, which will result in a number that can fit into 32 bits. If it passes, you have your answer (and the fix must be implemented in the provider)

As for @alexhung - the simplest, and safest thing to do, would be to explicitly set the type to uint64 on the payload struct. I think that's where the conversion error is occurring since when I tried to do this explicitly, it won't compile, and I know json unmarshalling is dynamic. You might also decide to express the value in a string form, and then expand it out in a type safe way (like 10gb)

var a int32 = 1024*1024*1024*10 // won't compile
var b int32 = 1024*1024*1024 //compiles

@alexhung
Copy link
Member

@chb0github You are on the money. The thought of incorrect integer type crossed my mind briefly but I didn't follow up when I couldn't reproduce. Switching type to uint64 is definitely the safest course of action.

@alexhung alexhung removed the question Further information is requested label Aug 25, 2023
@chb0github
Copy link
Contributor

Yeah, you're going to have to replace strconv.Atoi to strconv.PrseUint too
https://stackoverflow.com/questions/21532113/golang-converting-string-to-int64

alexhung added a commit that referenced this issue Aug 30, 2023
Use int64 explicitly with max_storage_in_gibibytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants