@@ -5,15 +5,15 @@ package power
55
66import (
77 "context"
8+ "fmt"
89 "log"
910
10- "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
11- "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12-
1311 "github.com/IBM-Cloud/power-go-client/clients/instance"
1412 "github.com/IBM-Cloud/power-go-client/power/models"
1513 "github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
1614 "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
15+ "github.com/hashicorp/terraform-plugin-sdk/v2/diag"
16+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
1717 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
1818)
1919
@@ -205,18 +205,22 @@ func DataSourceIBMPINetworkSecurityGroup() *schema.Resource {
205205 }
206206}
207207
208- func dataSourceIBMPINetworkSecurityGroupRead (ctx context.Context , d * schema.ResourceData , meta interface {} ) diag.Diagnostics {
208+ func dataSourceIBMPINetworkSecurityGroupRead (ctx context.Context , d * schema.ResourceData , meta any ) diag.Diagnostics {
209209 sess , err := meta .(conns.ClientSession ).IBMPISession ()
210210 if err != nil {
211- return diag .FromErr (err )
211+ tfErr := flex .TerraformErrorf (err , fmt .Sprintf ("IBMPISession failed: %s" , err .Error ()), "(Data) ibm_pi_network_security_group" , "read" )
212+ log .Printf ("[DEBUG]\n %s" , tfErr .GetDebugMessage ())
213+ return tfErr .GetDiag ()
212214 }
213215
214216 cloudInstanceID := d .Get (Arg_CloudInstanceID ).(string )
215217 nsgClient := instance .NewIBMIPINetworkSecurityGroupClient (ctx , sess , cloudInstanceID )
216218
217219 networkSecurityGroup , err := nsgClient .Get (d .Get (Arg_NetworkSecurityGroupID ).(string ))
218220 if err != nil {
219- return diag .FromErr (err )
221+ tfErr := flex .TerraformErrorf (err , fmt .Sprintf ("Get failed: %s" , err .Error ()), "(Data) ibm_pi_network_security_group" , "read" )
222+ log .Printf ("[DEBUG]\n %s" , tfErr .GetDebugMessage ())
223+ return tfErr .GetDiag ()
220224 }
221225
222226 d .SetId (* networkSecurityGroup .ID )
@@ -231,7 +235,7 @@ func dataSourceIBMPINetworkSecurityGroupRead(ctx context.Context, d *schema.Reso
231235 d .Set (Attr_Default , networkSecurityGroup .Default )
232236
233237 if len (networkSecurityGroup .Members ) > 0 {
234- members := []map [string ]interface {} {}
238+ members := []map [string ]any {}
235239 for _ , mbr := range networkSecurityGroup .Members {
236240 mbrMap := networkSecurityGroupMemberToMap (mbr )
237241 members = append (members , mbrMap )
@@ -242,7 +246,7 @@ func dataSourceIBMPINetworkSecurityGroupRead(ctx context.Context, d *schema.Reso
242246 d .Set (Attr_Name , networkSecurityGroup .Name )
243247
244248 if len (networkSecurityGroup .Rules ) > 0 {
245- rules := []map [string ]interface {} {}
249+ rules := []map [string ]any {}
246250 for _ , rule := range networkSecurityGroup .Rules {
247251 ruleMap := networkSecurityGroupRuleToMap (rule )
248252 rules = append (rules , ruleMap )
@@ -253,8 +257,8 @@ func dataSourceIBMPINetworkSecurityGroupRead(ctx context.Context, d *schema.Reso
253257 return nil
254258}
255259
256- func networkSecurityGroupMemberToMap (mbr * models.NetworkSecurityGroupMember ) map [string ]interface {} {
257- mbrMap := make (map [string ]interface {} )
260+ func networkSecurityGroupMemberToMap (mbr * models.NetworkSecurityGroupMember ) map [string ]any {
261+ mbrMap := make (map [string ]any )
258262 mbrMap [Attr_ID ] = mbr .ID
259263 if mbr .MacAddress != "" {
260264 mbrMap [Attr_MacAddress ] = mbr .MacAddress
@@ -267,46 +271,46 @@ func networkSecurityGroupMemberToMap(mbr *models.NetworkSecurityGroupMember) map
267271 return mbrMap
268272}
269273
270- func networkSecurityGroupRuleToMap (rule * models.NetworkSecurityGroupRule ) map [string ]interface {} {
271- ruleMap := make (map [string ]interface {} )
274+ func networkSecurityGroupRuleToMap (rule * models.NetworkSecurityGroupRule ) map [string ]any {
275+ ruleMap := make (map [string ]any )
272276 ruleMap [Attr_Action ] = rule .Action
273277 if rule .DestinationPort != nil {
274278 destinationPortMap := networkSecurityGroupRulePortToMap (rule .DestinationPort )
275- ruleMap [Attr_DestinationPort ] = []map [string ]interface {} {destinationPortMap }
279+ ruleMap [Attr_DestinationPort ] = []map [string ]any {destinationPortMap }
276280 }
277281
278282 ruleMap [Attr_ID ] = rule .ID
279283
280284 protocolMap := networkSecurityGroupRuleProtocolToMap (rule .Protocol )
281- ruleMap [Attr_Protocol ] = []map [string ]interface {} {protocolMap }
285+ ruleMap [Attr_Protocol ] = []map [string ]any {protocolMap }
282286
283287 remoteMap := networkSecurityGroupRuleRemoteToMap (rule .Remote )
284- ruleMap [Attr_Remote ] = []map [string ]interface {} {remoteMap }
288+ ruleMap [Attr_Remote ] = []map [string ]any {remoteMap }
285289
286290 if rule .SourcePort != nil {
287291 sourcePortMap := networkSecurityGroupRulePortToMap (rule .SourcePort )
288- ruleMap [Attr_SourcePort ] = []map [string ]interface {} {sourcePortMap }
292+ ruleMap [Attr_SourcePort ] = []map [string ]any {sourcePortMap }
289293 }
290294
291295 return ruleMap
292296}
293297
294- func networkSecurityGroupRulePortToMap (port * models.NetworkSecurityGroupRulePort ) map [string ]interface {} {
295- portMap := make (map [string ]interface {} )
298+ func networkSecurityGroupRulePortToMap (port * models.NetworkSecurityGroupRulePort ) map [string ]any {
299+ portMap := make (map [string ]any )
296300 portMap [Attr_Maximum ] = port .Maximum
297301 portMap [Attr_Minimum ] = port .Minimum
298302 return portMap
299303}
300304
301- func networkSecurityGroupRuleProtocolToMap (protocol * models.NetworkSecurityGroupRuleProtocol ) map [string ]interface {} {
302- protocolMap := make (map [string ]interface {} )
305+ func networkSecurityGroupRuleProtocolToMap (protocol * models.NetworkSecurityGroupRuleProtocol ) map [string ]any {
306+ protocolMap := make (map [string ]any )
303307 if protocol .IcmpType != nil {
304308 protocolMap [Attr_ICMPType ] = protocol .IcmpType
305309 }
306310 if len (protocol .TCPFlags ) > 0 {
307- tcpFlags := []map [string ]interface {} {}
311+ tcpFlags := []map [string ]any {}
308312 for _ , tcpFlagsItem := range protocol .TCPFlags {
309- tcpFlagsItemMap := make (map [string ]interface {} )
313+ tcpFlagsItemMap := make (map [string ]any )
310314 tcpFlagsItemMap [Attr_Flag ] = tcpFlagsItem .Flag
311315 tcpFlags = append (tcpFlags , tcpFlagsItemMap )
312316 }
@@ -318,8 +322,8 @@ func networkSecurityGroupRuleProtocolToMap(protocol *models.NetworkSecurityGroup
318322 return protocolMap
319323}
320324
321- func networkSecurityGroupRuleRemoteToMap (remote * models.NetworkSecurityGroupRuleRemote ) map [string ]interface {} {
322- remoteMap := make (map [string ]interface {} )
325+ func networkSecurityGroupRuleRemoteToMap (remote * models.NetworkSecurityGroupRuleRemote ) map [string ]any {
326+ remoteMap := make (map [string ]any )
323327 if remote .ID != "" {
324328 remoteMap [Attr_ID ] = remote .ID
325329 }
0 commit comments