mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
provider/openstack: Fix Ordering of Port Allowed Address Pairs (#10250)
This commit changes allowed_address_pairs from a TypeList to a TypeSet allowing for arbitrary ordering. This solves the issue where a user specifies an address pair one way and OpenStack returns a different order.
This commit is contained in:
parent
63ae6f019e
commit
1c9853ec1b
@ -1,10 +1,12 @@
|
||||
package openstack
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/hashcode"
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
||||
@ -97,10 +99,11 @@ func resourceNetworkingPortV2() *schema.Resource {
|
||||
},
|
||||
},
|
||||
"allowed_address_pairs": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Type: schema.TypeSet,
|
||||
Optional: true,
|
||||
ForceNew: false,
|
||||
Computed: true,
|
||||
Set: allowedAddressPairsHash,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"ip_address": &schema.Schema{
|
||||
@ -320,7 +323,7 @@ func resourcePortFixedIpsV2(d *schema.ResourceData) interface{} {
|
||||
|
||||
func resourceAllowedAddressPairsV2(d *schema.ResourceData) []ports.AddressPair {
|
||||
// ports.AddressPair
|
||||
rawPairs := d.Get("allowed_address_pairs").([]interface{})
|
||||
rawPairs := d.Get("allowed_address_pairs").(*schema.Set).List()
|
||||
|
||||
if len(rawPairs) == 0 {
|
||||
return nil
|
||||
@ -347,6 +350,14 @@ func resourcePortAdminStateUpV2(d *schema.ResourceData) *bool {
|
||||
return &value
|
||||
}
|
||||
|
||||
func allowedAddressPairsHash(v interface{}) int {
|
||||
var buf bytes.Buffer
|
||||
m := v.(map[string]interface{})
|
||||
buf.WriteString(fmt.Sprintf("%s", m["ip_address"].(string)))
|
||||
|
||||
return hashcode.String(buf.String())
|
||||
}
|
||||
|
||||
func waitForNetworkPortActive(networkingClient *gophercloud.ServiceClient, portId string) resource.StateRefreshFunc {
|
||||
return func() (interface{}, string, error) {
|
||||
p, err := ports.Get(networkingClient, portId).Extract()
|
||||
|
@ -59,7 +59,7 @@ func TestAccNetworkingV2Port_noip(t *testing.T) {
|
||||
func TestAccNetworkingV2Port_allowedAddressPairs(t *testing.T) {
|
||||
var network networks.Network
|
||||
var subnet subnets.Subnet
|
||||
var vrrp_port, instance_port ports.Port
|
||||
var vrrp_port_1, vrrp_port_2, instance_port ports.Port
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
@ -71,7 +71,8 @@ func TestAccNetworkingV2Port_allowedAddressPairs(t *testing.T) {
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.vrrp_subnet", &subnet),
|
||||
testAccCheckNetworkingV2NetworkExists(t, "openstack_networking_network_v2.vrrp_network", &network),
|
||||
testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.vrrp_port", &vrrp_port),
|
||||
testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.vrrp_port_1", &vrrp_port_1),
|
||||
testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.vrrp_port_2", &vrrp_port_2),
|
||||
testAccCheckNetworkingV2PortExists(t, "openstack_networking_port_v2.instance_port", &instance_port),
|
||||
),
|
||||
},
|
||||
@ -202,8 +203,18 @@ var testAccNetworkingV2Port_allowedAddressPairs = fmt.Sprintf(`
|
||||
subnet_id = "${openstack_networking_subnet_v2.vrrp_subnet.id}"
|
||||
}
|
||||
|
||||
resource "openstack_networking_port_v2" "vrrp_port" {
|
||||
name = "vrrp_port"
|
||||
resource "openstack_networking_port_v2" "vrrp_port_1" {
|
||||
name = "vrrp_port_1"
|
||||
network_id = "${openstack_networking_network_v2.vrrp_network.id}"
|
||||
admin_state_up = "true"
|
||||
fixed_ip {
|
||||
subnet_id = "${openstack_networking_subnet_v2.vrrp_subnet.id}"
|
||||
ip_address = "10.0.0.202"
|
||||
}
|
||||
}
|
||||
|
||||
resource "openstack_networking_port_v2" "vrrp_port_2" {
|
||||
name = "vrrp_port_2"
|
||||
network_id = "${openstack_networking_network_v2.vrrp_network.id}"
|
||||
admin_state_up = "true"
|
||||
fixed_ip {
|
||||
@ -218,7 +229,12 @@ var testAccNetworkingV2Port_allowedAddressPairs = fmt.Sprintf(`
|
||||
admin_state_up = "true"
|
||||
|
||||
allowed_address_pairs {
|
||||
ip_address = "${openstack_networking_port_v2.vrrp_port.fixed_ip.0.ip_address}"
|
||||
mac_address = "${openstack_networking_port_v2.vrrp_port.mac_address}"
|
||||
ip_address = "${openstack_networking_port_v2.vrrp_port_1.fixed_ip.0.ip_address}"
|
||||
mac_address = "${openstack_networking_port_v2.vrrp_port_1.mac_address}"
|
||||
}
|
||||
|
||||
allowed_address_pairs {
|
||||
ip_address = "${openstack_networking_port_v2.vrrp_port_2.fixed_ip.0.ip_address}"
|
||||
mac_address = "${openstack_networking_port_v2.vrrp_port_2.mac_address}"
|
||||
}
|
||||
}`)
|
||||
|
Loading…
Reference in New Issue
Block a user