Skip to content

Commit 3aadc19

Browse files
committed
Merge pull request hashicorp#6837 from carlpett/f-openstack-floatingip-fixed-binding
provider/openstack: Implement fixed_ip on floating ip allocations
2 parents 467ddab + 00be33e commit 3aadc19

4 files changed

Lines changed: 87 additions & 0 deletions

File tree

‎builtin/providers/openstack/provider_test.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ func testAccPreCheck(t *testing.T) {
6767
if v == "" {
6868
t.Fatal("OS_NETWORK_ID must be set for acceptance tests")
6969
}
70+
71+
v = os.Getenv("OS_EXTGW_ID")
72+
if v == "" {
73+
t.Fatal("OS_EXTGW_ID must be set for acceptance tests")
74+
}
7075
}

‎builtin/providers/openstack/resource_openstack_networking_floatingip_v2.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ func resourceNetworkingFloatingIPV2() *schema.Resource {
4949
Computed: true,
5050
ForceNew: true,
5151
},
52+
"fixed_ip": &schema.Schema{
53+
Type: schema.TypeString,
54+
Optional: true,
55+
Computed: true,
56+
},
5257
},
5358
}
5459
}
@@ -71,6 +76,7 @@ func resourceNetworkFloatingIPV2Create(d *schema.ResourceData, meta interface{})
7176
FloatingNetworkID: poolID,
7277
PortID: d.Get("port_id").(string),
7378
TenantID: d.Get("tenant_id").(string),
79+
FixedIP: d.Get("fixed_ip").(string),
7480
}
7581
log.Printf("[DEBUG] Create Options: %#v", createOpts)
7682
floatingIP, err := floatingips.Create(networkingClient, createOpts).Extract()
@@ -109,6 +115,7 @@ func resourceNetworkFloatingIPV2Read(d *schema.ResourceData, meta interface{}) e
109115

110116
d.Set("address", floatingIP.FloatingIP)
111117
d.Set("port_id", floatingIP.PortID)
118+
d.Set("fixed_ip", floatingIP.FixedIP)
112119
poolName, err := getNetworkName(d, meta, floatingIP.FloatingNetworkID)
113120
if err != nil {
114121
return fmt.Errorf("Error retrieving floating IP pool name: %s", err)

‎builtin/providers/openstack/resource_openstack_networking_floatingip_v2_test.go‎

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
68129
func 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+
121192
func testAccCheckNetworkingV2InstanceFloatingIPAttach(
122193
instance *servers.Server, fip *floatingips.FloatingIP) resource.TestCheckFunc {
123194

‎website/source/docs/providers/openstack/r/networking_floatingip_v2.html.markdown‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ The following arguments are supported:
4343
belongs to the same tenant. Changing this creates a new floating IP (which
4444
may or may not have a different address)
4545

46+
* `fixed_ip` - Fixed IP of the port to associate with this floating IP. Required if
47+
the port has multiple fixed IPs.
48+
4649
## Attributes Reference
4750

4851
The following attributes are exported:
@@ -52,3 +55,4 @@ The following attributes are exported:
5255
* `address` - The actual floating IP address itself.
5356
* `port_id` - ID of associated port.
5457
* `tenant_id` - the ID of the tenant in which to create the floating IP.
58+
* `fixed_ip` - The fixed IP which the floating IP maps to.

0 commit comments

Comments
 (0)