openstack_compute_interface_attach_v2

Attaches a Network Interface (a Port) to an Instance using the OpenStack Compute (Nova) v2 API.

Example Usage

Basic Attachment

resource "openstack_networking_network_v2" "network_1" {
  name           = "network_1"
  admin_state_up = "true"
}

resource "openstack_compute_instance_v2" "instance_1" {
  name            = "instance_1"
  security_groups = ["default"]
}

resource "openstack_compute_interface_attach_v2" "ai_1" {
  instance_id = openstack_compute_instance_v2.instance_1.id
  network_id  = openstack_networking_port_v2.network_1.id
}

Attachment Specifying a Fixed IP

resource "openstack_networking_network_v2" "network_1" {
  name           = "network_1"
  admin_state_up = "true"
}

resource "openstack_compute_instance_v2" "instance_1" {
  name            = "instance_1"
  security_groups = ["default"]
}

resource "openstack_compute_interface_attach_v2" "ai_1" {
  instance_id = openstack_compute_instance_v2.instance_1.id
  network_id  = openstack_networking_port_v2.network_1.id
  fixed_ip    = "10.0.10.10"
}

Attachment Using an Existing Port

resource "openstack_networking_network_v2" "network_1" {
  name           = "network_1"
  admin_state_up = "true"
}

resource "openstack_networking_port_v2" "port_1" {
  name           = "port_1"
  network_id     = openstack_networking_network_v2.network_1.id
  admin_state_up = "true"
}


resource "openstack_compute_instance_v2" "instance_1" {
  name            = "instance_1"
  security_groups = ["default"]
}

resource "openstack_compute_interface_attach_v2" "ai_1" {
  instance_id = openstack_compute_instance_v2.instance_1.id
  port_id     = openstack_networking_port_v2.port_1.id
}

Attaching Multiple Interfaces

resource "openstack_networking_network_v2" "network_1" {
  name           = "network_1"
  admin_state_up = "true"
}

resource "openstack_networking_port_v2" "ports" {
  count          = 2
  name           = format("port-%02d", count.index + 1)
  network_id     = openstack_networking_network_v2.network_1.id
  admin_state_up = "true"
}

resource "openstack_compute_instance_v2" "instance_1" {
  name            = "instance_1"
  security_groups = ["default"]
}

resource "openstack_compute_interface_attach_v2" "attachments" {
  count       = 2
  port_id     = openstack_networking_port_v2.ports[count.index].id
  instance_id = openstack_compute_instance_v2.instance_1.id
}

Note that the above example will not guarantee that the ports are attached in a deterministic manner. The ports will be attached in a seemingly random order.

If you want to ensure that the ports are attached in a given order, create explicit dependencies between the ports, such as:

resource "openstack_networking_network_v2" "network_1" {
  name           = "network_1"
  admin_state_up = "true"
}

resource "openstack_networking_port_v2" "ports" {
  count          = 2
  name           = format("port-%02d", count.index + 1)
  network_id     = openstack_networking_network_v2.network_1.id
  admin_state_up = "true"
}

resource "openstack_compute_instance_v2" "instance_1" {
  name            = "instance_1"
  security_groups = ["default"]
}

resource "openstack_compute_interface_attach_v2" "ai_1" {
  instance_id = openstack_compute_instance_v2.instance_1.id
  port_id     = openstack_networking_port_v2.ports[0].id
}

resource "openstack_compute_interface_attach_v2" "ai_2" {
  instance_id = openstack_compute_instance_v2.instance_1.id
  port_id     = openstack_networking_port_v2.ports[1].id
}

Argument Reference

The following arguments are supported:

Attributes Reference

The following attributes are exported:

Import

Interface Attachments can be imported using the Instance ID and Port ID separated by a slash, e.g.

$ terraform import openstack_compute_interface_attach_v2.ai_1 89c60255-9bd6-460c-822a-e2b959ede9d2/45670584-225f-46c3-b33e-6707b589b666