Skip to content

Commit d5d150f

Browse files
Network Peers (IBM-Cloud#5835)
Add [D]: pi_network_peers Update [D]: pi_network, pi_networks Update [R]: pi_network Add require option Add v1.9.0 fix spacing in cst file Co-authored-by: michaelkad <[email protected]>
1 parent e5a83f2 commit d5d150f

12 files changed

+433
-23
lines changed

ibm/provider/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,7 @@ func Provider() *schema.Provider {
685685
"ibm_pi_network_address_groups": power.DataSourceIBMPINetworkAddressGroups(),
686686
"ibm_pi_network_interface": power.DataSourceIBMPINetworkInterface(),
687687
"ibm_pi_network_interfaces": power.DataSourceIBMPINetworkInterfaces(),
688+
"ibm_pi_network_peers": power.DataSourceIBMPINetworkPeers(),
688689
"ibm_pi_network_port": power.DataSourceIBMPINetworkPort(),
689690
"ibm_pi_network_security_group": power.DataSourceIBMPINetworkSecurityGroup(),
690691
"ibm_pi_network_security_groups": power.DataSourceIBMPINetworkSecurityGroups(),

ibm/service/power/data_source_ibm_pi_network.go

+28-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func DataSourceIBMPINetwork() *schema.Resource {
3737
// Attributes
3838
Attr_AccessConfig: {
3939
Computed: true,
40-
Description: "The network communication configuration option of the network (for satellite locations only).",
40+
Deprecated: "This field is deprecated please use peer_id instead.",
41+
Description: "The network communication configuration option of the network (for on prem locations only). Use `peer_id` instead.",
4142
Type: schema.TypeString,
4243
},
4344
Attr_AvailableIPCount: {
@@ -83,6 +84,25 @@ func DataSourceIBMPINetwork() *schema.Resource {
8384
Description: "The unique identifier or name of a network.",
8485
Type: schema.TypeString,
8586
},
87+
Attr_NetworkAddressTranslation: {
88+
Computed: true,
89+
Description: "Contains the network address translation details (for on prem locations only).",
90+
Elem: &schema.Resource{
91+
Schema: map[string]*schema.Schema{
92+
Attr_SourceIP: {
93+
Computed: true,
94+
Description: "source IP address.",
95+
Type: schema.TypeString,
96+
},
97+
},
98+
},
99+
Type: schema.TypeList,
100+
},
101+
Attr_PeerID: {
102+
Computed: true,
103+
Description: "Network peer ID (for on prem locations only).",
104+
Type: schema.TypeString,
105+
},
86106
Attr_Type: {
87107
Computed: true,
88108
Description: "The type of network.",
@@ -153,6 +173,13 @@ func dataSourceIBMPINetworkRead(ctx context.Context, d *schema.ResourceData, met
153173
if networkdata.Name != nil {
154174
d.Set(Attr_Name, networkdata.Name)
155175
}
176+
networkAddressTranslation := []map[string]interface{}{}
177+
if networkdata.NetworkAddressTranslation != nil {
178+
natMap := networkAddressTranslationToMap(networkdata.NetworkAddressTranslation)
179+
networkAddressTranslation = append(networkAddressTranslation, natMap)
180+
}
181+
d.Set(Attr_NetworkAddressTranslation, networkAddressTranslation)
182+
d.Set(Attr_PeerID, networkdata.PeerID)
156183
if networkdata.Type != nil {
157184
d.Set(Attr_Type, networkdata.Type)
158185
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
// Copyright IBM Corp. 2024 All Rights Reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package power
5+
6+
import (
7+
"context"
8+
9+
"github.com/hashicorp/go-uuid"
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
13+
14+
"github.com/IBM-Cloud/power-go-client/clients/instance"
15+
"github.com/IBM-Cloud/power-go-client/power/models"
16+
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
17+
)
18+
19+
func DataSourceIBMPINetworkPeers() *schema.Resource {
20+
return &schema.Resource{
21+
ReadContext: dataSourceIBMPINetworkPeersRead,
22+
23+
Schema: map[string]*schema.Schema{
24+
// Arguments
25+
Arg_CloudInstanceID: {
26+
Description: "The GUID of the service instance associated with an account.",
27+
Required: true,
28+
Type: schema.TypeString,
29+
ValidateFunc: validation.NoZeroValues,
30+
},
31+
32+
// Attributes
33+
Attr_NetworkPeers: {
34+
Computed: true,
35+
Description: "List of network peers.",
36+
Elem: &schema.Resource{
37+
Schema: map[string]*schema.Schema{
38+
Attr_Description: {
39+
Computed: true,
40+
Description: "Description of the network peer.",
41+
Type: schema.TypeString,
42+
},
43+
Attr_ID: {
44+
Computed: true,
45+
Description: "ID of the network peer.",
46+
Type: schema.TypeString,
47+
},
48+
Attr_Name: {
49+
Computed: true,
50+
Description: "Name of the network peer.",
51+
Type: schema.TypeString,
52+
},
53+
Attr_Type: {
54+
Computed: true,
55+
Description: "Type of the network peer.",
56+
Type: schema.TypeString,
57+
},
58+
},
59+
},
60+
Type: schema.TypeList,
61+
},
62+
},
63+
}
64+
}
65+
66+
func dataSourceIBMPINetworkPeersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
67+
sess, err := meta.(conns.ClientSession).IBMPISession()
68+
if err != nil {
69+
return diag.FromErr(err)
70+
}
71+
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
72+
73+
networkC := instance.NewIBMPINetworkPeerClient(ctx, sess, cloudInstanceID)
74+
networkdata, err := networkC.GetNetworkPeers()
75+
if err != nil {
76+
return diag.FromErr(err)
77+
}
78+
var clientgenU, _ = uuid.GenerateUUID()
79+
d.SetId(clientgenU)
80+
81+
networkPeers := []map[string]interface{}{}
82+
if networkdata.NetworkPeers != nil {
83+
for _, np := range networkdata.NetworkPeers {
84+
npMap := dataSourceIBMPINetworkPeersNetworkPeerToMap(np)
85+
86+
networkPeers = append(networkPeers, npMap)
87+
}
88+
}
89+
d.Set(Attr_NetworkPeers, networkPeers)
90+
91+
return nil
92+
}
93+
94+
func dataSourceIBMPINetworkPeersNetworkPeerToMap(np *models.NetworkPeer) map[string]interface{} {
95+
npMap := make(map[string]interface{})
96+
if np.Description != nil {
97+
npMap[Attr_Description] = np.Description
98+
}
99+
if np.ID != nil {
100+
npMap[Attr_ID] = np.ID
101+
}
102+
if np.Name != nil {
103+
npMap[Attr_Name] = np.Name
104+
}
105+
if np.Type != nil {
106+
npMap[Attr_Type] = np.Type
107+
}
108+
return npMap
109+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright IBM Corp. 2024 All Rights Reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package power_test
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
12+
acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
13+
)
14+
15+
func TestAccIBMPINetworkPeersDataSourceBasic(t *testing.T) {
16+
networksResData := "data.ibm_pi_network_peers.network_peers"
17+
resource.Test(t, resource.TestCase{
18+
PreCheck: func() { acc.TestAccPreCheck(t) },
19+
Providers: acc.TestAccProviders,
20+
Steps: []resource.TestStep{
21+
{
22+
Config: testAccCheckIBMPINetworkPeersDataSourceConfigBasic(),
23+
Check: resource.ComposeTestCheckFunc(
24+
resource.TestCheckResourceAttrSet(networksResData, "id"),
25+
resource.TestCheckResourceAttrSet(networksResData, "network_peers.#"),
26+
),
27+
},
28+
},
29+
})
30+
}
31+
32+
func testAccCheckIBMPINetworkPeersDataSourceConfigBasic() string {
33+
return fmt.Sprintf(`
34+
data "ibm_pi_network_peers" "network_peers" {
35+
pi_cloud_instance_id = "%s"
36+
}`, acc.Pi_cloud_instance_id)
37+
}

ibm/service/power/data_source_ibm_pi_networks.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ func DataSourceIBMPINetworks() *schema.Resource {
3737
Schema: map[string]*schema.Schema{
3838
Attr_AccessConfig: {
3939
Computed: true,
40-
Description: "The network communication configuration option of the network (for satellite locations only).",
40+
Deprecated: "This field is deprecated please use peer_id instead.",
41+
Description: "The network communication configuration option of the network (for on-prem locations only). Use `peer_id` instead.",
4142
Type: schema.TypeString,
4243
},
4344
Attr_CRN: {
@@ -70,6 +71,11 @@ func DataSourceIBMPINetworks() *schema.Resource {
7071
Description: "The unique identifier of a network.",
7172
Type: schema.TypeString,
7273
},
74+
Attr_PeerID: {
75+
Computed: true,
76+
Description: "Network Peer ID.",
77+
Type: schema.TypeString,
78+
},
7379
Attr_Type: {
7480
Computed: true,
7581
Description: "The type of network.",
@@ -126,6 +132,7 @@ func flattenNetworks(list []*models.NetworkReference, meta interface{}) []map[st
126132
Attr_MTU: i.Mtu,
127133
Attr_Name: *i.Name,
128134
Attr_NetworkID: *i.NetworkID,
135+
Attr_PeerID: i.PeerID,
129136
Attr_Type: *i.Type,
130137
Attr_VLanID: *i.VlanID,
131138
}

ibm/service/power/ibm_pi_constants.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ const (
5353
Arg_NetworkID = "pi_network_id"
5454
Arg_NetworkInterfaceID = "pi_network_interface_id"
5555
Arg_NetworkName = "pi_network_name"
56+
Arg_NetworkPeer = "pi_network_peer"
5657
Arg_NetworkSecurityGroupID = "pi_network_security_group_id"
5758
Arg_NetworkSecurityGroupMemberID = "pi_network_security_group_member_id"
5859
Arg_NetworkSecurityGroupRuleID = "pi_network_security_group_rule_id"
@@ -279,9 +280,11 @@ const (
279280
Attr_Name = "name"
280281
Attr_NetworkAddressGroupID = "network_address_group_id"
281282
Attr_NetworkAddressGroups = "network_address_groups"
283+
Attr_NetworkAddressTranslation = "network_address_translation"
282284
Attr_NetworkID = "network_id"
283285
Attr_NetworkInterfaceID = "network_interface_id"
284286
Attr_NetworkName = "network_name"
287+
Attr_NetworkPeers = "network_peers"
285288
Attr_NetworkPorts = "network_ports"
286289
Attr_Networks = "networks"
287290
Attr_NetworkSecurityGroupID = "network_security_group_id"
@@ -291,6 +294,7 @@ const (
291294
Attr_Onboardings = "onboardings"
292295
Attr_OperatingSystem = "operating_system"
293296
Attr_OSType = "os_type"
297+
Attr_PeerID = "peer_id"
294298
Attr_PercentComplete = "percent_complete"
295299
Attr_PinPolicy = "pin_policy"
296300
Attr_PlacementGroupID = "placement_group_id"
@@ -345,6 +349,7 @@ const (
345349
Attr_Size = "size"
346350
Attr_SnapshotID = "snapshot_id"
347351
Attr_SourceChecksum = "source_checksum"
352+
Attr_SourceIP = "source_ip"
348353
Attr_SourcePort = "source_port"
349354
Attr_SourceVolumeID = "source_volume_id"
350355
Attr_SourceVolumeName = "source_volume_name"
@@ -468,8 +473,11 @@ const (
468473
HostGroup = "hostGroup"
469474
ICMP = "icmp"
470475
IPV4_Address = "ipv4-address"
471-
NAG = "network-address-group"
476+
L2 = "L2"
477+
L3BGP = "L3BGP"
478+
L3Static = "L3Static"
472479
MaxVolumeSupport = "maxVolumeSupport"
480+
NAG = "network-address-group"
473481
Netweaver = "Netweaver"
474482
Network_Interface = "network-interface"
475483
None = "none"

0 commit comments

Comments
 (0)