From 4ce36fc5587dbbebd2b0fc1141dc5a0b00ed05ae Mon Sep 17 00:00:00 2001 From: hhermanwang Date: Thu, 14 Jan 2021 11:28:36 +0800 Subject: [PATCH 1/3] modify cdn support cache and request header and range origin configuration --- CHANGELOG.md | 5 + examples/tencentcloud-cdn/main.tf | 16 + tencentcloud/data_source_tc_cdn_domains.go | 180 +++++++- .../data_source_tc_cdn_domains_test.go | 36 +- tencentcloud/extension_cdn.go | 26 ++ tencentcloud/resource_tc_cdn_domain.go | 417 +++++++++++++++++- tencentcloud/resource_tc_cdn_domain_test.go | 70 ++- website/docs/d/cdn_domains.html.markdown | 17 + website/docs/r/cdn_domain.html.markdown | 82 +++- 9 files changed, 819 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93f68167ca..3b10a52338 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ DEPRECATED: * Resource: `tencentcloud_kubernetes_as_scaling_group` replaced by `tencentcloud_kubernetes_node_pool`. +ENHANCEMENTS: + +* Resource `tencentcloud_cdn_domain` add `range_origin_switch` to support range back to source configuration. +* Resource `tencentcloud_cdn_domain` add `rule_cache` to support advanced path cache configuration. +* Resource `tencentcloud_cdn_domain` add `request_header` to support request header configuration. ## 1.51.1 (December 22, 2020) diff --git a/examples/tencentcloud-cdn/main.tf b/examples/tencentcloud-cdn/main.tf index 054dd03d60..2df48e1568 100644 --- a/examples/tencentcloud-cdn/main.tf +++ b/examples/tencentcloud-cdn/main.tf @@ -2,6 +2,22 @@ resource "tencentcloud_cdn_domain" "foo" { domain = "xxxx.com" service_type = "web" area = "mainland" + range_origin_switch = "off" + rule_cache{ + cache_time = 10000 + no_cache_switch="on" + re_validate="on" + } + request_header{ + switch = "on" + header_rules { + header_mode = "add" + header_name = "tf-header-name" + header_value = "tf-header-value" + rule_type = "all" + rule_paths = ["*"] + } + } origin { origin_type = "ip" diff --git a/tencentcloud/data_source_tc_cdn_domains.go b/tencentcloud/data_source_tc_cdn_domains.go index 36817c9d1b..871a28e1f4 100644 --- a/tencentcloud/data_source_tc_cdn_domains.go +++ b/tencentcloud/data_source_tc_cdn_domains.go @@ -117,6 +117,122 @@ func dataSourceTencentCloudCdnDomains() *schema.Resource { Computed: true, Description: "Whether to enable full-path cache.", }, + "range_origin_switch": { + Type: schema.TypeString, + Computed: true, + Description: "Sharding back to source configuration switch.", + }, + "request_header": { + Type: schema.TypeList, + Computed: true, + Description: "Request header configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Computed: true, + Description: "Custom request header configuration switch.", + }, + "header_rules": { + Type: schema.TypeList, + Computed: true, + Description: "Custom request header configuration rules.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "header_mode": { + Type: schema.TypeString, + Computed: true, + Description: "Http header setting method.", + }, + "header_name": { + Type: schema.TypeString, + Computed: true, + Description: "Http header name.", + }, + "header_value": { + Type: schema.TypeString, + Computed: true, + Description: "Http header value.", + }, + "rule_type": { + Type: schema.TypeString, + Computed: true, + Description: "Rule type.", + }, + "rule_paths": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "Rule paths.", + }, + }, + }, + }, + }, + }, + }, + "rule_cache": { + Type: schema.TypeList, + Computed: true, + Description: "Advanced path cache configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rule_paths": { + Type: schema.TypeList, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "Rule paths.", + }, + "rule_type": { + Type: schema.TypeString, + Computed: true, + Description: "Rule type.", + }, + "switch": { + Type: schema.TypeString, + Computed: true, + Description: "Cache configuration switch.", + }, + "cache_time": { + Type: schema.TypeInt, + Required: true, + Description: "Cache expiration time setting, the unit is second.", + }, + "compare_max_age": { + Type: schema.TypeString, + Optional: true, + Description: "Advanced cache expiration configuration.", + }, + "ignore_cache_control": { + Type: schema.TypeString, + Optional: true, + 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.", + }, + "ignore_set_cookie": { + Type: schema.TypeString, + Computed: true, + Description: "Ignore the Set-Cookie header of the origin site.", + }, + "no_cache_switch": { + Type: schema.TypeString, + Computed: true, + Description: "Cache configuration switch.", + }, + "re_validate": { + Type: schema.TypeString, + Computed: true, + Description: "Always check back to origin.", + }, + "follow_origin_switch": { + Type: schema.TypeString, + Computed: true, + Description: "Follow the source station configuration switch.", + }, + }, + }, + }, "origin": { Type: schema.TypeList, Computed: true, @@ -266,6 +382,41 @@ func dataSourceTencentCloudCdnDomainsRead(d *schema.ResourceData, meta interface fullUrlCache = true } + requestHeaders := make([]map[string]interface{}, 0, 1) + requestHeader := make(map[string]interface{}) + requestHeader["switch"] = detailDomain.RequestHeader.Switch + if len(detailDomain.RequestHeader.HeaderRules) > 0 { + headerRules := make([]map[string]interface{}, len(detailDomain.RequestHeader.HeaderRules)) + headerRuleList := detailDomain.RequestHeader.HeaderRules + for index, value := range headerRuleList { + headerRule := make(map[string]interface{}) + headerRule["header_mode"] = value.HeaderMode + headerRule["header_name"] = value.HeaderName + headerRule["header_value"] = value.HeaderValue + headerRule["rule_type"] = value.RuleType + headerRule["rule_paths"] = value.RulePaths + headerRules[index] = headerRule + } + requestHeader["header_rules"] = headerRules + } + requestHeaders = append(requestHeaders, requestHeader) + + ruleCaches := make([]map[string]interface{}, len(detailDomain.Cache.RuleCache)) + for index, value := range detailDomain.Cache.RuleCache { + ruleCache := make(map[string]interface{}) + ruleCache["rule_paths"] = value.RulePaths + ruleCache["rule_type"] = value.RuleType + ruleCache["switch"] = value.CacheConfig.Cache.Switch + ruleCache["cache_time"] = value.CacheConfig.Cache.CacheTime + ruleCache["compare_max_age"] = value.CacheConfig.Cache.CompareMaxAge + ruleCache["ignore_cache_control"] = value.CacheConfig.Cache.IgnoreCacheControl + ruleCache["ignore_set_cookie"] = value.CacheConfig.Cache.IgnoreSetCookie + ruleCache["no_cache_switch"] = value.CacheConfig.NoCache.Switch + ruleCache["re_validate"] = value.CacheConfig.NoCache.Revalidate + ruleCache["follow_origin_switch"] = value.CacheConfig.FollowOrigin.Switch + ruleCaches[index] = ruleCache + } + origins := make([]map[string]interface{}, 0, 1) origin := make(map[string]interface{}, 8) origin["origin_type"] = detailDomain.Origin.OriginType @@ -295,19 +446,22 @@ func dataSourceTencentCloudCdnDomainsRead(d *schema.ResourceData, meta interface } mapping := map[string]interface{}{ - "id": detailDomain.ResourceId, - "domain": detailDomain.Domain, - "cname": detailDomain.Cname, - "status": detailDomain.Status, - "create_time": detailDomain.CreateTime, - "update_time": detailDomain.UpdateTime, - "service_type": detailDomain.ServiceType, - "area": detailDomain.Area, - "project_id": detailDomain.ProjectId, - "full_url_cache": fullUrlCache, - "origin": origins, - "https_config": httpsconfigs, - "tags": tags, + "id": detailDomain.ResourceId, + "domain": detailDomain.Domain, + "cname": detailDomain.Cname, + "status": detailDomain.Status, + "create_time": detailDomain.CreateTime, + "update_time": detailDomain.UpdateTime, + "service_type": detailDomain.ServiceType, + "area": detailDomain.Area, + "project_id": detailDomain.ProjectId, + "full_url_cache": fullUrlCache, + "range_origin_switch": detailDomain.RangeOriginPull.Switch, + "request_header": requestHeaders, + "rule_cache": ruleCaches, + "origin": origins, + "https_config": httpsconfigs, + "tags": tags, } cdnDomainList = append(cdnDomainList, mapping) diff --git a/tencentcloud/data_source_tc_cdn_domains_test.go b/tencentcloud/data_source_tc_cdn_domains_test.go index e3c06d2565..3c5e81df23 100644 --- a/tencentcloud/data_source_tc_cdn_domains_test.go +++ b/tencentcloud/data_source_tc_cdn_domains_test.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/helper/resource" ) -func TestAccTencentCloudCdnDomains(t *testing.T) { +func TestAccTencentCloudCdnDomainDataSources(t *testing.T) { resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, Providers: testAccProviders, @@ -26,12 +26,25 @@ func TestAccTencentCloudCdnDomains(t *testing.T) { resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.https_switch", "on"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.http2_switch", "on"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.ocsp_stapling_switch", "on"), - resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.spdy_switch", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.spdy_switch", "off"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.verify_client", "off"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.message", "test"), resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.deploy_time"), resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.expire_time"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "tags.test", "world"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "range_origin_switch", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.cache_time", "10000"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.rule_paths.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.rule_type", "default"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.switch", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.compare_max_age", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.ignore_cache_control", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.ignore_set_cookie", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.no_cache_switch", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.re_validate", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.follow_origin_switch", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "request_header.0.switch", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "request_header.0.header_rules.#", "1"), ), }, }, @@ -44,7 +57,22 @@ resource "tencentcloud_cdn_domain" "foo" { service_type = "web" area = "mainland" full_url_cache = false - + range_origin_switch = "off" + rule_cache{ + cache_time = 10000 + no_cache_switch="on" + re_validate="on" + } + request_header{ + switch = "on" + header_rules { + header_mode = "add" + header_name = "tf-header-name" + header_value = "tf-header-value" + rule_type = "all" + rule_paths = ["*"] + } + } origin { origin_type = "ip" origin_list = ["172.199.199.140"] @@ -56,7 +84,7 @@ resource "tencentcloud_cdn_domain" "foo" { https_switch = "on" http2_switch = "on" ocsp_stapling_switch = "on" - spdy_switch = "on" + spdy_switch = "off" verify_client = "off" server_certificate_config { diff --git a/tencentcloud/extension_cdn.go b/tencentcloud/extension_cdn.go index 51e67fcd4b..3ec431b2c7 100644 --- a/tencentcloud/extension_cdn.go +++ b/tencentcloud/extension_cdn.go @@ -30,7 +30,17 @@ const ( CDN_RESOURCE_NAME_DOMAIN = "domain" CDN_HOST_NOT_FOUND = "ResourceNotFound.CdnHostNotExists" + CDN_HOST_EXISTS = "ResourceInUse.CdnHostExists" CDN_DOMAIN_CONFIG_ERROE = "FailedOperation.CdnConfigError" + + CDN_RULE_TYPE_ALL = "all" + CDN_RULE_TYPE_FILE = "file" + CDN_RULE_TYPE_DIRECTORY = "directory" + CDN_RULE_TYPE_PATH = "path" + CDN_RULE_TYPE_INDEX = "index" + CDN_RULE_TYPE_DEFAULT = "default" + + CDN_RULE_PATH = "no max-age" ) var CDN_SERVICE_TYPE = []string{ @@ -79,3 +89,19 @@ var CDN_HTTPS_SWITCH = []string{ CDN_DOMAIN_STATUS_OFFLINE, CDN_DOMAIN_STATUS_PROCESSING, } + +var CDN_RULE_TYPE = []string{ + CDN_RULE_TYPE_ALL, + CDN_RULE_TYPE_FILE, + CDN_RULE_TYPE_DIRECTORY, + CDN_RULE_TYPE_PATH, + CDN_RULE_TYPE_INDEX, + CDN_RULE_TYPE_DEFAULT, +} + +var CDN_HEADER_RULE = []string{ + CDN_RULE_TYPE_ALL, + CDN_RULE_TYPE_FILE, + CDN_RULE_TYPE_DIRECTORY, + CDN_RULE_TYPE_PATH, +} diff --git a/tencentcloud/resource_tc_cdn_domain.go b/tencentcloud/resource_tc_cdn_domain.go index d60ac03d74..1c100ffc7b 100644 --- a/tencentcloud/resource_tc_cdn_domain.go +++ b/tencentcloud/resource_tc_cdn_domain.go @@ -36,6 +36,57 @@ resource "tencentcloud_cdn_domain" "foo" { } ``` +Example Usage of cdn uses cache and request headers + +```hcl +resource "tencentcloud_cdn_domain" "foo" { + domain = "xxxx.com" + service_type = "web" + area = "mainland" + full_url_cache = false + range_origin_switch = "off" + rule_cache{ + cache_time = 10000 + no_cache_switch="on" + re_validate="on" + } + request_header{ + switch = "on" + header_rules { + header_mode = "add" + header_name = "tf-header-name" + header_value = "tf-header-value" + rule_type = "all" + rule_paths = ["*"] + } + } + + origin { + origin_type = "ip" + origin_list = ["127.0.0.1"] + origin_pull_protocol = "follow" + } + + https_config { + https_switch = "off" + http2_switch = "off" + ocsp_stapling_switch = "off" + spdy_switch = "off" + verify_client = "off" + + force_redirect { + switch = "on" + redirect_type = "http" + redirect_status_code = 302 + } + } + + tags = { + hello = "world" + } +} +``` + Example Usage of COS bucket url as origin ```hcl @@ -83,7 +134,6 @@ package tencentcloud import ( "context" "fmt" - "log" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/resource" @@ -158,6 +208,7 @@ func resourceTencentCloudCdnDomain() *schema.Resource { "server_name": { Type: schema.TypeString, Optional: true, + Computed: true, Description: "Host header used when accessing the master origin server. If left empty, the acceleration domain name will be used by default.", }, "cos_private_access": { @@ -226,7 +277,7 @@ func resourceTencentCloudCdnDomain() *schema.Resource { Optional: true, Default: CDN_SWITCH_OFF, ValidateFunc: validateAllowedStringValue(CDN_SWITCH), - Description: "Spdy configuration switch. Valid values are `on` and `off`. and default value is `off`.", + Description: "Spdy configuration switch. Valid values are `on` and `off`. and default value is `off`. The current version does not support `on`.", }, "verify_client": { Type: schema.TypeString, @@ -347,6 +398,154 @@ func resourceTencentCloudCdnDomain() *schema.Resource { }, }, }, + "range_origin_switch": { + Type: schema.TypeString, + Optional: true, + Default: CDN_SWITCH_ON, + ValidateFunc: validateAllowedStringValue(CDN_SWITCH), + Description: "Sharding back to source configuration switch. Valid values are `on` and `off`. Default value is `on`.", + }, + "rule_cache": { + Type: schema.TypeList, + Optional: true, + Description: "Advanced path cache configuration.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "rule_paths": { + Type: schema.TypeList, + Optional: true, + Computed: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + Description: "Matching content under the corresponding type of CacheType: `all`: fill *, `file`: fill in the suffix name, such as jpg, txt, " + + "`directory`: fill in the path, such as /xxx/test, `path`: fill in the absolute path, such as /xxx/test.html, `index`: fill /, `default`: Fill `no max-age`.", + }, + "rule_type": { + Type: schema.TypeString, + Optional: true, + Default: CDN_RULE_TYPE_DEFAULT, + ValidateFunc: validateAllowedStringValue(CDN_RULE_TYPE), + Description: "Rule type. The following types are supported: `all`: all documents take effect, `file`: the specified file suffix takes effect, " + + "`directory`: the specified path takes effect, `path`: specify the absolute path to take effect, `index`: home page, `default`: effective when the source site has no max-age.", + }, + "switch": { + Type: schema.TypeString, + Optional: true, + Default: CDN_SWITCH_OFF, + ValidateFunc: validateAllowedStringValue(CDN_SWITCH), + Description: "Cache configuration switch. Valid values are `on` and `off`.", + }, + "cache_time": { + Type: schema.TypeInt, + Required: true, + Description: "Cache expiration time setting, the unit is second, the maximum can be set to 365 days.", + }, + "compare_max_age": { + Type: schema.TypeString, + Optional: true, + Default: CDN_SWITCH_OFF, + ValidateFunc: validateAllowedStringValue(CDN_SWITCH), + Description: "Advanced cache expiration configuration. When it is turned on, it will compare the max-age value returned by the origin site with the cache expiration time set in CacheRules, " + + "and take the minimum value to cache at the node. Valid values are `on` and `off`. Default value is `off`.", + }, + "ignore_cache_control": { + Type: schema.TypeString, + Optional: true, + Default: CDN_SWITCH_OFF, + ValidateFunc: validateAllowedStringValue(CDN_SWITCH), + 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. Valid values are `on` and `off`. Default value is `off`.", + }, + "ignore_set_cookie": { + Type: schema.TypeString, + Optional: true, + Default: CDN_SWITCH_OFF, + ValidateFunc: validateAllowedStringValue(CDN_SWITCH), + Description: "Ignore the Set-Cookie header of the origin site. Valid values are `on` and `off`. Default value is `off`. The current version does not support `on`.", + }, + "no_cache_switch": { + Type: schema.TypeString, + Optional: true, + Default: CDN_SWITCH_OFF, + ValidateFunc: validateAllowedStringValue(CDN_SWITCH), + Description: "Cache configuration switch. Valid values are `on` and `off`.", + }, + "re_validate": { + Type: schema.TypeString, + Optional: true, + Default: CDN_SWITCH_OFF, + ValidateFunc: validateAllowedStringValue(CDN_SWITCH), + Description: "Always check back to origin. Valid values are `on` and `off`. Default value is `off`.", + }, + "follow_origin_switch": { + Type: schema.TypeString, + Optional: true, + Default: CDN_SWITCH_OFF, + ValidateFunc: validateAllowedStringValue(CDN_SWITCH), + Description: "Follow the source station configuration switch. Valid values are `on` and `off`.", + }, + }, + }, + }, + "request_header": { + Type: schema.TypeList, + Optional: true, + Computed: true, + MaxItems: 1, + Description: "Request header configuration. It's a list and consist of at most one item.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "switch": { + Type: schema.TypeString, + Optional: true, + Default: CDN_SWITCH_OFF, + ValidateFunc: validateAllowedStringValue(CDN_SWITCH), + Description: "Custom request header configuration switch. Valid values are `on` and `off`. and default value is `off`.", + }, + "header_rules": { + Type: schema.TypeList, + Optional: true, + Description: "Custom request header configuration rules.", + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "header_mode": { + Type: schema.TypeString, + Required: true, + Description: "Http header setting method. The following types are supported: `add`: add a head, if a head already exists, there will be a duplicate head, `del`: delete the head.", + }, + "header_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validateStringLengthInRange(1, 100), + Description: "Http header name.", + }, + "header_value": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validateStringLengthInRange(1, 1000), + Description: "Http header value, optional when Mode is `del`, Required when Mode is `add`/`set`.", + }, + "rule_type": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validateAllowedStringValue(CDN_HEADER_RULE), + Description: "Rule type. The following types are supported: `all`: all documents take effect, `file`: the specified file suffix takes effect, " + + "`directory`: the specified path takes effect, `path`: specify the absolute path to take effect.", + }, + "rule_paths": { + Type: schema.TypeList, + Required: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Description: "Matching content under the corresponding type of CacheType: `all`: fill *, `file`: fill in the suffix name, such as jpg, txt, " + + "`directory`: fill in the path, such as /xxx/test, `path`: fill in the absolute path, such as /xxx/test.html.", + }, + }, + }, + }, + }, + }, + }, "tags": { Type: schema.TypeMap, Optional: true, @@ -396,6 +595,87 @@ func resourceTencentCloudCdnDomainCreate(d *schema.ResourceData, meta interface{ } else { request.CacheKey.FullUrlCache = helper.String(CDN_SWITCH_OFF) } + // Range Origin Pull + request.RangeOriginPull = &cdn.RangeOriginPull{} + request.RangeOriginPull.Switch = helper.String(d.Get("range_origin_switch").(string)) + + // rule_cache + if v, ok := d.GetOk("rule_cache"); ok { + ruleCache := v.([]interface{}) + var ruleCaches []*cdn.RuleCache + for _, v := range ruleCache { + re := &cdn.RuleCache{} + ruleCacheMap := v.(map[string]interface{}) + rulePaths := ruleCacheMap["rule_paths"].([]interface{}) + rulePathList := make([]*string, 0, len(rulePaths)) + ruleType := ruleCacheMap["rule_type"].(string) + if ruleType == CDN_RULE_TYPE_DEFAULT { + rulePathList = append(rulePathList, helper.String(CDN_RULE_PATH)) + } else { + for _, value := range rulePaths { + rulePathList = append(rulePathList, helper.String(value.(string))) + } + } + switchFlag := ruleCacheMap["switch"].(string) + cacheTime := ruleCacheMap["cache_time"].(int) + compareMaxAge := ruleCacheMap["compare_max_age"].(string) + ignoreCacheControl := ruleCacheMap["ignore_cache_control"].(string) + ignoreSetCookie := ruleCacheMap["ignore_set_cookie"].(string) + noCacheSwitch := ruleCacheMap["no_cache_switch"].(string) + reValidate := ruleCacheMap["re_validate"].(string) + followOriginSwitch := ruleCacheMap["follow_origin_switch"].(string) + ruleCacheConfig := &cdn.RuleCacheConfig{} + cache := &cdn.CacheConfigCache{} + noCache := &cdn.CacheConfigNoCache{} + followOrigin := &cdn.CacheConfigFollowOrigin{} + ruleCacheConfig.Cache = cache + ruleCacheConfig.NoCache = noCache + ruleCacheConfig.FollowOrigin = followOrigin + re.CacheConfig = ruleCacheConfig + re.RulePaths = rulePathList + re.RuleType = &ruleType + re.CacheConfig.Cache.Switch = &switchFlag + re.CacheConfig.Cache.CacheTime = helper.IntInt64(cacheTime) + re.CacheConfig.Cache.CompareMaxAge = &compareMaxAge + re.CacheConfig.Cache.IgnoreCacheControl = &ignoreCacheControl + re.CacheConfig.Cache.IgnoreSetCookie = &ignoreSetCookie + re.CacheConfig.NoCache.Switch = &noCacheSwitch + re.CacheConfig.NoCache.Revalidate = &reValidate + re.CacheConfig.FollowOrigin.Switch = &followOriginSwitch + ruleCaches = append(ruleCaches, re) + } + request.Cache = &cdn.Cache{} + request.Cache.RuleCache = ruleCaches + } + + if v, ok := d.GetOk("request_header"); ok { + requestHeaders := v.([]interface{}) + requestHeader := requestHeaders[0].(map[string]interface{}) + headerRule := requestHeader["header_rules"].([]interface{}) + var headerRules []*cdn.HttpHeaderPathRule + for _, value := range headerRule { + hr := &cdn.HttpHeaderPathRule{} + headerRuleMap := value.(map[string]interface{}) + headerMode := headerRuleMap["header_mode"].(string) + headerName := headerRuleMap["header_name"].(string) + headerValue := headerRuleMap["header_value"].(string) + ruleType := headerRuleMap["rule_type"].(string) + rulePaths := headerRuleMap["rule_paths"].([]interface{}) + rulePathList := make([]*string, 0, len(rulePaths)) + for _, value := range rulePaths { + rulePathList = append(rulePathList, helper.String(value.(string))) + } + hr.HeaderMode = &headerMode + hr.HeaderName = &headerName + hr.HeaderValue = &headerValue + hr.RuleType = &ruleType + hr.RulePaths = rulePathList + headerRules = append(headerRules, hr) + } + request.RequestHeader = &cdn.RequestHeader{} + request.RequestHeader.Switch = helper.String(requestHeader["switch"].(string)) + request.RequestHeader.HeaderRules = headerRules + } // origin origins := d.Get("origin").([]interface{}) @@ -500,7 +780,7 @@ func resourceTencentCloudCdnDomainCreate(d *schema.ResourceData, meta interface{ _, err := meta.(*TencentCloudClient).apiV3Conn.UseCdnClient().AddCdnDomain(request) if err != nil { if sdkErr, ok := err.(*sdkErrors.TencentCloudSDKError); ok { - if sdkErr.Code == CDN_DOMAIN_CONFIG_ERROE { + if sdkErr.Code == CDN_DOMAIN_CONFIG_ERROE || sdkErr.Code == CDN_HOST_EXISTS { return resource.NonRetryableError(err) } } @@ -579,6 +859,7 @@ func resourceTencentCloudCdnDomainRead(d *schema.ResourceData, meta interface{}) _ = d.Set("status", domainConfig.Status) _ = d.Set("create_time", domainConfig.CreateTime) _ = d.Set("cname", domainConfig.Cname) + _ = d.Set("range_origin_switch", domainConfig.RangeOriginPull.Switch) if *domainConfig.CacheKey.FullUrlCache == CDN_SWITCH_OFF { _ = d.Set("full_url_cache", false) } else { @@ -598,6 +879,47 @@ func resourceTencentCloudCdnDomainRead(d *schema.ResourceData, meta interface{}) origins = append(origins, origin) _ = d.Set("origin", origins) + if len(domainConfig.Cache.RuleCache) > 0 { + ruleCaches := make([]map[string]interface{}, len(domainConfig.Cache.RuleCache)) + for index, value := range domainConfig.Cache.RuleCache { + ruleCache := make(map[string]interface{}) + ruleCache["rule_paths"] = value.RulePaths + ruleCache["rule_type"] = value.RuleType + ruleCache["switch"] = value.CacheConfig.Cache.Switch + ruleCache["cache_time"] = value.CacheConfig.Cache.CacheTime + ruleCache["compare_max_age"] = value.CacheConfig.Cache.CompareMaxAge + ruleCache["ignore_cache_control"] = value.CacheConfig.Cache.IgnoreCacheControl + ruleCache["ignore_set_cookie"] = value.CacheConfig.Cache.IgnoreSetCookie + ruleCache["no_cache_switch"] = value.CacheConfig.NoCache.Switch + ruleCache["re_validate"] = value.CacheConfig.NoCache.Revalidate + ruleCache["follow_origin_switch"] = value.CacheConfig.FollowOrigin.Switch + ruleCaches[index] = ruleCache + } + _ = d.Set("rule_cache", ruleCaches) + } + + requestHeaders := make([]map[string]interface{}, 1) + requestHeader := make(map[string]interface{}) + if domainConfig.RequestHeader != nil { + requestHeader["switch"] = domainConfig.RequestHeader.Switch + if len(domainConfig.RequestHeader.HeaderRules) > 0 { + headerRules := make([]map[string]interface{}, len(domainConfig.RequestHeader.HeaderRules)) + headerRuleList := domainConfig.RequestHeader.HeaderRules + for index, value := range headerRuleList { + headerRule := make(map[string]interface{}) + headerRule["header_mode"] = value.HeaderMode + headerRule["header_name"] = value.HeaderName + headerRule["header_value"] = value.HeaderValue + headerRule["rule_type"] = value.RuleType + headerRule["rule_paths"] = value.RulePaths + headerRules[index] = headerRule + } + requestHeader["header_rules"] = headerRules + } + requestHeaders[0] = requestHeader + _ = d.Set("request_header", requestHeaders) + } + httpsConfigs := make([]map[string]interface{}, 0, 1) httpsConfig := make(map[string]interface{}, 8) httpsConfig["https_switch"] = domainConfig.Https.Switch @@ -711,6 +1033,11 @@ func resourceTencentCloudCdnDomainUpdate(d *schema.ResourceData, meta interface{ } updateAttrs = append(updateAttrs, "full_url_cache") } + if d.HasChange("range_origin_switch") { + request.RangeOriginPull = &cdn.RangeOriginPull{} + request.RangeOriginPull.Switch = helper.String(d.Get("range_origin_switch").(string)) + updateAttrs = append(updateAttrs, "range_origin_switch") + } if d.HasChange("origin") { updateAttrs = append(updateAttrs, "origin") origins := d.Get("origin").([]interface{}) @@ -748,6 +1075,83 @@ func resourceTencentCloudCdnDomainUpdate(d *schema.ResourceData, meta interface{ } } } + if d.HasChange("request_header") { + updateAttrs = append(updateAttrs, "request_header") + requestHeaders := d.Get("request_header").([]interface{}) + requestHeader := requestHeaders[0].(map[string]interface{}) + headerRule := requestHeader["header_rules"].([]interface{}) + var headerRules []*cdn.HttpHeaderPathRule + for _, value := range headerRule { + hr := &cdn.HttpHeaderPathRule{} + headerRuleMap := value.(map[string]interface{}) + headerMode := headerRuleMap["header_mode"].(string) + headerName := headerRuleMap["header_name"].(string) + headerValue := headerRuleMap["header_value"].(string) + ruleType := headerRuleMap["rule_type"].(string) + rulePaths := headerRuleMap["rule_paths"].([]interface{}) + rulePathList := make([]*string, 0, len(rulePaths)) + for _, value := range rulePaths { + rulePathList = append(rulePathList, helper.String(value.(string))) + } + hr.HeaderMode = &headerMode + hr.HeaderName = &headerName + hr.HeaderValue = &headerValue + hr.RuleType = &ruleType + hr.RulePaths = rulePathList + headerRules = append(headerRules, hr) + } + request.RequestHeader = &cdn.RequestHeader{} + request.RequestHeader.Switch = helper.String(requestHeader["switch"].(string)) + request.RequestHeader.HeaderRules = headerRules + } + if d.HasChange("rule_cache") { + updateAttrs = append(updateAttrs, "rule_cache") + ruleCache := d.Get("rule_cache").([]interface{}) + var ruleCaches []*cdn.RuleCache + for _, v := range ruleCache { + re := &cdn.RuleCache{} + ruleCacheMap := v.(map[string]interface{}) + rulePaths := ruleCacheMap["rule_paths"].([]interface{}) + rulePathList := make([]*string, 0, len(rulePaths)) + ruleType := ruleCacheMap["rule_type"].(string) + if ruleType == CDN_RULE_TYPE_DEFAULT { + rulePathList = append(rulePathList, helper.String(CDN_RULE_PATH)) + } else { + for _, value := range rulePaths { + rulePathList = append(rulePathList, helper.String(value.(string))) + } + } + switchFlag := ruleCacheMap["switch"].(string) + cacheTime := ruleCacheMap["cache_time"].(int) + compareMaxAge := ruleCacheMap["compare_max_age"].(string) + ignoreCacheControl := ruleCacheMap["ignore_cache_control"].(string) + ignoreSetCookie := ruleCacheMap["ignore_set_cookie"].(string) + noCacheSwitch := ruleCacheMap["no_cache_switch"].(string) + reValidate := ruleCacheMap["re_validate"].(string) + followOriginSwitch := ruleCacheMap["follow_origin_switch"].(string) + ruleCacheConfig := &cdn.RuleCacheConfig{} + cache := &cdn.CacheConfigCache{} + noCache := &cdn.CacheConfigNoCache{} + followOrigin := &cdn.CacheConfigFollowOrigin{} + ruleCacheConfig.Cache = cache + ruleCacheConfig.NoCache = noCache + ruleCacheConfig.FollowOrigin = followOrigin + re.CacheConfig = ruleCacheConfig + re.RulePaths = rulePathList + re.RuleType = &ruleType + re.CacheConfig.Cache.Switch = &switchFlag + re.CacheConfig.Cache.CacheTime = helper.IntInt64(cacheTime) + re.CacheConfig.Cache.CompareMaxAge = &compareMaxAge + re.CacheConfig.Cache.IgnoreCacheControl = &ignoreCacheControl + re.CacheConfig.Cache.IgnoreSetCookie = &ignoreSetCookie + re.CacheConfig.NoCache.Switch = &noCacheSwitch + re.CacheConfig.NoCache.Revalidate = &reValidate + re.CacheConfig.FollowOrigin.Switch = &followOriginSwitch + ruleCaches = append(ruleCaches, re) + } + request.Cache = &cdn.Cache{} + request.Cache.RuleCache = ruleCaches + } if d.HasChange("https_config") { updateAttrs = append(updateAttrs, "https_config") httpsConfigs := d.Get("https_config").([]interface{}) @@ -815,8 +1219,11 @@ func resourceTencentCloudCdnDomainUpdate(d *schema.ResourceData, meta interface{ ratelimit.Check(request.GetAction()) _, err := meta.(*TencentCloudClient).apiV3Conn.UseCdnClient().UpdateDomainConfig(request) if err != nil { - log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", - logId, request.GetAction(), request.ToJsonString(), err.Error()) + if sdkErr, ok := err.(*sdkErrors.TencentCloudSDKError); ok { + if sdkErr.Code == CDN_DOMAIN_CONFIG_ERROE { + return resource.NonRetryableError(err) + } + } return retryError(err) } return nil diff --git a/tencentcloud/resource_tc_cdn_domain_test.go b/tencentcloud/resource_tc_cdn_domain_test.go index a1ae851a76..f890afd9f9 100644 --- a/tencentcloud/resource_tc_cdn_domain_test.go +++ b/tencentcloud/resource_tc_cdn_domain_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/terraform" ) -func TestAccTencentCloudCdnDomain(t *testing.T) { +func TestAccTencentCloudCdnDomainResource(t *testing.T) { t.Parallel() resource.Test(t, resource.TestCase{ @@ -51,6 +51,19 @@ func TestAccTencentCloudCdnDomainWithHTTPs(t *testing.T) { resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "service_type", "web"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "area", "mainland"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "full_url_cache", "false"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "range_origin_switch", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.cache_time", "10000"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.rule_paths.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.rule_type", "default"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.switch", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.compare_max_age", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.ignore_cache_control", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.ignore_set_cookie", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.no_cache_switch", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.re_validate", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.follow_origin_switch", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "request_header.0.switch", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "request_header.0.header_rules.#", "1"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.origin_type", "ip"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.origin_list.#", "1"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.server_name", "test.zhaoshaona.com"), @@ -58,7 +71,7 @@ func TestAccTencentCloudCdnDomainWithHTTPs(t *testing.T) { resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.https_switch", "on"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.http2_switch", "on"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.ocsp_stapling_switch", "on"), - resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.spdy_switch", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.spdy_switch", "off"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.verify_client", "off"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.message", "test"), resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.deploy_time"), @@ -76,6 +89,18 @@ func TestAccTencentCloudCdnDomainWithHTTPs(t *testing.T) { resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "service_type", "web"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "area", "mainland"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "full_url_cache", "false"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "range_origin_switch", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.cache_time", "20000"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.rule_paths.#", "1"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.rule_type", "all"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.switch", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.compare_max_age", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.ignore_cache_control", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.ignore_set_cookie", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.no_cache_switch", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.re_validate", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "rule_cache.0.follow_origin_switch", "off"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "request_header.0.switch", "off"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.origin_type", "ip"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.origin_list.#", "1"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.server_name", "test.zhaoshaona.com"), @@ -83,7 +108,7 @@ func TestAccTencentCloudCdnDomainWithHTTPs(t *testing.T) { resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.https_switch", "on"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.http2_switch", "on"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.ocsp_stapling_switch", "on"), - resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.spdy_switch", "on"), + resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.spdy_switch", "off"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.verify_client", "off"), resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.message", "test"), resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.deploy_time"), @@ -188,7 +213,23 @@ resource "tencentcloud_cdn_domain" "foo" { service_type = "web" area = "mainland" full_url_cache = false - + range_origin_switch = "off" + + rule_cache{ + cache_time = 10000 + no_cache_switch="on" + re_validate="on" + } + request_header{ + switch = "on" + header_rules { + header_mode = "add" + header_name = "tf-header-name" + header_value = "tf-header-value" + rule_type = "all" + rule_paths = ["*"] + } + } origin { origin_type = "ip" origin_list = ["139.199.199.140"] @@ -200,7 +241,7 @@ resource "tencentcloud_cdn_domain" "foo" { https_switch = "on" http2_switch = "on" ocsp_stapling_switch = "on" - spdy_switch = "on" + spdy_switch = "off" verify_client = "off" force_redirect { @@ -280,7 +321,22 @@ resource "tencentcloud_cdn_domain" "foo" { service_type = "web" area = "mainland" full_url_cache = false - + range_origin_switch = "on" + rule_cache { + cache_time = 20000 + rule_paths=["*"] + rule_type="all" + switch="on" + compare_max_age="on" + ignore_cache_control="on" + ignore_set_cookie="off" + no_cache_switch="off" + re_validate="off" + follow_origin_switch="off" + } + request_header{ + switch = "off" + } origin { origin_type = "ip" origin_list = ["139.199.199.140"] @@ -292,7 +348,7 @@ resource "tencentcloud_cdn_domain" "foo" { https_switch = "on" http2_switch = "on" ocsp_stapling_switch = "on" - spdy_switch = "on" + spdy_switch = "off" verify_client = "off" force_redirect { diff --git a/website/docs/d/cdn_domains.html.markdown b/website/docs/d/cdn_domains.html.markdown index 0d2ef8aab1..b98d91068f 100644 --- a/website/docs/d/cdn_domains.html.markdown +++ b/website/docs/d/cdn_domains.html.markdown @@ -61,6 +61,23 @@ In addition to all arguments above, the following attributes are exported: * `origin_type` - Master origin server type. * `server_name` - Host header used when accessing the master origin server. If left empty, the acceleration domain name will be used by default. * `project_id` - The project CDN belongs to. + * `range_origin_switch` - Sharding back to source configuration switch. + * `request_header` - Request header configuration. + * `header_rules` - Custom request header configuration rules. + * `header_mode` - Http header setting method. + * `header_name` - Http header name. + * `header_value` - Http header value. + * `rule_paths` - Rule paths. + * `rule_type` - Rule type. + * `switch` - Custom request header configuration switch. + * `rule_cache` - Advanced path cache configuration. + * `follow_origin_switch` - Follow the source station configuration switch. + * `ignore_set_cookie` - Ignore the Set-Cookie header of the origin site. + * `no_cache_switch` - Cache configuration switch. + * `re_validate` - Always check back to origin. + * `rule_paths` - Rule paths. + * `rule_type` - Rule type. + * `switch` - Cache configuration switch. * `service_type` - Service type of acceleration domain name. * `status` - Acceleration service status. * `tags` - Tags of cdn domain. diff --git a/website/docs/r/cdn_domain.html.markdown b/website/docs/r/cdn_domain.html.markdown index dedbd7d6b6..585074c64e 100644 --- a/website/docs/r/cdn_domain.html.markdown +++ b/website/docs/r/cdn_domain.html.markdown @@ -46,6 +46,57 @@ resource "tencentcloud_cdn_domain" "foo" { } ``` +Example Usage of cdn uses cache and request headers + +```hcl +resource "tencentcloud_cdn_domain" "foo" { + domain = "xxxx.com" + service_type = "web" + area = "mainland" + full_url_cache = false + range_origin_switch = "off" + rule_cache { + cache_time = 10000 + no_cache_switch = "on" + re_validate = "on" + } + request_header { + switch = "on" + header_rules { + header_mode = "add" + header_name = "tf-header-name" + header_value = "tf-header-value" + rule_type = "all" + rule_paths = ["*"] + } + } + + origin { + origin_type = "ip" + origin_list = ["127.0.0.1"] + origin_pull_protocol = "follow" + } + + https_config { + https_switch = "off" + http2_switch = "off" + ocsp_stapling_switch = "off" + spdy_switch = "off" + verify_client = "off" + + force_redirect { + switch = "on" + redirect_type = "http" + redirect_status_code = 302 + } + } + + tags = { + hello = "world" + } +} +``` + Example Usage of COS bucket url as origin ```hcl @@ -91,6 +142,9 @@ The following arguments are supported: * `full_url_cache` - (Optional) Whether to enable full-path cache. Default value is `true`. * `https_config` - (Optional) HTTPS acceleration configuration. It's a list and consist of at most one item. * `project_id` - (Optional) The project CDN belongs to, default to 0. +* `range_origin_switch` - (Optional) Sharding back to source configuration switch. Valid values are `on` and `off`. Default value is `on`. +* `request_header` - (Optional) Request header configuration. It's a list and consist of at most one item. +* `rule_cache` - (Optional) Advanced path cache configuration. * `tags` - (Optional) Tags of cdn domain. The `client_certificate_config` object supports the following: @@ -103,6 +157,14 @@ The `force_redirect` object supports the following: * `redirect_type` - (Optional) Forced redirect type. Valid values are `http` and `https`. `http` means a forced redirect from HTTPS to HTTP, `https` means a forced redirect from HTTP to HTTPS. When `switch` setting `off`, this property does not need to be set or set to `http`. Default value is `http`. * `switch` - (Optional) Forced redirect configuration switch. Valid values are `on` and `off`. Default value is `off`. +The `header_rules` object supports the following: + +* `header_mode` - (Required) Http header setting method. The following types are supported: `add`: add a head, if a head already exists, there will be a duplicate head, `del`: delete the head. +* `header_name` - (Required) Http header name. +* `header_value` - (Required) Http header value, optional when Mode is `del`, Required when Mode is `add`/`set`. +* `rule_paths` - (Required) Matching content under the corresponding type of CacheType: `all`: fill *, `file`: fill in the suffix name, such as jpg, txt, `directory`: fill in the path, such as /xxx/test, `path`: fill in the absolute path, such as /xxx/test.html. +* `rule_type` - (Required) Rule type. The following types are supported: `all`: all documents take effect, `file`: the specified file suffix takes effect, `directory`: the specified path takes effect, `path`: specify the absolute path to take effect. + The `https_config` object supports the following: * `https_switch` - (Required) HTTPS configuration switch. Valid values are `on` and `off`. @@ -111,7 +173,7 @@ The `https_config` object supports the following: * `http2_switch` - (Optional) HTTP2 configuration switch. Valid values are `on` and `off`. and default value is `off`. * `ocsp_stapling_switch` - (Optional) OCSP configuration switch. Valid values are `on` and `off`. and default value is `off`. * `server_certificate_config` - (Optional) Server certificate configuration information. -* `spdy_switch` - (Optional) Spdy configuration switch. Valid values are `on` and `off`. and default value is `off`. +* `spdy_switch` - (Optional) Spdy configuration switch. Valid values are `on` and `off`. and default value is `off`. The current version does not support `on`. * `verify_client` - (Optional) Client certificate authentication feature. Valid values are `on` and `off`. and default value is `off`. The `origin` object supports the following: @@ -125,6 +187,24 @@ The `origin` object supports the following: * `origin_pull_protocol` - (Optional) Origin-pull protocol configuration. `http`: forced HTTP origin-pull, `follow`: protocol follow origin-pull, `https`: forced HTTPS origin-pull. This only supports origin server port 443 for origin-pull. * `server_name` - (Optional) Host header used when accessing the master origin server. If left empty, the acceleration domain name will be used by default. +The `request_header` object supports the following: + +* `header_rules` - (Optional) Custom request header configuration rules. +* `switch` - (Optional) Custom request header configuration switch. Valid values are `on` and `off`. and default value is `off`. + +The `rule_cache` object supports the following: + +* `cache_time` - (Required) Cache expiration time setting, the unit is second, the maximum can be set to 365 days. +* `compare_max_age` - (Optional) Advanced cache expiration configuration. When it is turned on, it will compare the max-age value returned by the origin site with the cache expiration time set in CacheRules, and take the minimum value to cache at the node. Valid values are `on` and `off`. Default value is `off`. +* `follow_origin_switch` - (Optional) Follow the source station configuration switch. Valid values are `on` and `off`. +* `ignore_cache_control` - (Optional) 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. Valid values are `on` and `off`. Default value is `off`. +* `ignore_set_cookie` - (Optional) Ignore the Set-Cookie header of the origin site. Valid values are `on` and `off`. Default value is `off`. The current version does not support `on`. +* `no_cache_switch` - (Optional) Cache configuration switch. Valid values are `on` and `off`. +* `re_validate` - (Optional) Always check back to origin. Valid values are `on` and `off`. Default value is `off`. +* `rule_paths` - (Optional) Matching content under the corresponding type of CacheType: `all`: fill *, `file`: fill in the suffix name, such as jpg, txt, `directory`: fill in the path, such as /xxx/test, `path`: fill in the absolute path, such as /xxx/test.html, `index`: fill /, `default`: Fill `no max-age`. +* `rule_type` - (Optional) Rule type. The following types are supported: `all`: all documents take effect, `file`: the specified file suffix takes effect, `directory`: the specified path takes effect, `path`: specify the absolute path to take effect, `index`: home page, `default`: effective when the source site has no max-age. +* `switch` - (Optional) Cache configuration switch. Valid values are `on` and `off`. + The `server_certificate_config` object supports the following: * `certificate_content` - (Optional) Server certificate information. This is required when uploading an external certificate, which should contain the complete certificate chain. From 47ce459b8ff371d43bcdb2c3a4a061fe7ce167df Mon Sep 17 00:00:00 2001 From: hhermanwang Date: Thu, 14 Jan 2021 14:22:22 +0800 Subject: [PATCH 2/3] modify changelog.md file add datasource setting --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b10a52338..23ffb53e50 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ ENHANCEMENTS: * Resource `tencentcloud_cdn_domain` add `range_origin_switch` to support range back to source configuration. * Resource `tencentcloud_cdn_domain` add `rule_cache` to support advanced path cache configuration. * Resource `tencentcloud_cdn_domain` add `request_header` to support request header configuration. +* Data Source `tencentcloud_cdn_domains` add `range_origin_switch` to support range back to source configuration. +* Data Source `tencentcloud_cdn_domains` add `rule_cache` to support advanced path cache configuration. +* Data Source `tencentcloud_cdn_domains` add `request_header` to support request header configuration. ## 1.51.1 (December 22, 2020) From 5a010e2020e3ea72184e35ac75db1a604a0469eb Mon Sep 17 00:00:00 2001 From: hhermanwang Date: Thu, 14 Jan 2021 15:50:17 +0800 Subject: [PATCH 3/3] Add blank lines to complex structures --- examples/tencentcloud-cdn/main.tf | 3 +++ tencentcloud/data_source_tc_cdn_domains_test.go | 4 ++++ tencentcloud/resource_tc_cdn_domain.go | 5 ++++- tencentcloud/resource_tc_cdn_domain_test.go | 6 ++++++ website/docs/r/cdn_domain.html.markdown | 5 ++++- 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/examples/tencentcloud-cdn/main.tf b/examples/tencentcloud-cdn/main.tf index 2df48e1568..fc3c92a41c 100644 --- a/examples/tencentcloud-cdn/main.tf +++ b/examples/tencentcloud-cdn/main.tf @@ -3,13 +3,16 @@ resource "tencentcloud_cdn_domain" "foo" { service_type = "web" area = "mainland" range_origin_switch = "off" + rule_cache{ cache_time = 10000 no_cache_switch="on" re_validate="on" } + request_header{ switch = "on" + header_rules { header_mode = "add" header_name = "tf-header-name" diff --git a/tencentcloud/data_source_tc_cdn_domains_test.go b/tencentcloud/data_source_tc_cdn_domains_test.go index 3c5e81df23..38e015b0da 100644 --- a/tencentcloud/data_source_tc_cdn_domains_test.go +++ b/tencentcloud/data_source_tc_cdn_domains_test.go @@ -58,13 +58,16 @@ resource "tencentcloud_cdn_domain" "foo" { area = "mainland" full_url_cache = false range_origin_switch = "off" + rule_cache{ cache_time = 10000 no_cache_switch="on" re_validate="on" } + request_header{ switch = "on" + header_rules { header_mode = "add" header_name = "tf-header-name" @@ -73,6 +76,7 @@ resource "tencentcloud_cdn_domain" "foo" { rule_paths = ["*"] } } + origin { origin_type = "ip" origin_list = ["172.199.199.140"] diff --git a/tencentcloud/resource_tc_cdn_domain.go b/tencentcloud/resource_tc_cdn_domain.go index 1c100ffc7b..036c98676b 100644 --- a/tencentcloud/resource_tc_cdn_domain.go +++ b/tencentcloud/resource_tc_cdn_domain.go @@ -45,13 +45,16 @@ resource "tencentcloud_cdn_domain" "foo" { area = "mainland" full_url_cache = false range_origin_switch = "off" + rule_cache{ cache_time = 10000 no_cache_switch="on" re_validate="on" } + request_header{ switch = "on" + header_rules { header_mode = "add" header_name = "tf-header-name" @@ -277,7 +280,7 @@ func resourceTencentCloudCdnDomain() *schema.Resource { Optional: true, Default: CDN_SWITCH_OFF, ValidateFunc: validateAllowedStringValue(CDN_SWITCH), - Description: "Spdy configuration switch. Valid values are `on` and `off`. and default value is `off`. The current version does not support `on`.", + Description: "Spdy configuration switch. Valid values are `on` and `off`. and default value is `off`. This parameter is for white-list customer.", }, "verify_client": { Type: schema.TypeString, diff --git a/tencentcloud/resource_tc_cdn_domain_test.go b/tencentcloud/resource_tc_cdn_domain_test.go index f890afd9f9..a43ade3d95 100644 --- a/tencentcloud/resource_tc_cdn_domain_test.go +++ b/tencentcloud/resource_tc_cdn_domain_test.go @@ -220,8 +220,10 @@ resource "tencentcloud_cdn_domain" "foo" { no_cache_switch="on" re_validate="on" } + request_header{ switch = "on" + header_rules { header_mode = "add" header_name = "tf-header-name" @@ -230,6 +232,7 @@ resource "tencentcloud_cdn_domain" "foo" { rule_paths = ["*"] } } + origin { origin_type = "ip" origin_list = ["139.199.199.140"] @@ -322,6 +325,7 @@ resource "tencentcloud_cdn_domain" "foo" { area = "mainland" full_url_cache = false range_origin_switch = "on" + rule_cache { cache_time = 20000 rule_paths=["*"] @@ -334,9 +338,11 @@ resource "tencentcloud_cdn_domain" "foo" { re_validate="off" follow_origin_switch="off" } + request_header{ switch = "off" } + origin { origin_type = "ip" origin_list = ["139.199.199.140"] diff --git a/website/docs/r/cdn_domain.html.markdown b/website/docs/r/cdn_domain.html.markdown index 585074c64e..3c71ee6b61 100644 --- a/website/docs/r/cdn_domain.html.markdown +++ b/website/docs/r/cdn_domain.html.markdown @@ -55,13 +55,16 @@ resource "tencentcloud_cdn_domain" "foo" { area = "mainland" full_url_cache = false range_origin_switch = "off" + rule_cache { cache_time = 10000 no_cache_switch = "on" re_validate = "on" } + request_header { switch = "on" + header_rules { header_mode = "add" header_name = "tf-header-name" @@ -173,7 +176,7 @@ The `https_config` object supports the following: * `http2_switch` - (Optional) HTTP2 configuration switch. Valid values are `on` and `off`. and default value is `off`. * `ocsp_stapling_switch` - (Optional) OCSP configuration switch. Valid values are `on` and `off`. and default value is `off`. * `server_certificate_config` - (Optional) Server certificate configuration information. -* `spdy_switch` - (Optional) Spdy configuration switch. Valid values are `on` and `off`. and default value is `off`. The current version does not support `on`. +* `spdy_switch` - (Optional) Spdy configuration switch. Valid values are `on` and `off`. and default value is `off`. This parameter is for white-list customer. * `verify_client` - (Optional) Client certificate authentication feature. Valid values are `on` and `off`. and default value is `off`. The `origin` object supports the following: