digitalocean / terraform-provider-digitalocean

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

Get unattached reserved_ip in data #1049

Open AAverin opened 11 months ago

AAverin commented 11 months ago

Is your feature request related to a problem? Please describe.

If reserved_ip resource is managed by terraform it ends up in the state. Then destroying such infrastructure results in destruction of the reserved ip too. I would like to keep my reserved ip in case I want to tear down and recreate the whole setup, but still have it accessible on the same production ip. A way to do that could be to remove resource from terraform state and have data instead.

data "digitalocean_reserved_ip" "nomad_bastion" {
  ip_address = digitalocean_droplet.nomad_bastion.ipv4_address

  depends_on = [
    resource.digitalocean_droplet.nomad_bastion
  ]
}

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

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

Issue is that ip_address field is required on data.digitalocean_reserved_ip and it is not possible to just get already created reserved_ip by name to then assign it to the droplet.

Describe the solution you'd like

ip_address field should be marked as optional and data.digitalocean_reserved_ip should provide access to created reserved ip by name without ip_address, basically allowing to get unassigned reserved_ip.

Describe alternatives you've considered

Additional context

andrewsomething commented 11 months ago

Currently DigitalOcean reserved IPs do not have a "name." The only unique identifier for the reserved IP is the IP address itself. In order to retrieve information about the reserved IP from the DigitalOcean, you must supply the IP.

https://docs.digitalocean.com/reference/api/api-reference/#operation/reservedIPs_get

AAverin commented 11 months ago

@andrewsomething Why would I need to get a reserved IP if I already know it? What's the point of it?