digitalocean / terraform-provider-digitalocean

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

Droplet already has a pending event for reserved_ip #1034

Open AAverin opened 1 year ago

AAverin commented 1 year ago

Bug Report


Describe the bug

Having

resource "digitalocean_reserved_ip" "nomad_bastion" {
  droplet_id = digitalocean_droplet.nomad_bastion.id
  region     = digitalocean_droplet.nomad_bastion.region

  depends_on = [ resource.digitalocean_droplet.nomad_bastion ]
}

Applying often causes Droplet already has a pending event error, failing deployment.

Restart of the deployment results in Error: Error retrieving reserved IP: stream error: stream ID 17; INTERNAL_ERROR; received from peer

Affected Resource(s)

digitalocean_reserved_ip

Expected Behavior

Actual Behavior

Steps to Reproduce

Terraform Configuration Files

Terraform version

Debug Output

Panic Output

Additional context

Important Factoids

References

danaelhe commented 1 year ago

Hi there, thank you for the write up!

Hmmm....I can't seem to recreate this issue on my end. Are there any more details you can provide about the config you're using or if you have to run it multiple times to see the issue? For reference, this is the config file I'm using:

resource "digitalocean_droplet" "example" {
  name               = "example"
  size               = "s-1vcpu-1gb"
  image              = "ubuntu-22-04-x64"
  region             = "nyc3"
  ipv6               = true
  private_networking = true
}

resource "digitalocean_reserved_ip" "example" {
  droplet_id = digitalocean_droplet.example.id
  region     = digitalocean_droplet.example.region

  depends_on = [ resource.digitalocean_droplet.example ]
}
AAverin commented 1 year ago

It will probably be difficult to reproduce, but happens for me quite consistently.

Try to apply the infrastructure once and then do a small change (in user data, for example) and apply again. With the current example you use, reserved_ip will be created every time new, which is wrong, even though this is what is in the resource examples.

I have this now:

resource "digitalocean_droplet" "nomad_bastion" {
  image = data.digitalocean_images.cluster_server.images[0].id

  # Consul members name must be unique
  name   = "nomad-bastion"
  region = var.do_region_ams3
  size   = var.do_size_s-1vcpu-512mb-10gb
  user_data = templatefile("templates/user_data.sh", {
    nomad_servers_count = var.nomad_servers_count,
    do_token = var.do_token,
    ph_tags = "bastion"
  })
  ssh_keys  = [data.digitalocean_ssh_key.ssh.id]
  vpc_uuid  = digitalocean_vpc.cluster.id

  tags = [
    "bastion",
    local.retry_join.tag_name
  ]
}

resource "digitalocean_reserved_ip" "nomad_bastion" {
  region     = digitalocean_droplet.nomad_bastion.region
}

resource "digitalocean_reserved_ip_assignment" "bastion_static_ip" {
  ip_address = digitalocean_reserved_ip.nomad_bastion.ip_address
  droplet_id = digitalocean_droplet.nomad_bastion.id

  depends_on = [ 
    resource.digitalocean_reserved_ip.nomad_bastion,
    resource.digitalocean_droplet.nomad_bastion
   ]
}

Even with this setup, I often get the same error. But at very least I can run apply again and everything works fine then.

It is probably some kind of synchronization issue on the API side when reserved ip is being assigned to the droplet.