@@ -65,6 +65,67 @@ func TestAccNetworkingV2FloatingIP_attach(t *testing.T) {
6565 })
6666}
6767
68+ func TestAccNetworkingV2FloatingIP_fixedip_bind (t * testing.T ) {
69+ var fip floatingips.FloatingIP
70+ var testAccNetworkingV2FloatingIP_fixedip_bind = fmt .Sprintf (`
71+ resource "openstack_networking_network_v2" "network_1" {
72+ name = "network_1"
73+ admin_state_up = "true"
74+ }
75+
76+ resource "openstack_networking_subnet_v2" "subnet_1" {
77+ name = "subnet_1"
78+ network_id = "${openstack_networking_network_v2.network_1.id}"
79+ cidr = "192.168.199.0/24"
80+ ip_version = 4
81+ }
82+
83+ resource "openstack_networking_router_interface_v2" "router_interface_1" {
84+ router_id = "${openstack_networking_router_v2.router_1.id}"
85+ subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
86+ }
87+
88+ resource "openstack_networking_router_v2" "router_1" {
89+ name = "router_1"
90+ external_gateway = "%s"
91+ }
92+
93+ resource "openstack_networking_port_v2" "port_1" {
94+ network_id = "${openstack_networking_subnet_v2.subnet_1.network_id}"
95+ admin_state_up = "true"
96+ fixed_ip {
97+ subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
98+ ip_address = "192.168.199.10"
99+ }
100+ fixed_ip {
101+ subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
102+ ip_address = "192.168.199.20"
103+ }
104+ }
105+
106+ resource "openstack_networking_floatingip_v2" "ip_1" {
107+ pool = "%s"
108+ port_id = "${openstack_networking_port_v2.port_1.id}"
109+ fixed_ip = "${openstack_networking_port_v2.port_1.fixed_ip.1.ip_address}"
110+ }` ,
111+ os .Getenv ("OS_EXTGW_ID" ), os .Getenv ("OS_POOL_NAME" ))
112+
113+ resource .Test (t , resource.TestCase {
114+ PreCheck : func () { testAccPreCheck (t ) },
115+ Providers : testAccProviders ,
116+ CheckDestroy : testAccCheckNetworkingV2FloatingIPDestroy ,
117+ Steps : []resource.TestStep {
118+ resource.TestStep {
119+ Config : testAccNetworkingV2FloatingIP_fixedip_bind ,
120+ Check : resource .ComposeTestCheckFunc (
121+ testAccCheckNetworkingV2FloatingIPExists (t , "openstack_networking_floatingip_v2.ip_1" , & fip ),
122+ testAccCheckNetworkingV2FloatingIPBoundToCorrectIP (t , & fip , "192.168.199.20" ),
123+ ),
124+ },
125+ },
126+ })
127+ }
128+
68129func testAccCheckNetworkingV2FloatingIPDestroy (s * terraform.State ) error {
69130 config := testAccProvider .Meta ().(* Config )
70131 networkClient , err := config .networkingV2Client (OS_REGION_NAME )
@@ -118,6 +179,16 @@ func testAccCheckNetworkingV2FloatingIPExists(t *testing.T, n string, kp *floati
118179 }
119180}
120181
182+ func testAccCheckNetworkingV2FloatingIPBoundToCorrectIP (t * testing.T , fip * floatingips.FloatingIP , fixed_ip string ) resource.TestCheckFunc {
183+ return func (s * terraform.State ) error {
184+ if fip .FixedIP != fixed_ip {
185+ return fmt .Errorf ("Floating ip associated with wrong fixed ip" )
186+ }
187+
188+ return nil
189+ }
190+ }
191+
121192func testAccCheckNetworkingV2InstanceFloatingIPAttach (
122193 instance * servers.Server , fip * floatingips.FloatingIP ) resource.TestCheckFunc {
123194
0 commit comments