openstack_compute_floatingip_associate_v2

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        = "ad091b52-742f-469e-8f3c-fd81cadf0743"
  flavor_id       = 3
  key_pair        = "my_key_pair_name"
  security_groups = ["default"]
}

resource "openstack_networking_floatingip_v2" "fip_1" {
  pool = "my_pool"
}

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        = "ad091b52-742f-469e-8f3c-fd81cadf0743"
  flavor_id       = 3
  key_pair        = "my_key_pair_name"
  security_groups = ["default"]

  network {
    name = "my_network"
  }

  network {
    name = "default"
  }
}

resource "openstack_networking_floatingip_v2" "fip_1" {
  pool = "my_pool"
}

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:

Attributes Reference

The following attributes are exported:

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