github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/tencentcloud/clb.go (about) 1 // Copyright 2021 The Terraformer Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tencentcloud 16 17 import ( 18 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 19 clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317" 20 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" 21 ) 22 23 type ClbGenerator struct { 24 TencentCloudService 25 } 26 27 func (g *ClbGenerator) InitResources() error { 28 args := g.GetArgs() 29 region := args["region"].(string) 30 credential := args["credential"].(common.Credential) 31 profile := NewTencentCloudClientProfile() 32 client, err := clb.NewClient(&credential, region, profile) 33 if err != nil { 34 return err 35 } 36 37 request := clb.NewDescribeLoadBalancersRequest() 38 var offset int64 = 0 39 var pageSize int64 = 50 40 allInstances := make([]*clb.LoadBalancer, 0) 41 42 for { 43 request.Offset = &offset 44 request.Limit = &pageSize 45 response, err := client.DescribeLoadBalancers(request) 46 if err != nil { 47 return err 48 } 49 50 allInstances = append(allInstances, response.Response.LoadBalancerSet...) 51 if len(response.Response.LoadBalancerSet) < int(pageSize) { 52 break 53 } 54 offset += pageSize 55 } 56 57 for _, instance := range allInstances { 58 resource := terraformutils.NewResource( 59 *instance.LoadBalancerId, 60 *instance.LoadBalancerName+"_"+*instance.LoadBalancerId, 61 "tencentcloud_clb_instance", 62 "tencentcloud", 63 map[string]string{}, 64 []string{}, 65 map[string]interface{}{}, 66 ) 67 g.Resources = append(g.Resources, resource) 68 } 69 70 return nil 71 }