github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/tencentcloud/tcaplus.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 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" 20 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" 21 tcaplus "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcaplusdb/v20190823" 22 ) 23 24 type TcaplusGenerator struct { 25 TencentCloudService 26 } 27 28 func (g *TcaplusGenerator) InitResources() error { 29 args := g.GetArgs() 30 region := args["region"].(string) 31 credential := args["credential"].(common.Credential) 32 profile := NewTencentCloudClientProfile() 33 client, err := tcaplus.NewClient(&credential, region, profile) 34 if err != nil { 35 return err 36 } 37 38 request := tcaplus.NewDescribeClustersRequest() 39 40 var offset int64 = 0 41 var pageSize int64 = 50 42 allInstances := make([]*tcaplus.ClusterInfo, 0) 43 44 for { 45 request.Offset = &offset 46 request.Limit = &pageSize 47 response, err := client.DescribeClusters(request) 48 if err != nil { 49 sdkErr, ok := err.(*errors.TencentCloudSDKError) 50 if ok && sdkErr.Code == "UnsupportedRegion" { 51 return nil 52 } 53 return err 54 } 55 56 allInstances = append(allInstances, response.Response.Clusters...) 57 if len(response.Response.Clusters) < int(pageSize) { 58 break 59 } 60 offset += pageSize 61 } 62 63 for _, instance := range allInstances { 64 resource := terraformutils.NewResource( 65 *instance.ClusterId, 66 *instance.ClusterName+"_"+*instance.ClusterId, 67 "tencentcloud_tcaplus_cluster", 68 "tencentcloud", 69 map[string]string{}, 70 []string{}, 71 map[string]interface{}{}, 72 ) 73 g.Resources = append(g.Resources, resource) 74 } 75 76 return nil 77 }