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.
This commit is contained in:
Joe Topjian 2015-11-13 04:46:12 +00:00
parent 536ba76b21
commit edd8e722bf
5 changed files with 21 additions and 21 deletions

View File

@ -148,8 +148,8 @@ func TestAccNetworkingV2Network_fullstack(t *testing.T) {
name = "port_1"
network_id = "${openstack_networking_network_v2.foo.id}"
admin_state_up = "true"
security_groups = ["${openstack_compute_secgroup_v2.foo.id}"]
fixed_ips {
security_group_ids = ["${openstack_compute_secgroup_v2.foo.id}"]
fixed_ip {
"subnet_id" = "${openstack_networking_subnet_v2.foo.id}"
"ip_address" = "192.168.199.23"
}

View File

@ -3,7 +3,6 @@ package openstack
import (
"fmt"
"log"
"strconv"
"time"
"github.com/hashicorp/terraform/helper/hashcode"
@ -39,7 +38,7 @@ func resourceNetworkingPortV2() *schema.Resource {
ForceNew: true,
},
"admin_state_up": &schema.Schema{
Type: schema.TypeString,
Type: schema.TypeBool,
Optional: true,
ForceNew: false,
Computed: true,
@ -62,7 +61,7 @@ func resourceNetworkingPortV2() *schema.Resource {
ForceNew: true,
Computed: true,
},
"security_groups": &schema.Schema{
"security_group_ids": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
ForceNew: false,
@ -78,7 +77,7 @@ func resourceNetworkingPortV2() *schema.Resource {
ForceNew: true,
Computed: true,
},
"fixed_ips": &schema.Schema{
"fixed_ip": &schema.Schema{
Type: schema.TypeList,
Optional: true,
ForceNew: false,
@ -157,14 +156,14 @@ func resourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) erro
log.Printf("[DEBUG] Retreived Port %s: %+v", d.Id(), p)
d.Set("name", p.Name)
d.Set("admin_state_up", strconv.FormatBool(p.AdminStateUp))
d.Set("admin_state_up", p.AdminStateUp)
d.Set("network_id", p.NetworkID)
d.Set("mac_address", p.MACAddress)
d.Set("tenant_id", p.TenantID)
d.Set("device_owner", p.DeviceOwner)
d.Set("security_groups", p.SecurityGroups)
d.Set("security_group_ids", p.SecurityGroups)
d.Set("device_id", p.DeviceID)
d.Set("fixed_ips", p.FixedIPs)
d.Set("fixed_ip", p.FixedIPs)
return nil
}
@ -190,7 +189,7 @@ func resourceNetworkingPortV2Update(d *schema.ResourceData, meta interface{}) er
updateOpts.DeviceOwner = d.Get("device_owner").(string)
}
if d.HasChange("security_groups") {
if d.HasChange("security_group_ids") {
updateOpts.SecurityGroups = resourcePortSecurityGroupsV2(d)
}
@ -198,7 +197,7 @@ func resourceNetworkingPortV2Update(d *schema.ResourceData, meta interface{}) er
updateOpts.DeviceID = d.Get("device_id").(string)
}
if d.HasChange("fixed_ips") {
if d.HasChange("fixed_ip") {
updateOpts.FixedIPs = resourcePortFixedIpsV2(d)
}
@ -238,7 +237,7 @@ func resourceNetworkingPortV2Delete(d *schema.ResourceData, meta interface{}) er
}
func resourcePortSecurityGroupsV2(d *schema.ResourceData) []string {
rawSecurityGroups := d.Get("security_groups").(*schema.Set)
rawSecurityGroups := d.Get("security_group_ids").(*schema.Set)
groups := make([]string, rawSecurityGroups.Len())
for i, raw := range rawSecurityGroups.List() {
groups[i] = raw.(string)
@ -247,7 +246,7 @@ func resourcePortSecurityGroupsV2(d *schema.ResourceData) []string {
}
func resourcePortFixedIpsV2(d *schema.ResourceData) []ports.IP {
rawIP := d.Get("fixed_ips").([]interface{})
rawIP := d.Get("fixed_ip").([]interface{})
ip := make([]ports.IP, len(rawIP))
for i, raw := range rawIP {
rawMap := raw.(map[string]interface{})
@ -263,7 +262,7 @@ func resourcePortFixedIpsV2(d *schema.ResourceData) []ports.IP {
func resourcePortAdminStateUpV2(d *schema.ResourceData) *bool {
value := false
if raw, ok := d.GetOk("admin_state_up"); ok && raw == "true" {
if raw, ok := d.GetOk("admin_state_up"); ok && raw == true {
value = true
}

View File

@ -40,7 +40,7 @@ func TestAccNetworkingV2Port_basic(t *testing.T) {
name = "port_1"
network_id = "${openstack_networking_network_v2.foo.id}"
admin_state_up = "true"
fixed_ips {
fixed_ip {
subnet_id = "${openstack_networking_subnet_v2.foo.id}"
ip_address = "192.168.199.23"
}

View File

@ -160,7 +160,7 @@ var testAccNetworkingV2RouterInterface_basic_port = fmt.Sprintf(`
name = "port_1"
network_id = "${openstack_networking_network_v2.network_1.id}"
admin_state_up = "true"
fixed_ips {
fixed_ip {
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
ip_address = "192.168.199.1"
}

View File

@ -53,17 +53,18 @@ The following arguments are supported:
* `device_owner` - (Optional) The device owner of the Port. Changing this creates
a new port.
* `security_groups` - (Optional) A list of security groups to apply to the port.
The security groups must be specified by ID and not name (as opposed to how
they are configured with the Compute Instance).
* `security_group_ids` - (Optional) A list of security group IDs to apply to the
port. The security groups must be specified by ID and not name (as opposed
to how they are configured with the Compute Instance).
* `device_id` - (Optional) The ID of the device attached to the port. Changing this
creates a new port.
* `fixed_ips` - (Optional) An array of desired IPs for this port.
* `fixed_ip` - (Optional) An array of desired IPs for this port. The structure is
described below.
The `fixed_ips` block supports:
The `fixed_ip` block supports:
* `subnet_id` - (Required) Subnet in which to allocate IP address for
this port.