Merge pull request #3904 from jtopjian/jtopjian-openstack-port-attr-cleanup
provider/openstack: Make Networking Port attributes more intuitive
This commit is contained in:
commit
19fc2193f4
|
@ -148,8 +148,8 @@ func TestAccNetworkingV2Network_fullstack(t *testing.T) {
|
||||||
name = "port_1"
|
name = "port_1"
|
||||||
network_id = "${openstack_networking_network_v2.foo.id}"
|
network_id = "${openstack_networking_network_v2.foo.id}"
|
||||||
admin_state_up = "true"
|
admin_state_up = "true"
|
||||||
security_groups = ["${openstack_compute_secgroup_v2.foo.id}"]
|
security_group_ids = ["${openstack_compute_secgroup_v2.foo.id}"]
|
||||||
fixed_ips {
|
fixed_ip {
|
||||||
"subnet_id" = "${openstack_networking_subnet_v2.foo.id}"
|
"subnet_id" = "${openstack_networking_subnet_v2.foo.id}"
|
||||||
"ip_address" = "192.168.199.23"
|
"ip_address" = "192.168.199.23"
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package openstack
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"strconv"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
|
@ -39,7 +38,7 @@ func resourceNetworkingPortV2() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
"admin_state_up": &schema.Schema{
|
"admin_state_up": &schema.Schema{
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeBool,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: false,
|
ForceNew: false,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
|
@ -62,7 +61,7 @@ func resourceNetworkingPortV2() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
"security_groups": &schema.Schema{
|
"security_group_ids": &schema.Schema{
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeSet,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: false,
|
ForceNew: false,
|
||||||
|
@ -78,7 +77,7 @@ func resourceNetworkingPortV2() *schema.Resource {
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
"fixed_ips": &schema.Schema{
|
"fixed_ip": &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: false,
|
ForceNew: false,
|
||||||
|
@ -157,14 +156,14 @@ func resourceNetworkingPortV2Read(d *schema.ResourceData, meta interface{}) erro
|
||||||
log.Printf("[DEBUG] Retreived Port %s: %+v", d.Id(), p)
|
log.Printf("[DEBUG] Retreived Port %s: %+v", d.Id(), p)
|
||||||
|
|
||||||
d.Set("name", p.Name)
|
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("network_id", p.NetworkID)
|
||||||
d.Set("mac_address", p.MACAddress)
|
d.Set("mac_address", p.MACAddress)
|
||||||
d.Set("tenant_id", p.TenantID)
|
d.Set("tenant_id", p.TenantID)
|
||||||
d.Set("device_owner", p.DeviceOwner)
|
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("device_id", p.DeviceID)
|
||||||
d.Set("fixed_ips", p.FixedIPs)
|
d.Set("fixed_ip", p.FixedIPs)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -190,7 +189,7 @@ func resourceNetworkingPortV2Update(d *schema.ResourceData, meta interface{}) er
|
||||||
updateOpts.DeviceOwner = d.Get("device_owner").(string)
|
updateOpts.DeviceOwner = d.Get("device_owner").(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("security_groups") {
|
if d.HasChange("security_group_ids") {
|
||||||
updateOpts.SecurityGroups = resourcePortSecurityGroupsV2(d)
|
updateOpts.SecurityGroups = resourcePortSecurityGroupsV2(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,7 +197,7 @@ func resourceNetworkingPortV2Update(d *schema.ResourceData, meta interface{}) er
|
||||||
updateOpts.DeviceID = d.Get("device_id").(string)
|
updateOpts.DeviceID = d.Get("device_id").(string)
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("fixed_ips") {
|
if d.HasChange("fixed_ip") {
|
||||||
updateOpts.FixedIPs = resourcePortFixedIpsV2(d)
|
updateOpts.FixedIPs = resourcePortFixedIpsV2(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +237,7 @@ func resourceNetworkingPortV2Delete(d *schema.ResourceData, meta interface{}) er
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourcePortSecurityGroupsV2(d *schema.ResourceData) []string {
|
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())
|
groups := make([]string, rawSecurityGroups.Len())
|
||||||
for i, raw := range rawSecurityGroups.List() {
|
for i, raw := range rawSecurityGroups.List() {
|
||||||
groups[i] = raw.(string)
|
groups[i] = raw.(string)
|
||||||
|
@ -247,7 +246,7 @@ func resourcePortSecurityGroupsV2(d *schema.ResourceData) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourcePortFixedIpsV2(d *schema.ResourceData) []ports.IP {
|
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))
|
ip := make([]ports.IP, len(rawIP))
|
||||||
for i, raw := range rawIP {
|
for i, raw := range rawIP {
|
||||||
rawMap := raw.(map[string]interface{})
|
rawMap := raw.(map[string]interface{})
|
||||||
|
@ -263,7 +262,7 @@ func resourcePortFixedIpsV2(d *schema.ResourceData) []ports.IP {
|
||||||
func resourcePortAdminStateUpV2(d *schema.ResourceData) *bool {
|
func resourcePortAdminStateUpV2(d *schema.ResourceData) *bool {
|
||||||
value := false
|
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
|
value = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ func TestAccNetworkingV2Port_basic(t *testing.T) {
|
||||||
name = "port_1"
|
name = "port_1"
|
||||||
network_id = "${openstack_networking_network_v2.foo.id}"
|
network_id = "${openstack_networking_network_v2.foo.id}"
|
||||||
admin_state_up = "true"
|
admin_state_up = "true"
|
||||||
fixed_ips {
|
fixed_ip {
|
||||||
subnet_id = "${openstack_networking_subnet_v2.foo.id}"
|
subnet_id = "${openstack_networking_subnet_v2.foo.id}"
|
||||||
ip_address = "192.168.199.23"
|
ip_address = "192.168.199.23"
|
||||||
}
|
}
|
||||||
|
|
|
@ -160,7 +160,7 @@ var testAccNetworkingV2RouterInterface_basic_port = fmt.Sprintf(`
|
||||||
name = "port_1"
|
name = "port_1"
|
||||||
network_id = "${openstack_networking_network_v2.network_1.id}"
|
network_id = "${openstack_networking_network_v2.network_1.id}"
|
||||||
admin_state_up = "true"
|
admin_state_up = "true"
|
||||||
fixed_ips {
|
fixed_ip {
|
||||||
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
subnet_id = "${openstack_networking_subnet_v2.subnet_1.id}"
|
||||||
ip_address = "192.168.199.1"
|
ip_address = "192.168.199.1"
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,17 +53,18 @@ The following arguments are supported:
|
||||||
* `device_owner` - (Optional) The device owner of the Port. Changing this creates
|
* `device_owner` - (Optional) The device owner of the Port. Changing this creates
|
||||||
a new port.
|
a new port.
|
||||||
|
|
||||||
* `security_groups` - (Optional) A list of security groups to apply to the port.
|
* `security_group_ids` - (Optional) A list of security group IDs to apply to the
|
||||||
The security groups must be specified by ID and not name (as opposed to how
|
port. The security groups must be specified by ID and not name (as opposed
|
||||||
they are configured with the Compute Instance).
|
to how they are configured with the Compute Instance).
|
||||||
|
|
||||||
* `device_id` - (Optional) The ID of the device attached to the port. Changing this
|
* `device_id` - (Optional) The ID of the device attached to the port. Changing this
|
||||||
creates a new port.
|
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
|
* `subnet_id` - (Required) Subnet in which to allocate IP address for
|
||||||
this port.
|
this port.
|
||||||
|
|
Loading…
Reference in New Issue