digitalocean / terraform-provider-digitalocean

Terraform DigitalOcean provider
https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs
Mozilla Public License 2.0
510 stars 278 forks source link

Error creating droplet: JSON unmarshal issue with large number into Go struct field type int #1183

Open tlserver opened 4 months ago

tlserver commented 4 months ago

Bug Report


Describe the bug

When attempting to create a Droplet using Terraform, an error occurs indicating that a number in the JSON response cannot be unmarshaled into a Go struct field of type int. This seems to be due to the ID number being larger than the maximum value for an int in Go.

Affected Resource(s)

Expected Behavior

The Droplet should be created successfully without any errors.

Actual Behavior

The Droplet is created but an error make terraform stopped.

╷
│ Error: Error creating droplet: json: cannot unmarshal number 2215418155 into Go struct field LinkAction.links.actions.id of type int
│ 
│   with digitalocean_droplet.app_net,
│   on do-droplets.tf line 1, in resource "digitalocean_droplet" "app_net":
│    1: resource "digitalocean_droplet" "app_net" {
│ 
╵

Steps to Reproduce

  1. Define a Droplet resource in Terraform.
  2. Run terraform apply.

Terraform Configuration Files

provider "digitalocean" {}

resource "digitalocean_droplet" "app_net" {
  name     = "AppNet"
  image    = "ubuntu-24-04-x64"
  size     = "s-1vcpu-512mb-10gb"
  region   = "sgp1"
  ipv6     = true
}

Terraform version

Terraform v1.9.2
on windows_386
+ provider registry.terraform.io/1password/onepassword v2.1.0
+ provider registry.terraform.io/digitalocean/digitalocean v2.39.2
+ provider registry.terraform.io/hashicorp/google v5.38.0
+ provider registry.terraform.io/hashicorp/google-beta v5.38.0
+ provider registry.terraform.io/hashicorp/random v3.6.2

Debug Output Gist

Panic Output No panic output.

Additional context

The issue appears to be related to the JSON response from the DigitalOcean API containing an ID number that is too large for an int field in the Go struct. Since 2,215,418,155 ( 840C 992B ) > 2,147,483,647 ( 7FFF FFFF ) which is the max number of int32. The type of these large number field should be changed to uint32 or int64 instead of int32.

Important Factoids No custom images or kernels are being used.

References

151

tlserver commented 4 months ago

I am using Windows and found that this issue only occurs with the 386 (32-bit) version of Terraform, but not with the AMD64 (64-bit) version. You can download different versions of Terraform here.

nicholasmireles commented 4 months ago

I had the same issue and was able to resolve it by using the 64-bit executable as mentioned above. It is rather confusing that the 64-bit is called AMD.

eliseodesign commented 2 months ago

tuve el mismo maldito problema, te odio windows