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