in providers/ibm/ibm_dl.go [67:143]
func (g *DLGenerator) InitResources() error {
apiKey := os.Getenv("IC_API_KEY")
if apiKey == "" {
return fmt.Errorf("no API key set")
}
dlURL := "https://directlink.cloud.ibm.com/v1"
directlinkOptions := &dl.DirectLinkV1Options{
URL: envFallBack([]string{"IBMCLOUD_DL_API_ENDPOINT"}, dlURL),
Authenticator: &core.IamAuthenticator{
ApiKey: apiKey,
},
Version: CreateVersionDate(),
}
dlclient, err := dl.NewDirectLinkV1(directlinkOptions)
if err != nil {
return err
}
listGatewaysOptions := &dl.ListGatewaysOptions{}
gateways, response, err := dlclient.ListGateways(listGatewaysOptions)
if err != nil {
return fmt.Errorf("Error Fetching Direct Link Gateways %s\n%s", err, response)
}
if gateways.Gateways != nil {
for _, gateway := range gateways.Gateways {
g.Resources = append(g.Resources, g.createDirectLinkGatewayResources(*gateway.ID, *gateway.Name))
resourceName := g.Resources[len(g.Resources)-1:][0].ResourceName
var dependsOn []string
dependsOn = append(dependsOn, "ibm_dl_gateway."+resourceName)
listGatewayVirtualConnectionsOptions := &dl.ListGatewayVirtualConnectionsOptions{
GatewayID: gateway.ID,
}
connections, response, err := dlclient.ListGatewayVirtualConnections(listGatewayVirtualConnectionsOptions)
if err != nil {
return fmt.Errorf("Error Fetching Direct Link Virtual connections %s\n%s", err, response)
}
for _, connection := range connections.VirtualConnections {
g.Resources = append(g.Resources, g.createDirectLinkVirtualConnectionResources(*gateway.ID, *connection.ID, *connection.Name, dependsOn))
}
}
}
dlproviderURL := "https://directlink.cloud.ibm.com/provider/v2"
dlproviderOptions := &dlProviderV2.DirectLinkProviderV2Options{
URL: envFallBack([]string{"IBMCLOUD_DL_PROVIDER_API_ENDPOINT"}, dlproviderURL),
Authenticator: &core.IamAuthenticator{
ApiKey: apiKey,
},
Version: CreateVersionDate(),
}
dlproviderclient, err := dlProviderV2.NewDirectLinkProviderV2(dlproviderOptions)
if err != nil {
return err
}
start := ""
allrecs := []dlProviderV2.ProviderGateway{}
for {
listProviderGatewaysOptions := &dlProviderV2.ListProviderGatewaysOptions{}
if start != "" {
listProviderGatewaysOptions.Start = &start
}
providerGateways, resp, err := dlproviderclient.ListProviderGateways(listProviderGatewaysOptions)
if err != nil {
return fmt.Errorf("Error Listing Direct Link Provider Gateways %s\n%s", err, resp)
}
start = GetNext(providerGateways.Next)
allrecs = append(allrecs, providerGateways.Gateways...)
if start == "" {
break
}
}
for _, providerGateway := range allrecs {
g.Resources = append(g.Resources, g.createDirectLinkProviderGatewayResources(*providerGateway.ID, *providerGateway.Name))
}
return nil
}