github.com/GoogleCloudPlatform/terraformer@v0.8.18/providers/tencentcloud/vpc.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 "strconv" 19 20 "github.com/GoogleCloudPlatform/terraformer/terraformutils" 21 "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" 22 vpc "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/vpc/v20170312" 23 ) 24 25 type VpcGenerator struct { 26 TencentCloudService 27 } 28 29 func (g *VpcGenerator) InitResources() error { 30 args := g.GetArgs() 31 region := args["region"].(string) 32 credential := args["credential"].(common.Credential) 33 profile := NewTencentCloudClientProfile() 34 client, err := vpc.NewClient(&credential, region, profile) 35 if err != nil { 36 return err 37 } 38 39 request := vpc.NewDescribeVpcsRequest() 40 offset := 0 41 pageSize := 50 42 allVpcs := make([]*vpc.Vpc, 0) 43 44 for { 45 offsetString := strconv.Itoa(offset) 46 limitString := strconv.Itoa(pageSize) 47 request.Offset = &offsetString 48 request.Limit = &limitString 49 response, err := client.DescribeVpcs(request) 50 if err != nil { 51 return err 52 } 53 54 allVpcs = append(allVpcs, response.Response.VpcSet...) 55 if len(response.Response.VpcSet) < pageSize { 56 break 57 } 58 offset += pageSize 59 } 60 61 for _, vpcInstance := range allVpcs { 62 resource := terraformutils.NewResource( 63 *vpcInstance.VpcId, 64 *vpcInstance.VpcName+"_"+*vpcInstance.VpcId, 65 "tencentcloud_vpc", 66 "tencentcloud", 67 map[string]string{}, 68 []string{}, 69 map[string]interface{}{}, 70 ) 71 g.Resources = append(g.Resources, resource) 72 } 73 74 return nil 75 }