Skip to content

Commit 50aade4

Browse files
committed
Network Peers
Add [D]: pi_network_peers Update [D]: pi_network, pi_networks Update [R]: pi_network
1 parent 0fc55fc commit 50aade4

14 files changed

+440
-51
lines changed

go.mod

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ toolchain go1.22.5
77
require (
88
github.com/IBM-Cloud/bluemix-go v0.0.0-20240926024252-81b3928fd062
99
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113
10-
github.com/IBM-Cloud/power-go-client v1.8.3
10+
github.com/IBM-Cloud/power-go-client v1.9.0-beta5
1111
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca
1212
github.com/IBM/appconfiguration-go-admin-sdk v0.3.0
1313
github.com/IBM/appid-management-go-sdk v0.0.0-20210908164609-dd0e0eaf732f
@@ -76,7 +76,6 @@ require (
7676
require (
7777
cloud.google.com/go/kms v1.10.1 // indirect
7878
cloud.google.com/go/monitoring v1.13.0 // indirect
79-
github.com/Bowery/prompt v0.0.0-20190916142128-fa8279994f75 // indirect
8079
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 // indirect
8180
github.com/PromonLogicalis/asn1 v0.0.0-20190312173541-d60463189a56 // indirect
8281
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
@@ -95,7 +94,6 @@ require (
9594
github.com/coreos/pkg v0.0.0-20220810130054-c7d1c02cb6cf // indirect
9695
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
9796
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a // indirect
98-
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185 // indirect
9997
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
10098
github.com/eapache/go-resiliency v1.4.0 // indirect
10199
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
@@ -128,7 +126,6 @@ require (
128126
github.com/google/gnostic v0.6.9 // indirect
129127
github.com/google/go-querystring v1.1.0 // indirect
130128
github.com/google/gofuzz v1.2.0 // indirect
131-
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
132129
github.com/hashicorp/errwrap v1.1.0 // indirect
133130
github.com/hashicorp/go-checkpoint v0.5.0 // indirect
134131
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
@@ -169,7 +166,6 @@ require (
169166
github.com/jmespath/go-jmespath v0.4.0 // indirect
170167
github.com/josharian/intern v1.0.0 // indirect
171168
github.com/json-iterator/go v1.1.12 // indirect
172-
github.com/kardianos/govendor v1.0.9 // indirect
173169
github.com/klauspost/compress v1.16.7 // indirect
174170
github.com/kube-object-storage/lib-bucket-provisioner v0.0.0-20221122204822-d1a8c34382f1 // indirect
175171
github.com/leodido/go-urn v1.4.0 // indirect
@@ -181,8 +177,6 @@ require (
181177
github.com/mitchellh/copystructure v1.2.0 // indirect
182178
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
183179
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
184-
github.com/mitchellh/gox v1.0.1 // indirect
185-
github.com/mitchellh/iochan v1.0.0 // indirect
186180
github.com/mitchellh/mapstructure v1.5.0 // indirect
187181
github.com/mitchellh/reflectwalk v1.0.2 // indirect
188182
github.com/moby/spdystream v0.2.0 // indirect
@@ -223,9 +217,6 @@ require (
223217
golang.org/x/term v0.22.0 // indirect
224218
golang.org/x/text v0.16.0 // indirect
225219
golang.org/x/time v0.3.0 // indirect
226-
golang.org/x/tools v0.23.0 // indirect
227-
golang.org/x/tools/cmd/cover v0.1.0-deprecated // indirect
228-
golang.org/x/tools/go/vcs v0.1.0-deprecated // indirect
229220
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
230221
google.golang.org/appengine v1.6.7 // indirect
231222
google.golang.org/genproto/googleapis/rpc v0.0.0-20230525234030-28d5490b6b19 // indirect

go.sum

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ github.com/Azure/go-autorest/logger v0.2.1/go.mod h1:T9E3cAhj2VqvPOtCYAvby9aBXkZ
105105
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
106106
github.com/Azure/go-autorest/tracing v0.6.0 h1:TYi4+3m5t6K48TGI9AUdb+IzbnSxvnvUMfuitfgcfuo=
107107
github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBpUA79WCAKPPZVC2DeU=
108-
github.com/Bowery/prompt v0.0.0-20190916142128-fa8279994f75 h1:xGHheKK44eC6K0u5X+DZW/fRaR1LnDdqPHMZMWx5fv8=
109-
github.com/Bowery/prompt v0.0.0-20190916142128-fa8279994f75/go.mod h1:4/6eNcqZ09BZ9wLK3tZOjBA1nDj+B0728nlX5YRlSmQ=
110108
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
111109
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
112110
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
@@ -120,8 +118,8 @@ github.com/IBM-Cloud/bluemix-go v0.0.0-20240926024252-81b3928fd062/go.mod h1:/7h
120118
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113 h1:f2Erqfea1dKpaTFagTJM6W/wnD3JGq/Vn9URh8nuRwk=
121119
github.com/IBM-Cloud/container-services-go-sdk v0.0.0-20240725064144-454a2ae23113/go.mod h1:xUQL9SGAjoZFd4GNjrjjtEpjpkgU7RFXRyHesbKTjiY=
122120
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.5.3/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
123-
github.com/IBM-Cloud/power-go-client v1.8.3 h1:QsBuIS6KvKsiEpe0yiHYKhWgXlqkcJ7XqFHtATj8Yh4=
124-
github.com/IBM-Cloud/power-go-client v1.8.3/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0=
121+
github.com/IBM-Cloud/power-go-client v1.9.0-beta5 h1:W2mnJxwuS+pP8Dsu3HtEqg+csx7z8MQuFfiB6xee91o=
122+
github.com/IBM-Cloud/power-go-client v1.9.0-beta5/go.mod h1:UDyXeIKEp6r7yWUXYu3r0ZnFSlNZ2YeQTHwM2Tmlgv0=
125123
github.com/IBM-Cloud/softlayer-go v1.0.5-tf h1:koUAyF9b6X78lLLruGYPSOmrfY2YcGYKOj/Ug9nbKNw=
126124
github.com/IBM-Cloud/softlayer-go v1.0.5-tf/go.mod h1:6HepcfAXROz0Rf63krk5hPZyHT6qyx2MNvYyHof7ik4=
127125
github.com/IBM/apigateway-go-sdk v0.0.0-20210714141226-a5d5d49caaca h1:crniVcf+YcmgF03NmmfonXwSQ73oJF+IohFYBwknMxs=
@@ -395,8 +393,6 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
395393
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
396394
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a h1:saTgr5tMLFnmy/yg3qDTft4rE5DY2uJ/cCxCe3q0XTU=
397395
github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a/go.mod h1:Bw9BbhOJVNR+t0jCqx2GC6zv0TGBsShs56Y3gfSCvl0=
398-
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185 h1:3T8ZyTDp5QxTx3NU48JVb2u+75xc040fofcBaN+6jPA=
399-
github.com/dchest/safefile v0.0.0-20151022103144-855e8d98f185/go.mod h1:cFRxtTwTOJkz2x3rQUNCYKWC93yP1VKjR8NUhqFxZNU=
400396
github.com/denisenkom/go-mssqldb v0.0.0-20190412130859-3b1d194e553a/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
401397
github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba h1:p6poVbjHDkKa+wtC8frBMwQtT3BmqGYBjzMwJ63tuR4=
402398
github.com/denverdino/aliyungo v0.0.0-20190125010748-a747050bb1ba/go.mod h1:dV8lFg6daOBZbT6/BDGIz6Y3WFGn8juu6G+CQ6LHtl0=
@@ -788,8 +784,6 @@ github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLe
788784
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 h1:k7nVchz72niMH6YLQNvHSdIE7iqsQxK1P41mySCvssg=
789785
github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw=
790786
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
791-
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
792-
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
793787
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
794788
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
795789
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
@@ -959,7 +953,6 @@ github.com/hashicorp/go-uuid v1.0.2-0.20191001231223-f32f5fe8d6a8/go.mod h1:6SBZ
959953
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
960954
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
961955
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
962-
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
963956
github.com/hashicorp/go-version v1.1.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
964957
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
965958
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
@@ -1152,8 +1145,6 @@ github.com/jtolds/gls v4.2.1+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVY
11521145
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
11531146
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
11541147
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
1155-
github.com/kardianos/govendor v1.0.9 h1:WOH3FcVI9eOgnIZYg96iwUwrL4eOVx+aQ66oyX2R8Yc=
1156-
github.com/kardianos/govendor v1.0.9/go.mod h1:yvmR6q9ZZ7nSF5Wvh40v0wfP+3TwwL8zYQp+itoZSVM=
11571148
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
11581149
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
11591150
github.com/kelseyhightower/envconfig v1.3.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
@@ -1272,10 +1263,7 @@ github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp
12721263
github.com/mitchellh/go-wordwrap v1.0.0 h1:6GlHJ/LTGMrIJbwgdqdl2eEH8o+Exx/0m8ir9Gns0u4=
12731264
github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
12741265
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
1275-
github.com/mitchellh/gox v1.0.1 h1:x0jD3dcHk9a9xPSDN6YEL4xL6Qz0dvNYm8yZqui5chI=
1276-
github.com/mitchellh/gox v1.0.1/go.mod h1:ED6BioOGXMswlXa2zxfh/xdd5QhwYliBFn9V18Ap4z4=
12771266
github.com/mitchellh/hashstructure v1.0.0/go.mod h1:QjSHrPWS+BGUVBYkbTZWEnOh3G1DutKwClXU/ABz6AQ=
1278-
github.com/mitchellh/iochan v1.0.0 h1:C+X3KsSTLFVBr/tK1eYN/vs4rJcvsiLU338UhYPJWeY=
12791267
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
12801268
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
12811269
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
@@ -2210,10 +2198,6 @@ golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58
22102198
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
22112199
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
22122200
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
2213-
golang.org/x/tools/cmd/cover v0.1.0-deprecated h1:Rwy+mWYz6loAF+LnG1jHG/JWMHRMMC2/1XX3Ejkx9lA=
2214-
golang.org/x/tools/cmd/cover v0.1.0-deprecated/go.mod h1:hMDiIvlpN1NoVgmjLjUJE9tMHyxHjFX7RuQ+rW12mSA=
2215-
golang.org/x/tools/go/vcs v0.1.0-deprecated h1:cOIJqWBl99H1dH5LWizPa+0ImeeJq3t3cJjaeOWUAL4=
2216-
golang.org/x/tools/go/vcs v0.1.0-deprecated/go.mod h1:zUrvATBAvEI9535oC0yWYsLsHIV4Z7g63sNPVMtuBy8=
22172201
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
22182202
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
22192203
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

ibm/provider/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ func Provider() *schema.Provider {
666666
"ibm_pi_network_address_groups": power.DataSourceIBMPINetworkAddressGroups(),
667667
"ibm_pi_network_interface": power.DataSourceIBMPINetworkInterface(),
668668
"ibm_pi_network_interfaces": power.DataSourceIBMPINetworkInterfaces(),
669+
"ibm_pi_network_peers": power.DataSourceIBMPINetworkPeers(),
669670
"ibm_pi_network_port": power.DataSourceIBMPINetworkPort(),
670671
"ibm_pi_network_security_group": power.DataSourceIBMPINetworkSecurityGroup(),
671672
"ibm_pi_network_security_groups": power.DataSourceIBMPINetworkSecurityGroups(),

ibm/service/power/data_source_ibm_pi_network.go

Lines changed: 28 additions & 1 deletion
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
}
Lines changed: 109 additions & 0 deletions
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+
}
Lines changed: 37 additions & 0 deletions
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

Lines changed: 8 additions & 1 deletion
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
}

0 commit comments

Comments
 (0)