Skip to content

Commit edd8e72

Browse files
committed
provider/openstack: Make Networking Port attributes more intuitive
This commit makes some quick updates to the port attributes to make them more intuitive: * `security_groups` to `security_group_ids`: since the port is expecting IDs and not security group names like in other areas of OpenStack. * `admin_state_up`: change to Boolean to match this same attribute on other resources. * `fixed_ips` to `fixed_ip`: while multiple `fixed_ip` blocks can be specified, only one fixed IP can be specified in each block.
1 parent 536ba76 commit edd8e72

5 files changed

Lines changed: 21 additions & 21 deletions

File tree

builtin/providers/openstack/resource_openstack_networking_network_v2_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ func TestAccNetworkingV2Network_fullstack(t *testing.T) {
148148
name = "port_1"
149149
network_id = "${openstack_networking_network_v2.foo.id}"
150150
admin_state_up = "true"
151-
security_groups = ["${openstack_compute_secgroup_v2.foo.id}"]
152-
fixed_ips {
151+
security_group_ids = ["${openstack_compute_secgroup_v2.foo.id}"]
152+
fixed_ip {
153153
"subnet_id" = "${openstack_networking_subnet_v2.foo.id}"
154154
"ip_address" = "192.168.199.23"
155155
}

builtin/providers/openstack/resource_openstack_networking_port_v2.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package openstack
33
import (
44
"fmt"
55
"log"
6-
"strconv"
76
"time"
87

98
"github.com/hashicorp/terraform/helper/hashcode"
@@ -39,7 +38,7 @@ func resourceNetworkingPortV2() *schema.Resource {
3938
ForceNew: true,
4039
},
4140
"admin_state_up": &schema.Schema{
42-
Type: schema.TypeString,
41+
Type: schema.TypeBool,
4342
Optional: true,
4443
ForceNew: false,
4544
Computed: true,
@@ -62,7 +61,7 @@ func resourceNetworkingPortV2() *schema.Resource {
6261
ForceNew: true,
6362
Computed: true,
6463
},
65-
"security_groups": &schema.Schema{
64+
"security_group_ids": &schema.Schema{
6665
Type: schema.TypeSet,
6766
Optional: true,
6867
ForceNew: false,
@@ -78,7 +77,7 @@ func resourceNetworkingPortV2() *schema.Resource {
7877
ForceNew: true,
7978
Computed: true,
8079
},
81-
"fixed_ips": &schema.Schema{
80+
"fixed_ip": &schema.Schema{
8281
Type: schema.TypeList,
8382
Optional: true,
8483
ForceNew: false,
@@ -157,14 +156,14 @@ func resourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) erro
157156
log.Printf("[DEBUG] Retreived Port %s: %+v", d.Id(), p)
158157

159158
d.Set("name", p.Name)
160-
d.Set("admin_state_up", strconv.FormatBool(p.AdminStateUp))
159+
d.Set("admin_state_up", p.AdminStateUp)
161160
d.Set("network_id", p.NetworkID)
162161
d.Set("mac_address", p.MACAddress)
163162
d.Set("tenant_id", p.TenantID)
164163
d.Set("device_owner", p.DeviceOwner)
165-
d.Set("security_groups", p.SecurityGroups)
164+
d.Set("security_group_ids", p.SecurityGroups)
166165
d.Set("device_id", p.DeviceID)
167-
d.Set("fixed_ips", p.FixedIPs)
166+
d.Set("fixed_ip", p.FixedIPs)
168167

169168
return nil
170169
}
@@ -190,15 +189,15 @@ func resourceNetworkingPortV2Update(d *schema.ResourceData, meta interface{}) er
190189
updateOpts.DeviceOwner = d.Get("device_owner").(string)
191190
}
192191

193-
if d.HasChange("security_groups") {
192+
if d.HasChange("security_group_ids") {
194193
updateOpts.SecurityGroups = resourcePortSecurityGroupsV2(d)
195194
}
196195

197196
if d.HasChange("device_id") {
198197
updateOpts.DeviceID = d.Get("device_id").(string)
199198
}
200199

201-
if d.HasChange("fixed_ips") {
200+
if d.HasChange("fixed_ip") {
202201
updateOpts.FixedIPs = resourcePortFixedIpsV2(d)
203202
}
204203

@@ -238,7 +237,7 @@ func resourceNetworkingPortV2Delete(d *schema.ResourceData, meta interface{}) er
238237
}
239238

240239
func resourcePortSecurityGroupsV2(d *schema.ResourceData) []string {
241-
rawSecurityGroups := d.Get("security_groups").(*schema.Set)
240+
rawSecurityGroups := d.Get("security_group_ids").(*schema.Set)
242241
groups := make([]string, rawSecurityGroups.Len())
243242
for i, raw := range rawSecurityGroups.List() {
244243
groups[i] = raw.(string)
@@ -247,7 +246,7 @@ func resourcePortSecurityGroupsV2(d *schema.ResourceData) []string {
247246
}
248247

249248
func resourcePortFixedIpsV2(d *schema.ResourceData) []ports.IP {
250-
rawIP := d.Get("fixed_ips").([]interface{})
249+
rawIP := d.Get("fixed_ip").([]interface{})
251250
ip := make([]ports.IP, len(rawIP))
252251
for i, raw := range rawIP {
253252
rawMap := raw.(map[string]interface{})
@@ -263,7 +262,7 @@ func resourcePortFixedIpsV2(d *schema.ResourceData) []ports.IP {
263262
func resourcePortAdminStateUpV2(d *schema.ResourceData) *bool {
264263
value := false
265264

266-
if raw, ok := d.GetOk("admin_state_up"); ok && raw == "true" {
265+
if raw, ok := d.GetOk("admin_state_up"); ok && raw == true {
267266
value = true
268267
}
269268

builtin/providers/openstack/resource_openstack_networking_port_v2_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestAccNetworkingV2Port_basic(t *testing.T) {
4040
name = "port_1"
4141
network_id = "${openstack_networking_network_v2.foo.id}"
4242
admin_state_up = "true"
43-
fixed_ips {
43+
fixed_ip {
4444
subnet_id = "${openstack_networking_subnet_v2.foo.id}"
4545
ip_address = "192.168.199.23"
4646
}

builtin/providers/openstack/resource_openstack_networking_router_interface_v2_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ var testAccNetworkingV2RouterInterface_basic_port = fmt.Sprintf(`
160160
name = "port_1"
161161
network_id = "${openstack_networking_network_v2.network_1.id}"
162162
admin_state_up = "true"
163-
fixed_ips {
163+
fixed_ip {
164164
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
165165
ip_address = "192.168.199.1"
166166
}

website/source/docs/providers/openstack/r/networking_port_v2.html.markdown

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,18 @@ The following arguments are supported:
5353
* `device_owner` - (Optional) The device owner of the Port. Changing this creates
5454
a new port.
5555

56-
* `security_groups` - (Optional) A list of security groups to apply to the port.
57-
The security groups must be specified by ID and not name (as opposed to how
58-
they are configured with the Compute Instance).
56+
* `security_group_ids` - (Optional) A list of security group IDs to apply to the
57+
port. The security groups must be specified by ID and not name (as opposed
58+
to how they are configured with the Compute Instance).
5959

6060
* `device_id` - (Optional) The ID of the device attached to the port. Changing this
6161
creates a new port.
6262

63-
* `fixed_ips` - (Optional) An array of desired IPs for this port.
63+
* `fixed_ip` - (Optional) An array of desired IPs for this port. The structure is
64+
described below.
6465

6566

66-
The `fixed_ips` block supports:
67+
The `fixed_ip` block supports:
6768

6869
* `subnet_id` - (Required) Subnet in which to allocate IP address for
6970
this port.

0 commit comments

Comments
 (0)