|
|
|
|
@ -65,6 +65,67 @@ func TestAccNetworkingV2FloatingIP_attach(t *testing.T) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAccNetworkingV2FloatingIP_fixedip_bind(t *testing.T) {
|
|
|
|
|
var fip floatingips.FloatingIP
|
|
|
|
|
var testAccNetworkingV2FloatingIP_fixedip_bind = fmt.Sprintf(`
|
|
|
|
|
resource "openstack_networking_network_v2" "network_1" {
|
|
|
|
|
name = "network_1"
|
|
|
|
|
admin_state_up = "true"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "openstack_networking_subnet_v2" "subnet_1" {
|
|
|
|
|
name = "subnet_1"
|
|
|
|
|
network_id = "${openstack_networking_network_v2.network_1.id}"
|
|
|
|
|
cidr = "192.168.199.0/24"
|
|
|
|
|
ip_version = 4
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "openstack_networking_router_interface_v2" "router_interface_1" {
|
|
|
|
|
router_id = "${openstack_networking_router_v2.router_1.id}"
|
|
|
|
|
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "openstack_networking_router_v2" "router_1" {
|
|
|
|
|
name = "router_1"
|
|
|
|
|
external_gateway = "%s"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "openstack_networking_port_v2" "port_1" {
|
|
|
|
|
network_id = "${openstack_networking_subnet_v2.subnet_1.network_id}"
|
|
|
|
|
admin_state_up = "true"
|
|
|
|
|
fixed_ip {
|
|
|
|
|
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
|
|
|
|
ip_address = "192.168.199.10"
|
|
|
|
|
}
|
|
|
|
|
fixed_ip {
|
|
|
|
|
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
|
|
|
|
ip_address = "192.168.199.20"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resource "openstack_networking_floatingip_v2" "ip_1" {
|
|
|
|
|
pool = "%s"
|
|
|
|
|
port_id = "${openstack_networking_port_v2.port_1.id}"
|
|
|
|
|
fixed_ip = "${openstack_networking_port_v2.port_1.fixed_ip.1.ip_address}"
|
|
|
|
|
}`,
|
|
|
|
|
os.Getenv("OS_EXTGW_ID"), os.Getenv("OS_POOL_NAME"))
|
|
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
|
Providers: testAccProviders,
|
|
|
|
|
CheckDestroy: testAccCheckNetworkingV2FloatingIPDestroy,
|
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
|
resource.TestStep{
|
|
|
|
|
Config: testAccNetworkingV2FloatingIP_fixedip_bind,
|
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
|
testAccCheckNetworkingV2FloatingIPExists(t, "openstack_networking_floatingip_v2.ip_1", &fip),
|
|
|
|
|
testAccCheckNetworkingV2FloatingIPBoundToCorrectIP(t, &fip, "192.168.199.20"),
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testAccCheckNetworkingV2FloatingIPDestroy(s *terraform.State) error {
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
networkClient, err := config.networkingV2Client(OS_REGION_NAME)
|
|
|
|
|
@ -118,6 +179,16 @@ func testAccCheckNetworkingV2FloatingIPExists(t *testing.T, n string, kp *floati
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testAccCheckNetworkingV2FloatingIPBoundToCorrectIP(t *testing.T, fip *floatingips.FloatingIP, fixed_ip string) resource.TestCheckFunc {
|
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
|
if fip.FixedIP != fixed_ip {
|
|
|
|
|
return fmt.Errorf("Floating ip associated with wrong fixed ip")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func testAccCheckNetworkingV2InstanceFloatingIPAttach(
|
|
|
|
|
instance *servers.Server, fip *floatingips.FloatingIP) resource.TestCheckFunc {
|
|
|
|
|
|
|
|
|
|
|