0

I have a use case where I need to re-use detached Floating IPs. Is there a way to do this in Terraform? I've tried:

`
data "openstack_networking_floatingip_v2" "fips" {
   status = "DOWN"
}
`

to get a list of detached IPs, but I get an error saying there is more than one Floating IP (Which is true).

Is there a good way to get detached floating IPs as a data resource in terraform? The alternative is passing an array of available IPs via a wrapper script with the command outlined here: Reuse detached floating IPs in OpenStack

Rudy
  • 170
  • 1
  • 11
  • I'm guessing there is not a way to get detached floating IPs as a data resource in terraform, because the only data resource with "ip" in its name is `openstack_networking_floatingip_v2` and that only returns the `id` of the *one* found floating IP : https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs/data-sources/networking_floatingip_v2 – Yann Stoneman Oct 22 '20 at 12:37
  • Yeah, there doesn't seem to be a openstack data resource that returns multiple IPs from what I can tell. – Rudy Oct 22 '20 at 15:25

1 Answers1

0

For anyone else that comes across this, here is I solved it for now:

I used the 'external' data resource to call the openstack cli to retrieve a comma seperated list of available ips. The openstack cli command looks like this:

openstack floating ip list --status DOWN -f yaml -c "Floating IP Address"  

In order to get the output in the format suitable for terraform's external data resource, I used a python script. The script outputs a json object that looks like this: {ips = "ip.1.2.3,ip.4.5.6,ip.7.8.9"}

The external data resource in terraform looks like this:

data "external" ips {
    program = ["python", "<path-to-python-script>"]
}

From there I'm able to split the comma seperated string of ips in terraform and access the the ips as an array:

output available_ips {
    value = split(",", data.external.ips.result.ips)
}

It's definitely not elegant, I wish the openstack_networking_floatingip_v2 data resource would allow for this functionality, I'll look into opening an issue to get it added.

Rudy
  • 170
  • 1
  • 11