Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/data-sources/networking_port_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ are exported:
addresses that can be active on this port. The structure is described
below.

* `all_fixed_ips` - The collection of Fixed IP addresses on the port in the
order returned by the Network v2 API.
* `all_fixed_ips` - The collection of Fixed IP addresses and subnet IDs on the
port in the order returned by the Network v2 API.

* `all_security_group_ids` - The set of security group IDs applied on the port.

Expand Down
6 changes: 3 additions & 3 deletions docs/resources/networking_port_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ The following arguments are supported:

* `dns_name` - (Optional) The port DNS name. Available, when Neutron DNS extension
is enabled.

* `qos_policy_id` - (Optional) Reference to the associated QoS policy.

The `fixed_ip` block supports:
Expand Down Expand Up @@ -231,8 +231,8 @@ The following attributes are exported:
* `security_group_ids` - See Argument Reference above.
* `device_id` - See Argument Reference above.
* `fixed_ip` - See Argument Reference above.
* `all_fixed_ips` - The collection of Fixed IP addresses on the port in the
order returned by the Network v2 API.
* `all_fixed_ips` - The collection of Fixed IP addresses and sibnet IDs on the
port in the order returned by the Network v2 API.
* `all_security_group_ids` - The collection of Security Group IDs on the port
which have been explicitly and implicitly added.
* `extra_dhcp_option` - See Argument Reference above.
Expand Down
13 changes: 12 additions & 1 deletion openstack/data_source_openstack_networking_port_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,18 @@ func dataSourceNetworkingPortV2() *schema.Resource {
"all_fixed_ips": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_address": {
Type: schema.TypeString,
Computed: true,
},
"subnet_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"all_security_group_ids": {
Expand Down
2 changes: 1 addition & 1 deletion openstack/data_source_openstack_networking_port_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ data "openstack_networking_port_v2" "port_2" {
}

data "openstack_networking_port_v2" "port_3" {
fixed_ip = openstack_networking_port_v2.port_1.all_fixed_ips.1
fixed_ip = openstack_networking_port_v2.port_1.all_fixed_ips[1].ip_address
}
`
41 changes: 41 additions & 0 deletions openstack/migrate_resource_openstack_networking_port_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package openstack

import (
"context"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func resourceNetworkingPortV2V0() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"all_fixed_ips": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}

func convertFixedIPs(list []any) []map[string]any {
newList := make([]map[string]any, len(list))
for i, ipRaw := range list {
newList[i] = map[string]any{
"ip_address": ipRaw.(string),
"subnet_id": "",
}
}

return newList
}

func upgradeNetworkingPortV2StateV0toV1(_ context.Context, rawState map[string]any, _ any) (map[string]any, error) {
if v, ok := rawState["all_fixed_ips"]; ok {
if list, ok := v.([]any); ok {
rawState["all_fixed_ips"] = convertFixedIPs(list)
}
}

return rawState, nil
}
45 changes: 45 additions & 0 deletions openstack/migrate_resource_openstack_networking_port_v2_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package openstack

import (
"reflect"
"testing"
)

func testResourceNetworkingV2PortStateDataV0() map[string]any {
return map[string]any{
"name": "test",
"all_fixed_ips": []any{
"192.168.0.10",
"192.168.0.11",
},
}
}

func testResourceNetworkingV2PortStateDataV1() map[string]any {
return map[string]any{
"name": "test",
"all_fixed_ips": []map[string]any{
{
"ip_address": "192.168.0.10",
"subnet_id": "",
},
{
"ip_address": "192.168.0.11",
"subnet_id": "",
},
},
}
}

func TestAccNetworkingV2PortStateUpgradeV0(t *testing.T) {
expected := testResourceNetworkingV2PortStateDataV1()

actual, err := upgradeNetworkingPortV2StateV0toV1(t.Context(), testResourceNetworkingV2PortStateDataV0(), nil)
if err != nil {
t.Fatalf("error migrating state: %s", err)
}

if !reflect.DeepEqual(expected, actual) {
t.Fatalf("\n\nexpected:\n\n%#v\n\ngot:\n\n%#v\n\n", expected, actual)
}
}
9 changes: 6 additions & 3 deletions openstack/networking_port_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,13 @@ func resourceNetworkingPortV2AllowedAddressPairsHash(v any) int {
return hashcode.String(buf.String())
}

func expandNetworkingPortFixedIPToStringSlice(fixedIPs []ports.IP) []string {
s := make([]string, len(fixedIPs))
func expandNetworkingPortFixedIPToStringSlice(fixedIPs []ports.IP) []map[string]any {
s := make([]map[string]any, len(fixedIPs))
for i, fixedIP := range fixedIPs {
s[i] = fixedIP.IPAddress
s[i] = map[string]any{
"ip_address": fixedIP.IPAddress,
"subnet_id": fixedIP.SubnetID,
}
}

return s
Expand Down
24 changes: 23 additions & 1 deletion openstack/resource_openstack_networking_port_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ func resourceNetworkingPortV2() *schema.Resource {
Delete: schema.DefaultTimeout(10 * time.Minute),
},

SchemaVersion: 1,
StateUpgraders: []schema.StateUpgrader{
{
Type: resourceNetworkingPortV2V0().CoreConfigSchema().ImpliedType(),
Upgrade: upgradeNetworkingPortV2StateV0toV1,
Version: 0,
},
},

Schema: map[string]*schema.Schema{
"region": {
Type: schema.TypeString,
Expand Down Expand Up @@ -119,10 +128,12 @@ func resourceNetworkingPortV2() *schema.Resource {
"subnet_id": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
"ip_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},
},
},
Expand Down Expand Up @@ -186,7 +197,18 @@ func resourceNetworkingPortV2() *schema.Resource {
"all_fixed_ips": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{Type: schema.TypeString},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_address": {
Type: schema.TypeString,
Computed: true,
},
"subnet_id": {
Type: schema.TypeString,
Computed: true,
},
},
},
},

"all_security_group_ids": {
Expand Down
6 changes: 3 additions & 3 deletions openstack/resource_openstack_networking_port_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ func TestAccNetworkingV2Port_fixedIPs(t *testing.T) {
Config: testAccNetworkingV2PortFixedIPs,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"openstack_networking_port_v2.port_1", "all_fixed_ips.0", "192.168.199.23"),
"openstack_networking_port_v2.port_1", "all_fixed_ips.0.ip_address", "192.168.199.23"),
resource.TestCheckResourceAttr(
"openstack_networking_port_v2.port_1", "all_fixed_ips.1", "192.168.199.24"),
"openstack_networking_port_v2.port_1", "all_fixed_ips.1.ip_address", "192.168.199.24"),
),
},
},
Expand Down Expand Up @@ -2212,7 +2212,7 @@ resource "openstack_networking_port_v2" "port_1" {
name = "port_1"
admin_state_up = "true"
network_id = openstack_networking_network_v2.network_1.id
fixed_ip {}
no_fixed_ip = true
}
`

Expand Down
4 changes: 2 additions & 2 deletions openstack/resource_openstack_taas_tap_mirror_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ resource "openstack_taas_tap_mirror_v2" "tap_mirror_1" {
description = "desc"
mirror_type = "erspanv1"
port_id = openstack_networking_port_v2.port_1.id
remote_ip = openstack_networking_port_v2.port_1.all_fixed_ips[0]
remote_ip = openstack_networking_port_v2.port_1.all_fixed_ips[0].ip_address
directions {
in = 1000
out = 1001
Expand Down Expand Up @@ -200,7 +200,7 @@ resource "openstack_taas_tap_mirror_v2" "tap_mirror_1" {
description = "updated desc"
mirror_type = "erspanv1"
port_id = openstack_networking_port_v2.port_1.id
remote_ip = openstack_networking_port_v2.port_1.all_fixed_ips[0]
remote_ip = openstack_networking_port_v2.port_1.all_fixed_ips[0].ip_address
directions {
in = 1000
out = 1001
Expand Down