@@ -7,9 +7,11 @@ import (
77 "fmt"
88 "log"
99
10- "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
1110 "github.com/IBM/networking-go-sdk/transitgatewayapisv1"
1211 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12+
13+ "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
14+ "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate"
1315)
1416
1517const (
@@ -195,94 +197,103 @@ func dataSourceIBMTransitGatewayConnectionsRead(d *schema.ResourceData, meta int
195197 if err != nil {
196198 return err
197199 }
200+ startSub := ""
198201 listTransitGatewayConnectionsOptions := & transitgatewayapisv1.ListTransitGatewayConnectionsOptions {}
199202 tgGatewayId := d .Id ()
200203 log .Println ("tgGatewayId: " , tgGatewayId )
201204
202205 listTransitGatewayConnectionsOptions .SetTransitGatewayID (tgGatewayId )
203- listTGConnections , response , err := client .ListTransitGatewayConnections (listTransitGatewayConnectionsOptions )
204- if err != nil {
205- return fmt .Errorf ("[ERROR] Error while listing transit gateway connections %s\n %s" , err , response )
206- }
207206 connections := make ([]map [string ]interface {}, 0 )
207+ for {
208208
209- for _ , instance := range listTGConnections .Connections {
210- tgConn := map [string ]interface {}{}
211-
212- if instance .ID != nil {
213- tgConn [ID ] = * instance .ID
209+ if startSub != "" {
210+ listTransitGatewayConnectionsOptions .Start = & startSub
214211 }
215- if instance .Name != nil {
216- tgConn [tgConnName ] = * instance .Name
217- }
218- if instance .NetworkType != nil {
219- tgConn [tgNetworkType ] = * instance .NetworkType
212+ listTGConnections , response , err := client .ListTransitGatewayConnections (listTransitGatewayConnectionsOptions )
213+ if err != nil {
214+ return fmt .Errorf ("[ERROR] Error while listing transit gateway connections %s\n %s" , err , response )
220215 }
216+ for _ , instance := range listTGConnections .Connections {
217+ tgConn := map [string ]interface {}{}
221218
222- if instance .NetworkID != nil {
223- tgConn [tgNetworkId ] = * instance .NetworkID
224- }
225- if instance .NetworkAccountID != nil {
226- tgConn [tgNetworkAccountID ] = * instance .NetworkAccountID
227- }
219+ if instance .ID != nil {
220+ tgConn [ID ] = * instance .ID
221+ }
222+ if instance .Name != nil {
223+ tgConn [tgConnName ] = * instance .Name
224+ }
225+ if instance .NetworkType != nil {
226+ tgConn [tgNetworkType ] = * instance .NetworkType
227+ }
228228
229- if instance .BaseConnectionID != nil {
230- tgConn [tgBaseConnectionId ] = * instance .BaseConnectionID
231- }
229+ if instance .NetworkID != nil {
230+ tgConn [tgNetworkId ] = * instance .NetworkID
231+ }
232+ if instance .NetworkAccountID != nil {
233+ tgConn [tgNetworkAccountID ] = * instance .NetworkAccountID
234+ }
232235
233- if instance .BaseNetworkType != nil {
234- tgConn [tgBaseNetworkType ] = * instance .BaseNetworkType
235- }
236+ if instance .BaseConnectionID != nil {
237+ tgConn [tgBaseConnectionId ] = * instance .BaseConnectionID
238+ }
236239
237- if instance .LocalBgpAsn != nil {
238- tgConn [tgLocalBgpAsn ] = * instance .LocalBgpAsn
239- }
240+ if instance .BaseNetworkType != nil {
241+ tgConn [tgBaseNetworkType ] = * instance .BaseNetworkType
242+ }
240243
241- if instance .LocalGatewayIp != nil {
242- tgConn [tgLocalGatewayIp ] = * instance .LocalGatewayIp
243- }
244+ if instance .LocalBgpAsn != nil {
245+ tgConn [tgLocalBgpAsn ] = * instance .LocalBgpAsn
246+ }
244247
245- if instance .LocalTunnelIp != nil {
246- tgConn [tgLocalTunnelIp ] = * instance .LocalTunnelIp
247- }
248+ if instance .LocalGatewayIp != nil {
249+ tgConn [tgLocalGatewayIp ] = * instance .LocalGatewayIp
250+ }
248251
249- if instance .RemoteBgpAsn != nil {
250- tgConn [tgRemoteBgpAsn ] = * instance .RemoteBgpAsn
251- }
252+ if instance .LocalTunnelIp != nil {
253+ tgConn [tgLocalTunnelIp ] = * instance .LocalTunnelIp
254+ }
252255
253- if instance .RemoteGatewayIp != nil {
254- tgConn [tgRemoteGatewayIp ] = * instance .RemoteGatewayIp
255- }
256+ if instance .RemoteBgpAsn != nil {
257+ tgConn [tgRemoteBgpAsn ] = * instance .RemoteBgpAsn
258+ }
256259
257- if instance .RemoteTunnelIp != nil {
258- tgConn [tgRemoteTunnelIp ] = * instance .RemoteTunnelIp
259- }
260+ if instance .RemoteGatewayIp != nil {
261+ tgConn [tgRemoteGatewayIp ] = * instance .RemoteGatewayIp
262+ }
260263
261- if instance .Zone != nil {
262- tgConn [tgZone ] = * instance .Zone . Name
263- }
264+ if instance .RemoteTunnelIp != nil {
265+ tgConn [tgRemoteTunnelIp ] = * instance .RemoteTunnelIp
266+ }
264267
265- if instance .Mtu != nil {
266- tgConn [tgMtu ] = * instance .Mtu
267- }
268+ if instance .Zone != nil {
269+ tgConn [tgZone ] = * instance .Zone . Name
270+ }
268271
269- if instance .CreatedAt != nil {
270- tgConn [tgConectionCreatedAt ] = instance .CreatedAt .String ()
272+ if instance .Mtu != nil {
273+ tgConn [tgMtu ] = * instance .Mtu
274+ }
271275
272- }
273- if instance .UpdatedAt != nil {
274- tgConn [tgUpdatedAt ] = instance .UpdatedAt .String ()
276+ if instance .CreatedAt != nil {
277+ tgConn [tgConectionCreatedAt ] = instance .CreatedAt .String ()
275278
276- }
277- if instance .Status != nil {
278- tgConn [tgConnectionStatus ] = * instance .Status
279- }
279+ }
280+ if instance .UpdatedAt != nil {
281+ tgConn [tgUpdatedAt ] = instance .UpdatedAt .String ()
280282
281- connections = append (connections , tgConn )
283+ }
284+ if instance .Status != nil {
285+ tgConn [tgConnectionStatus ] = * instance .Status
286+ }
287+
288+ connections = append (connections , tgConn )
282289
290+ }
291+ startSub = flex .GetNext (listTGConnections .Next )
292+ if startSub == "" {
293+ break
294+ }
283295 }
284296 d .Set (tgConnections , connections )
285-
286297 return nil
287298
288299}
0 commit comments