@@ -9,7 +9,6 @@ data "tencentcloud_cdn_domains" "foo" {
99 service_type = "web"
1010 full_url_cache = false
1111 origin_pull_protocol = "follow"
12- status = "online"
1312 https_switch = "on"
1413}
1514```
@@ -32,21 +31,21 @@ func dataSourceTencentCloudCdnDomains() *schema.Resource {
3231 "domain" : {
3332 Type : schema .TypeString ,
3433 Optional : true ,
35- Description : "Name of the acceleration domain." ,
34+ Description : "Acceleration domain name ." ,
3635 },
3736 "service_type" : {
3837 Type : schema .TypeString ,
3938 Optional : true ,
4039 ValidateFunc : validateAllowedStringValue (CDN_SERVICE_TYPE ),
41- Description : "Service type of Acceleration domain name. The available value include `web`, `download` and `media`." ,
40+ Description : "Service type of acceleration domain name. The available value include `web`, `download` and `media`." ,
4241 },
4342 "full_url_cache" : {
4443 Type : schema .TypeBool ,
4544 Optional : true ,
4645 Description : "Whether to enable full-path cache." ,
4746 },
4847 "origin_pull_protocol" : {
49- Type : schema .TypeBool ,
48+ Type : schema .TypeString ,
5049 Optional : true ,
5150 ValidateFunc : validateAllowedStringValue (CDN_ORIGIN_PULL_PROTOCOL ),
5251 Description : "Origin-pull protocol configuration. The available value include `http`, `https` and `follow`." ,
@@ -62,29 +61,29 @@ func dataSourceTencentCloudCdnDomains() *schema.Resource {
6261 Optional : true ,
6362 Description : "Used to save results." ,
6463 },
65- "cdn_domain_list " : {
64+ "domain_list " : {
6665 Type : schema .TypeList ,
6766 Computed : true ,
68- Description : "Information list of cdn domain." ,
67+ Description : "An information list of cdn domain. Each element contains the following attributes: " ,
6968 Elem : & schema.Resource {
7069 Schema : map [string ]* schema.Schema {
7170 "domain" : {
7271 Type : schema .TypeString ,
7372 Computed : true ,
74- Description : "Name of the acceleration domain." ,
73+ Description : "Acceleration domain name ." ,
7574 },
7675 "service_type" : {
7776 Type : schema .TypeString ,
7877 Computed : true ,
79- Description : "Service type of Acceleration domain name." ,
78+ Description : "Service type of acceleration domain name." ,
8079 },
8180 "area" : {
8281 Type : schema .TypeString ,
8382 Computed : true ,
84- Description : "Domain name acceleration region." ,
83+ Description : "Acceleration region." ,
8584 },
8685 "project_id" : {
87- Type : schema .TypeString ,
86+ Type : schema .TypeInt ,
8887 Computed : true ,
8988 Description : "The project CDN belongs to." ,
9089 },
@@ -96,7 +95,7 @@ func dataSourceTencentCloudCdnDomains() *schema.Resource {
9695 "origin" : {
9796 Type : schema .TypeList ,
9897 Computed : true ,
99- Description : "Origin server configuration. It's a list and consist of at most one item. " ,
98+ Description : "Origin server configuration." ,
10099 Elem : & schema.Resource {
101100 Schema : map [string ]* schema.Schema {
102101 "origin_type" : {
@@ -203,18 +202,18 @@ func dataSourceTencentCloudCdnDomainsRead(d *schema.ResourceData, meta interface
203202
204203 var domainFilterMap = make (map [string ]interface {}, 5 )
205204
206- if v , ok := d .GetOk (CDN_DATASOURCE_NAME_DOMAIN ); ok {
207- domainFilterMap [CDN_DATASOURCE_NAME_DOMAIN ] = v .(string )
205+ if v , ok := d .GetOk ("domain" ); ok {
206+ domainFilterMap ["domain" ] = v .(string )
208207 }
209208 if v , ok := d .GetOk ("service_type" ); ok {
210209 domainFilterMap ["service_type" ] = v .(string )
211210 }
212- if v , ok := d .GetOk ("status" ); ok {
213- domainFilterMap ["status" ] = v .(string )
214- }
215211 if v , ok := d .GetOk ("https_switch" ); ok {
216212 domainFilterMap ["https_switch" ] = v .(string )
217213 }
214+ if v , ok := d .GetOk ("origin_pull_protocol" ); ok {
215+ domainFilterMap ["origin_pull_protocol" ] = v .(string )
216+ }
218217 if v , ok := d .GetOk ("full_url_cache" ); ok {
219218 var value string
220219 if v .(bool ) {
@@ -226,14 +225,10 @@ func dataSourceTencentCloudCdnDomainsRead(d *schema.ResourceData, meta interface
226225 domainFilterMap ["full_url_cache" ] = value
227226 }
228227
229- if len (domainFilterMap ) == 0 {
230- return nil
231- }
232-
233- var domainConfig * cdn.DetailDomain
228+ var domainConfigs []* cdn.DetailDomain
234229 var errRet error
235230 err := resource .Retry (readRetryTimeout , func () * resource.RetryError {
236- domainConfig , errRet = cdnService .DescribeDomainsConfigByFilters (ctx , domainFilterMap )
231+ domainConfigs , errRet = cdnService .DescribeDomainsConfigByFilters (ctx , domainFilterMap )
237232 if errRet != nil {
238233 return retryError (errRet , InternalError )
239234 }
@@ -244,49 +239,67 @@ func dataSourceTencentCloudCdnDomainsRead(d *schema.ResourceData, meta interface
244239 log .Printf ("[CRITAL]%s describeDomainsConfigByFilters fail, reason:%s\n " , logId , err .Error ())
245240 return err
246241 }
247- if domainConfig == nil {
242+ if domainConfigs == nil {
248243 return nil
249244 }
250245
251- domain := domainFilterMap [ CDN_DATASOURCE_NAME_DOMAIN ]
252- _ = d . Set ( CDN_DATASOURCE_NAME_DOMAIN , domain )
253- _ = d . Set ( "service_type" , domainConfig . ServiceType )
254- _ = d . Set ( "project_id" , domainConfig . ProjectId )
255- _ = d . Set ( "area" , domainConfig . Area )
256- _ = d . Set ( "status" , domainConfig . Status )
246+ cdnDomainList := make ([] map [ string ] interface {}, 0 , len ( domainConfigs ))
247+ for _ , detailDomain := range domainConfigs {
248+ var fullUrlCache bool
249+ if detailDomain . CacheKey != nil && * detailDomain . CacheKey . FullUrlCache == CDN_SWITCH_ON {
250+ fullUrlCache = true
251+ }
257252
258- if * domainConfig .CacheKey .FullUrlCache == CDN_SWITCH_OFF {
259- _ = d .Set ("full_url_cache" , false )
260- } else {
261- _ = d .Set ("full_url_cache" , true )
262- }
253+ origins := make ([]map [string ]interface {}, 0 , 1 )
254+ origin := make (map [string ]interface {}, 8 )
255+ origin ["origin_type" ] = detailDomain .Origin .OriginType
256+ origin ["origin_list" ] = detailDomain .Origin .Origins
257+ origin ["backup_origin_type" ] = detailDomain .Origin .BackupOriginType
258+ origin ["backup_origin_list" ] = detailDomain .Origin .BackupOrigins
259+ origin ["backup_server_name" ] = detailDomain .Origin .BackupServerName
260+ origin ["server_name" ] = detailDomain .Origin .ServerName
261+ origin ["cos_private_access" ] = detailDomain .Origin .CosPrivateAccess
262+ origin ["origin_pull_protocol" ] = detailDomain .Origin .OriginPullProtocol
263+ origins = append (origins , origin )
263264
264- origins := make ([]map [string ]interface {}, 0 , 1 )
265- origin := make (map [string ]interface {}, 8 )
266- origin ["origin_type" ] = domainConfig .Origin .OriginType
267- origin ["origin_list" ] = domainConfig .Origin .Origins
268- origin ["server_name" ] = domainConfig .Origin .ServerName
269- origin ["cos_private_access" ] = domainConfig .Origin .CosPrivateAccess
270- origin ["origin_pull_protocol" ] = domainConfig .Origin .OriginPullProtocol
271- origin ["backup_origin_type" ] = domainConfig .Origin .BackupOriginType
272- origin ["backup_origin_list" ] = domainConfig .Origin .BackupOrigins
273- origin ["backup_server_name" ] = domainConfig .Origin .BackupServerName
274- origins = append (origins , origin )
275- _ = d .Set ("origin" , origins )
265+ httpsconfigs := make ([]map [string ]interface {}, 0 , 1 )
266+ httpsConfig := make (map [string ]interface {}, 7 )
267+ httpsConfig ["https_switch" ] = detailDomain .Https .Switch
268+ httpsConfig ["http2_switch" ] = detailDomain .Https .Http2
269+ httpsConfig ["ocsp_stapling_switch" ] = detailDomain .Https .OcspStapling
270+ httpsConfig ["spdy_switch" ] = detailDomain .Https .Spdy
271+ httpsConfig ["verify_client" ] = detailDomain .Https .VerifyClient
272+ httpsconfigs = append (httpsconfigs , httpsConfig )
276273
277- httpsConfig := make (map [string ]interface {}, 7 )
278- httpsConfig ["https_switch" ] = domainConfig .Https .Switch
279- httpsConfig ["http2_switch" ] = domainConfig .Https .Http2
280- httpsConfig ["ocsp_stapling_switch" ] = domainConfig .Https .OcspStapling
281- httpsConfig ["spdy_switch" ] = domainConfig .Https .Spdy
282- httpsConfig ["verify_client" ] = domainConfig .Https .VerifyClient
283- _ = d .Set ("https_config" , httpsConfig )
274+ tags , errRet := tagService .DescribeResourceTags (ctx , CDN_SERVICE_NAME , CDN_RESOURCE_NAME_DOMAIN , region , * detailDomain .Domain )
275+ if errRet != nil {
276+ return errRet
277+ }
284278
285- tags , errRet := tagService .DescribeResourceTags (ctx , CDN_SERVICE_NAME , CDN_RESOURCE_NAME_DOMAIN , region , domain .(string ))
286- if errRet != nil {
287- return errRet
279+ mapping := map [string ]interface {}{
280+ "domain" : detailDomain .Domain ,
281+ "service_type" : detailDomain .ServiceType ,
282+ "area" : detailDomain .Area ,
283+ "project_id" : detailDomain .ProjectId ,
284+ "full_url_cache" : fullUrlCache ,
285+ "origin" : origins ,
286+ "https_config" : httpsconfigs ,
287+ "tags" : tags ,
288+ }
289+
290+ cdnDomainList = append (cdnDomainList , mapping )
288291 }
289- _ = d .Set ("tags" , tags )
290292
293+ err = d .Set ("domain_list" , cdnDomainList )
294+ if err != nil {
295+ log .Printf ("[CRITAL]%s provider set cdn domain list fail, reason:%s\n " , logId , err .Error ())
296+ return err
297+ }
298+ output , ok := d .GetOk ("result_output_file" )
299+ if ok && output .(string ) != "" {
300+ if err := writeToFile (output .(string ), cdnDomainList ); err != nil {
301+ return err
302+ }
303+ }
291304 return nil
292305}
0 commit comments