Skip to content

Commit ece7990

Browse files
author
ttomzhou
committed
merge upstream
2 parents d354b15 + 2ff1bd3 commit ece7990

File tree

9 files changed

+836
-27
lines changed

9 files changed

+836
-27
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ ENHANCEMENTS:
1313
* Resource `tencentcloud_ccn` add `charge_type` to support billing mode setting.
1414
* Resource `tencentcloud_ccn` add `bandwidth_limit_type` to support the speed limit type setting.
1515
* Resource `tencentcloud_ccn_bandwidth_limit` add `dst_region` to support destination area restriction setting.
16+
* Resource `tencentcloud_cdn_domain` add `range_origin_switch` to support range back to source configuration.
17+
* Resource `tencentcloud_cdn_domain` add `rule_cache` to support advanced path cache configuration.
18+
* Resource `tencentcloud_cdn_domain` add `request_header` to support request header configuration.
1619
* Data Source `tencentcloud_ccn_instances` add `charge_type` to support billing mode.
1720
* Data Source `tencentcloud_ccn_instances` add `bandwidth_limit_type` to support the speed limit type.
1821
* Data Source `tencentcloud_ccn_bandwidth_limit` add `dst_region` to support destination area restriction.
22+
* Data Source `tencentcloud_cdn_domains` add `range_origin_switch` to support range back to source configuration.
23+
* Data Source `tencentcloud_cdn_domains` add `rule_cache` to support advanced path cache configuration.
24+
* Data Source `tencentcloud_cdn_domains` add `request_header` to support request header configuration.
1925

2026
## 1.51.1 (December 22, 2020)
2127

examples/tencentcloud-cdn/main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@ resource "tencentcloud_cdn_domain" "foo" {
22
domain = "xxxx.com"
33
service_type = "web"
44
area = "mainland"
5+
range_origin_switch = "off"
6+
7+
rule_cache{
8+
cache_time = 10000
9+
no_cache_switch="on"
10+
re_validate="on"
11+
}
12+
13+
request_header{
14+
switch = "on"
15+
16+
header_rules {
17+
header_mode = "add"
18+
header_name = "tf-header-name"
19+
header_value = "tf-header-value"
20+
rule_type = "all"
21+
rule_paths = ["*"]
22+
}
23+
}
524

625
origin {
726
origin_type = "ip"

tencentcloud/data_source_tc_cdn_domains.go

Lines changed: 167 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,122 @@ func dataSourceTencentCloudCdnDomains() *schema.Resource {
117117
Computed: true,
118118
Description: "Whether to enable full-path cache.",
119119
},
120+
"range_origin_switch": {
121+
Type: schema.TypeString,
122+
Computed: true,
123+
Description: "Sharding back to source configuration switch.",
124+
},
125+
"request_header": {
126+
Type: schema.TypeList,
127+
Computed: true,
128+
Description: "Request header configuration.",
129+
Elem: &schema.Resource{
130+
Schema: map[string]*schema.Schema{
131+
"switch": {
132+
Type: schema.TypeString,
133+
Computed: true,
134+
Description: "Custom request header configuration switch.",
135+
},
136+
"header_rules": {
137+
Type: schema.TypeList,
138+
Computed: true,
139+
Description: "Custom request header configuration rules.",
140+
Elem: &schema.Resource{
141+
Schema: map[string]*schema.Schema{
142+
"header_mode": {
143+
Type: schema.TypeString,
144+
Computed: true,
145+
Description: "Http header setting method.",
146+
},
147+
"header_name": {
148+
Type: schema.TypeString,
149+
Computed: true,
150+
Description: "Http header name.",
151+
},
152+
"header_value": {
153+
Type: schema.TypeString,
154+
Computed: true,
155+
Description: "Http header value.",
156+
},
157+
"rule_type": {
158+
Type: schema.TypeString,
159+
Computed: true,
160+
Description: "Rule type.",
161+
},
162+
"rule_paths": {
163+
Type: schema.TypeList,
164+
Computed: true,
165+
Elem: &schema.Schema{Type: schema.TypeString},
166+
Description: "Rule paths.",
167+
},
168+
},
169+
},
170+
},
171+
},
172+
},
173+
},
174+
"rule_cache": {
175+
Type: schema.TypeList,
176+
Computed: true,
177+
Description: "Advanced path cache configuration.",
178+
Elem: &schema.Resource{
179+
Schema: map[string]*schema.Schema{
180+
"rule_paths": {
181+
Type: schema.TypeList,
182+
Computed: true,
183+
Elem: &schema.Schema{
184+
Type: schema.TypeString,
185+
},
186+
Description: "Rule paths.",
187+
},
188+
"rule_type": {
189+
Type: schema.TypeString,
190+
Computed: true,
191+
Description: "Rule type.",
192+
},
193+
"switch": {
194+
Type: schema.TypeString,
195+
Computed: true,
196+
Description: "Cache configuration switch.",
197+
},
198+
"cache_time": {
199+
Type: schema.TypeInt,
200+
Required: true,
201+
Description: "Cache expiration time setting, the unit is second.",
202+
},
203+
"compare_max_age": {
204+
Type: schema.TypeString,
205+
Optional: true,
206+
Description: "Advanced cache expiration configuration.",
207+
},
208+
"ignore_cache_control": {
209+
Type: schema.TypeString,
210+
Optional: true,
211+
Description: "Force caching. After opening, the no-store and no-cache resources returned by the origin site will also be cached in accordance with the CacheRules rules.",
212+
},
213+
"ignore_set_cookie": {
214+
Type: schema.TypeString,
215+
Computed: true,
216+
Description: "Ignore the Set-Cookie header of the origin site.",
217+
},
218+
"no_cache_switch": {
219+
Type: schema.TypeString,
220+
Computed: true,
221+
Description: "Cache configuration switch.",
222+
},
223+
"re_validate": {
224+
Type: schema.TypeString,
225+
Computed: true,
226+
Description: "Always check back to origin.",
227+
},
228+
"follow_origin_switch": {
229+
Type: schema.TypeString,
230+
Computed: true,
231+
Description: "Follow the source station configuration switch.",
232+
},
233+
},
234+
},
235+
},
120236
"origin": {
121237
Type: schema.TypeList,
122238
Computed: true,
@@ -266,6 +382,41 @@ func dataSourceTencentCloudCdnDomainsRead(d *schema.ResourceData, meta interface
266382
fullUrlCache = true
267383
}
268384

385+
requestHeaders := make([]map[string]interface{}, 0, 1)
386+
requestHeader := make(map[string]interface{})
387+
requestHeader["switch"] = detailDomain.RequestHeader.Switch
388+
if len(detailDomain.RequestHeader.HeaderRules) > 0 {
389+
headerRules := make([]map[string]interface{}, len(detailDomain.RequestHeader.HeaderRules))
390+
headerRuleList := detailDomain.RequestHeader.HeaderRules
391+
for index, value := range headerRuleList {
392+
headerRule := make(map[string]interface{})
393+
headerRule["header_mode"] = value.HeaderMode
394+
headerRule["header_name"] = value.HeaderName
395+
headerRule["header_value"] = value.HeaderValue
396+
headerRule["rule_type"] = value.RuleType
397+
headerRule["rule_paths"] = value.RulePaths
398+
headerRules[index] = headerRule
399+
}
400+
requestHeader["header_rules"] = headerRules
401+
}
402+
requestHeaders = append(requestHeaders, requestHeader)
403+
404+
ruleCaches := make([]map[string]interface{}, len(detailDomain.Cache.RuleCache))
405+
for index, value := range detailDomain.Cache.RuleCache {
406+
ruleCache := make(map[string]interface{})
407+
ruleCache["rule_paths"] = value.RulePaths
408+
ruleCache["rule_type"] = value.RuleType
409+
ruleCache["switch"] = value.CacheConfig.Cache.Switch
410+
ruleCache["cache_time"] = value.CacheConfig.Cache.CacheTime
411+
ruleCache["compare_max_age"] = value.CacheConfig.Cache.CompareMaxAge
412+
ruleCache["ignore_cache_control"] = value.CacheConfig.Cache.IgnoreCacheControl
413+
ruleCache["ignore_set_cookie"] = value.CacheConfig.Cache.IgnoreSetCookie
414+
ruleCache["no_cache_switch"] = value.CacheConfig.NoCache.Switch
415+
ruleCache["re_validate"] = value.CacheConfig.NoCache.Revalidate
416+
ruleCache["follow_origin_switch"] = value.CacheConfig.FollowOrigin.Switch
417+
ruleCaches[index] = ruleCache
418+
}
419+
269420
origins := make([]map[string]interface{}, 0, 1)
270421
origin := make(map[string]interface{}, 8)
271422
origin["origin_type"] = detailDomain.Origin.OriginType
@@ -295,19 +446,22 @@ func dataSourceTencentCloudCdnDomainsRead(d *schema.ResourceData, meta interface
295446
}
296447

297448
mapping := map[string]interface{}{
298-
"id": detailDomain.ResourceId,
299-
"domain": detailDomain.Domain,
300-
"cname": detailDomain.Cname,
301-
"status": detailDomain.Status,
302-
"create_time": detailDomain.CreateTime,
303-
"update_time": detailDomain.UpdateTime,
304-
"service_type": detailDomain.ServiceType,
305-
"area": detailDomain.Area,
306-
"project_id": detailDomain.ProjectId,
307-
"full_url_cache": fullUrlCache,
308-
"origin": origins,
309-
"https_config": httpsconfigs,
310-
"tags": tags,
449+
"id": detailDomain.ResourceId,
450+
"domain": detailDomain.Domain,
451+
"cname": detailDomain.Cname,
452+
"status": detailDomain.Status,
453+
"create_time": detailDomain.CreateTime,
454+
"update_time": detailDomain.UpdateTime,
455+
"service_type": detailDomain.ServiceType,
456+
"area": detailDomain.Area,
457+
"project_id": detailDomain.ProjectId,
458+
"full_url_cache": fullUrlCache,
459+
"range_origin_switch": detailDomain.RangeOriginPull.Switch,
460+
"request_header": requestHeaders,
461+
"rule_cache": ruleCaches,
462+
"origin": origins,
463+
"https_config": httpsconfigs,
464+
"tags": tags,
311465
}
312466

313467
cdnDomainList = append(cdnDomainList, mapping)

tencentcloud/data_source_tc_cdn_domains_test.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
77
)
88

9-
func TestAccTencentCloudCdnDomains(t *testing.T) {
9+
func TestAccTencentCloudCdnDomainDataSources(t *testing.T) {
1010
resource.Test(t, resource.TestCase{
1111
PreCheck: func() { testAccPreCheck(t) },
1212
Providers: testAccProviders,
@@ -26,12 +26,25 @@ func TestAccTencentCloudCdnDomains(t *testing.T) {
2626
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.https_switch", "on"),
2727
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.http2_switch", "on"),
2828
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.ocsp_stapling_switch", "on"),
29-
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.spdy_switch", "on"),
29+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.spdy_switch", "off"),
3030
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.verify_client", "off"),
3131
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.message", "test"),
3232
resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.deploy_time"),
3333
resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.expire_time"),
3434
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "tags.test", "world"),
35+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "range_origin_switch", "off"),
36+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.cache_time", "10000"),
37+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.rule_paths.#", "1"),
38+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.rule_type", "default"),
39+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.switch", "off"),
40+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.compare_max_age", "off"),
41+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.ignore_cache_control", "off"),
42+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.ignore_set_cookie", "off"),
43+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.no_cache_switch", "on"),
44+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.re_validate", "on"),
45+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.follow_origin_switch", "off"),
46+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "request_header.0.switch", "on"),
47+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "request_header.0.header_rules.#", "1"),
3548
),
3649
},
3750
},
@@ -44,6 +57,25 @@ resource "tencentcloud_cdn_domain" "foo" {
4457
service_type = "web"
4558
area = "mainland"
4659
full_url_cache = false
60+
range_origin_switch = "off"
61+
62+
rule_cache{
63+
cache_time = 10000
64+
no_cache_switch="on"
65+
re_validate="on"
66+
}
67+
68+
request_header{
69+
switch = "on"
70+
71+
header_rules {
72+
header_mode = "add"
73+
header_name = "tf-header-name"
74+
header_value = "tf-header-value"
75+
rule_type = "all"
76+
rule_paths = ["*"]
77+
}
78+
}
4779
4880
origin {
4981
origin_type = "ip"
@@ -56,7 +88,7 @@ resource "tencentcloud_cdn_domain" "foo" {
5688
https_switch = "on"
5789
http2_switch = "on"
5890
ocsp_stapling_switch = "on"
59-
spdy_switch = "on"
91+
spdy_switch = "off"
6092
verify_client = "off"
6193
6294
server_certificate_config {

tencentcloud/extension_cdn.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@ const (
3030
CDN_RESOURCE_NAME_DOMAIN = "domain"
3131

3232
CDN_HOST_NOT_FOUND = "ResourceNotFound.CdnHostNotExists"
33+
CDN_HOST_EXISTS = "ResourceInUse.CdnHostExists"
3334
CDN_DOMAIN_CONFIG_ERROE = "FailedOperation.CdnConfigError"
35+
36+
CDN_RULE_TYPE_ALL = "all"
37+
CDN_RULE_TYPE_FILE = "file"
38+
CDN_RULE_TYPE_DIRECTORY = "directory"
39+
CDN_RULE_TYPE_PATH = "path"
40+
CDN_RULE_TYPE_INDEX = "index"
41+
CDN_RULE_TYPE_DEFAULT = "default"
42+
43+
CDN_RULE_PATH = "no max-age"
3444
)
3545

3646
var CDN_SERVICE_TYPE = []string{
@@ -79,3 +89,19 @@ var CDN_HTTPS_SWITCH = []string{
7989
CDN_DOMAIN_STATUS_OFFLINE,
8090
CDN_DOMAIN_STATUS_PROCESSING,
8191
}
92+
93+
var CDN_RULE_TYPE = []string{
94+
CDN_RULE_TYPE_ALL,
95+
CDN_RULE_TYPE_FILE,
96+
CDN_RULE_TYPE_DIRECTORY,
97+
CDN_RULE_TYPE_PATH,
98+
CDN_RULE_TYPE_INDEX,
99+
CDN_RULE_TYPE_DEFAULT,
100+
}
101+
102+
var CDN_HEADER_RULE = []string{
103+
CDN_RULE_TYPE_ALL,
104+
CDN_RULE_TYPE_FILE,
105+
CDN_RULE_TYPE_DIRECTORY,
106+
CDN_RULE_TYPE_PATH,
107+
}

0 commit comments

Comments
 (0)