Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ 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.
* 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)

Expand Down
19 changes: 19 additions & 0 deletions examples/tencentcloud-cdn/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@ resource "tencentcloud_cdn_domain" "foo" {
domain = "xxxx.com"
service_type = "web"
area = "mainland"
range_origin_switch = "off"

rule_cache{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复杂结构体空行

cache_time = 10000
no_cache_switch="on"
re_validate="on"
}

request_header{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

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"
Expand Down
180 changes: 167 additions & 13 deletions tencentcloud/data_source_tc_cdn_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
38 changes: 35 additions & 3 deletions tencentcloud/data_source_tc_cdn_domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),
),
},
},
Expand All @@ -44,6 +57,25 @@ 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"
Expand All @@ -56,7 +88,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 {
Expand Down
26 changes: 26 additions & 0 deletions tencentcloud/extension_cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
}
Loading