Skip to main content
openstack_compute_floatingip_associate_v2
Last update:

openstack_compute_floatingip_associate_v2

For your information

This instruction is an adapted copy of the official OpenStack Terraform provider documentation in the Terraform Registry.

Associate a floating IP to an instance.

Example Usage

Automatically detect the correct network

resource "openstack_compute_instance_v2" "instance_1" {
name = "instance_1"
image_id = "<image-id>"
flavor_id = "1311"
key_pair = "<key-pair-name>"
security_groups = ["default"]
}

resource "openstack_networking_floatingip_v2" "fip_1" {
pool = "external-network"
}

resource "openstack_compute_floatingip_associate_v2" "fip_1" {
floating_ip = openstack_networking_floatingip_v2.fip_1.address
instance_id = openstack_compute_instance_v2.instance_1.id
}

Explicitly set the network to attach to

resource "openstack_compute_instance_v2" "instance_1" {
name = "instance_1"
image_id = "<image-id>"
flavor_id = "1311"
key_pair = "<key-pair-name>"
security_groups = ["default"]

network {
name = "<network1-name>"
}

network {
name = "<network2-name>"
}
}

resource "openstack_networking_floatingip_v2" "fip_1" {
pool = "external-network"
}

resource "openstack_compute_floatingip_associate_v2" "fip_1" {
floating_ip = openstack_networking_floatingip_v2.fip_1.address
instance_id = openstack_compute_instance_v2.instance_1.id
fixed_ip = openstack_compute_instance_v2.instance_1.network.1.fixed_ip_v4
}

Argument Reference

The following arguments are supported:

  • region — (Optional) The region in which to obtain the V2 Compute client. Keypairs are associated with accounts, but a Compute client is needed to create one. If omitted, the region argument of the provider is used. Changing this creates a new floatingip_associate.

  • floating_ip — (Required) The floating IP to associate.

  • instance_id — (Required) The instance to associte the floating IP with.

  • fixed_ip — (Optional) The specific IP address to direct traffic to.

  • wait_until_associated — (Optional) In cases where the OpenStack environment does not automatically wait until the association has finished, set this option to have Terraform poll the instance until the floating IP has been associated. Defaults to false.

Attributes Reference

The following attributes are exported:

  • region — See Argument Reference above.
  • floating_ip — See Argument Reference above.
  • instance_id — See Argument Reference above.
  • fixed_ip — See Argument Reference above.

Import

This resource can be imported by specifying all three arguments, separated by a forward slash:

$ terraform import openstack_compute_floatingip_associate_v2.fip_1 floating_ip/instance_id/fixed_ip