digitalocean / terraform-provider-digitalocean

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

floating_ip_assignment does not apply cleanly. #151

Open stillinbeta opened 6 years ago

stillinbeta commented 6 years ago

Terraform Version

$ terraform -v
Terraform v0.11.8
+ provider.digitalocean v1.0.0

Affected Resource(s)

Please list the resources as a list, for example:

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

variable "digital_ocean_token" {}

provider "digitalocean" {
  token = "${var.digital_ocean_token}"
  version = "1.0.0"
}

resource "digitalocean_floating_ip" "ip" {
  region = "nyc1"
}

resource "digitalocean_droplet" "droplet" {
  name = "mastodon"
  image = "ubuntu-18-04-x64"
  region = "nyc1"
  size = "1gb"
}

resource "digitalocean_floating_ip_assignment" "ip_assignment"{
  droplet_id = "${digitalocean_droplet.droplet.id}"
  ip_address = "${digitalocean_floating_ip.ip.ip_address}"
}

Debug Output

https://gist.github.com/stillinbeta/20d7b6c52cb59a839b47ce0997451ebb

Panic Output

none

Expected Behavior

The floating IP address should be assigned and exit cleanly.

Actual Behavior

Behind the scenes the floating IP is assigned to the appropriate droplet, but it then errors out. Because of the error, the floating IP isn't marked as assigned in the terraform state, so it will try to apply the assignment again next time Terraform is executed.

Error: Error applying plan:

1 error(s) occurred:

* digitalocean_floating_ip_assignment.ip_assignment: 1 error(s) occurred:

* digitalocean_floating_ip_assignment.ip_assignment: Error Assigning FloatingIP (165.227.254.109) to the droplet: json: cannot unmarshal number 2783182445 into Go struct field Action.resource_id of type int

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Define a digital ocean key under digital_ocean_api_key in e.g. terraform.tfvars
  2. terraform apply

Important Factoids

none

References

none

ArtiomL commented 6 years ago

You could use digitalocean_floating_ip to both create and assign the IP.

It works for me:

resource "digitalocean_droplet" "foobar" {
  name               = "baz"
  size               = "s-1vcpu-1gb"
  image              = "ubuntu-18-04-x64"
  region             = "sgp1"
  ipv6               = true
  private_networking = true
}

resource "digitalocean_floating_ip" "foobar" {
  droplet_id = "${digitalocean_droplet.foobar.id}"
  region     = "${digitalocean_droplet.foobar.region}"
}

Source: https://www.terraform.io/docs/providers/do/r/floating_ip.html#example-usage

stillinbeta commented 6 years ago

Same error:


1 error(s) occurred:

* digitalocean_floating_ip.ip: 1 error(s) occurred:

* digitalocean_floating_ip.ip: Error Assigning FloatingIP (174.138.109.215) to the droplet: json: cannot unmarshal number 2928307671 into Go struct field Action.resource_id of type int

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
variable "digital_ocean_token" {}

provider "digitalocean" {
  token = "${var.digital_ocean_token}"
  version = "1.0.0"
}

resource "digitalocean_floating_ip" "ip" {
  region = "nyc1"
  droplet_id = "${digitalocean_droplet.droplet.id}"
}

resource "digitalocean_droplet" "droplet" {
  name = "mastodon"
  image = "ubuntu-18-04-x64"
  region = "nyc1"
  size = "1gb"
}
ArtiomL commented 6 years ago

Could you try:

provider.digitalocean v1.0.2

That's what I'm using.

Thanks.

stillinbeta commented 6 years ago

It still crashes for me:

1 error(s) occurred:

* digitalocean_floating_ip.ip: 1 error(s) occurred:

* digitalocean_floating_ip.ip: Error Assigning FloatingIP (138.197.231.156) to the droplet: json: cannot unmarshal number 2328225692 into Go struct field Action.resource_id of type int

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.

zsh: exit 1     terraform apply tf.plan
terraform apply tf.plan  0.89s user 0.57s system 4% cpu 36.020 total
ArtiomL commented 6 years ago

Just tested and it works for me:

provider "digitalocean" {}

resource "digitalocean_floating_ip" "ip" {
  region = "nyc1"
  droplet_id = "${digitalocean_droplet.droplet.id}"
}

resource "digitalocean_droplet" "droplet" {
  name = "mastodon"
  image = "ubuntu-18-04-x64"
  region = "nyc1"
  size = "1gb"
}

Output:

digitalocean_droplet.droplet: Creation complete after 2m4s
digitalocean_floating_ip.ip: Creating...
digitalocean_floating_ip.ip: Still creating... (10s elapsed)
digitalocean_floating_ip.ip: Creation complete after 19s

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
stillinbeta commented 6 years ago

I tried this again on my macbook and on a x86 linux cloud instance, and it worked in both places. My guess, therefore, is that somehow this is an ARM-specific bug. Unless you have an ARM machine, I'm probably on my own to fix this.

andrewsomething commented 6 years ago

Thanks for that additional info on the platform. My suspicion that the Action.resource_id is larger than what fits in an int on your platform. If that's the case, this would need to be solved in github.com/digitalocean/godo

eddiezane commented 6 years ago

@stillinbeta I just tested with version 1.0.0 and 1.0.2 on my Raspberry Pi 3 and am unable to reproduce.

I'm wondering if Andrew is right in the specific int id is too large? Not sure where to go with this one.

martinaamodt commented 4 years ago

While running on my ARM platform i encountered the same issue. The issue is not apparent on my x86 workstation.

bramd commented 4 years ago

Same issue on Windows. After checking the Terraform binary, it seems I somehow installed the 32 bits version, was solved after using 64 bits.

stillinbeta commented 4 years ago

my arm laptop is 32 bits, so that's probably the throughline.

eddiezane commented 4 years ago

@stillinbeta @martinaamodt did switching to the 64 bit arm binary solve this?