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
4 changes: 4 additions & 0 deletions examples/tencentcloud-cdn/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ resource "tencentcloud_cdn_domain" "foo" {
ocsp_stapling_switch = "off"
spdy_switch = "off"
verify_client = "off"

force_redirect {
switch = "on"
}
}

tags = {
Expand Down
5 changes: 5 additions & 0 deletions tencentcloud/extension_cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ var CDN_ORIGIN_PULL_PROTOCOL = []string{
CDN_ORIGIN_PULL_PROTOCOL_FOLLOW,
}

var CDN_FORCE_REDIRECT_TYPE = []string{
CDN_ORIGIN_PULL_PROTOCOL_HTTP,
CDN_ORIGIN_PULL_PROTOCOL_HTTPS,
}

var CDN_AREA = []string{
CDN_AREA_MAINLAND,
CDN_AREA_OVERSEAS,
Expand Down
85 changes: 84 additions & 1 deletion tencentcloud/resource_tc_cdn_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ resource "tencentcloud_cdn_domain" "foo" {
ocsp_stapling_switch = "off"
spdy_switch = "off"
verify_client = "off"

force_redirect {
switch = "on"
redirect_type = "http"
redirect_status_code = 302
}
}

tags = {
Expand Down Expand Up @@ -304,6 +310,40 @@ func resourceTencentCloudCdnDomain() *schema.Resource {
},
},
},
"force_redirect": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 1,
Description: "Access protocol mandatory jump 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: "Access forced jump configuration switch. Valid values are `on` and `off`. Default value is `off`.",
},
"redirect_type": {
Type: schema.TypeString,
Optional: true,
Default: CDN_ORIGIN_PULL_PROTOCOL_HTTP,
ValidateFunc: validateAllowedStringValue(CDN_FORCE_REDIRECT_TYPE),
Description: "Access forced jump type. Valid values are `http` and `https`. `http` means force http redirect, `https` means force http redirect. " +
"When `switch` setting `off`, this property does not need to be set or set to `http`. Default value is `http`.",
},
"redirect_status_code": {
Type: schema.TypeInt,
Optional: true,
Default: 302,
ValidateFunc: validateAllowedIntValue([]int{301, 302}),
Description: "Access forced jump code. Valid values are `301` and `302`. " +
"When `switch` setting `off`, this property does not need to be set or set to `302`. Default value is `302`.",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -435,6 +475,23 @@ func resourceTencentCloudCdnDomainCreate(d *schema.ResourceData, meta interface{
}
}
}
if v, ok := config["force_redirect"]; ok {
forceRedirect := v.([]interface{})
if len(forceRedirect) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

上面不是判断了么

var redirect cdn.ForceRedirect
redirectMap := forceRedirect[0].(map[string]interface{})
if sw := redirectMap["switch"]; sw.(string) != "" {
redirect.Switch = helper.String(sw.(string))
}
if rt := redirectMap["redirect_type"]; rt.(string) != "" {
redirect.RedirectType = helper.String(rt.(string))
}
if rsc := redirectMap["redirect_status_code"]; rsc.(int) != 0 {
redirect.RedirectStatusCode = helper.Int64(int64(rsc.(int)))
}
request.ForceRedirect = &redirect
}
}
}
}

Expand Down Expand Up @@ -542,7 +599,7 @@ func resourceTencentCloudCdnDomainRead(d *schema.ResourceData, meta interface{})
_ = d.Set("origin", origins)

httpsConfigs := make([]map[string]interface{}, 0, 1)
httpsConfig := make(map[string]interface{}, 7)
httpsConfig := make(map[string]interface{}, 8)
httpsConfig["https_switch"] = domainConfig.Https.Switch
httpsConfig["http2_switch"] = domainConfig.Https.Http2
httpsConfig["ocsp_stapling_switch"] = domainConfig.Https.OcspStapling
Expand Down Expand Up @@ -597,6 +654,15 @@ func resourceTencentCloudCdnDomainRead(d *schema.ResourceData, meta interface{})
clientCertConfigs = append(clientCertConfigs, clientCertConfig)
httpsConfig["client_certificate_config"] = clientCertConfigs
}
if domainConfig.ForceRedirect != nil {
httpsConfig["force_redirect"] = []map[string]interface{}{
{
"switch": domainConfig.ForceRedirect.Switch,
"redirect_type": domainConfig.ForceRedirect.RedirectType,
"redirect_status_code": domainConfig.ForceRedirect.RedirectStatusCode,
},
}
}
httpsConfigs = append(httpsConfigs, httpsConfig)
_ = d.Set("https_config", httpsConfigs)

Expand Down Expand Up @@ -724,6 +790,23 @@ func resourceTencentCloudCdnDomainUpdate(d *schema.ResourceData, meta interface{
}
}
}
if v, ok := config["force_redirect"]; ok {
forceRedirect := v.([]interface{})
if len(forceRedirect) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

var redirect cdn.ForceRedirect
redirectMap := forceRedirect[0].(map[string]interface{})
if sw := redirectMap["switch"]; sw.(string) != "" {
redirect.Switch = helper.String(sw.(string))
}
if rt := redirectMap["redirect_type"]; rt.(string) != "" {
redirect.RedirectType = helper.String(rt.(string))
}
if rsc := redirectMap["redirect_status_code"]; rsc.(int) != 0 {
redirect.RedirectStatusCode = helper.Int64(int64(rsc.(int)))
}
request.ForceRedirect = &redirect
}
}
}
}

Expand Down
160 changes: 150 additions & 10 deletions tencentcloud/resource_tc_cdn_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ func TestAccTencentCloudCdnDomain(t *testing.T) {
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.origin_list.#", "1"),
),
},
{
ResourceName: "tencentcloud_cdn_domain.foo",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"https_config"},
},
},
})
}

func TestAccTencentCloudCdnDomainWithHTTPs(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCdnDomainDestroy,
Steps: []resource.TestStep{
{
Config: testAccCdnDomainFull,
Check: resource.ComposeTestCheckFunc(
Expand All @@ -48,6 +64,34 @@ func TestAccTencentCloudCdnDomain(t *testing.T) {
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.hello", "world"),
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.switch", "on"),
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.redirect_type", "https"),
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.redirect_status_code", "302"),
),
},
{
Config: testAccCdnDomainFullUpdate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "domain", "test.zhaoshaona.com"),
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", "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"),
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.origin_pull_protocol", "follow"),
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.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.hello", "world"),
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.switch", "off"),
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.redirect_type", "http"),
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.redirect_status_code", "302"),
),
},
{
Expand Down Expand Up @@ -140,24 +184,30 @@ resource "tencentcloud_cdn_domain" "foo" {

const testAccCdnDomainFull = `
resource "tencentcloud_cdn_domain" "foo" {
domain = "test.zhaoshaona.com"
service_type = "web"
area = "mainland"
domain = "test.zhaoshaona.com"
service_type = "web"
area = "mainland"
full_url_cache = false

origin {
origin_type = "ip"
origin_list = ["139.199.199.140"]
server_name = "test.zhaoshaona.com"
origin_type = "ip"
origin_list = ["139.199.199.140"]
server_name = "test.zhaoshaona.com"
origin_pull_protocol = "follow"
}

https_config {
https_switch = "on"
http2_switch = "on"
https_switch = "on"
http2_switch = "on"
ocsp_stapling_switch = "on"
spdy_switch = "on"
verify_client = "off"
spdy_switch = "on"
verify_client = "off"

force_redirect {
switch = "on"
redirect_type = "https"
redirect_status_code = 302
}

server_certificate_config {
certificate_content = <<EOT
Expand Down Expand Up @@ -216,7 +266,97 @@ KKcVGqvwVh2r8ocP7OnrQPVK9ZW7BcoYiqM2DjdKyl7AtQKnvWfPMai++oXKzo0y
EOT
message = "test"
}
}

tags = {
hello = "world"
}
}
`

const testAccCdnDomainFullUpdate = `
resource "tencentcloud_cdn_domain" "foo" {
domain = "test.zhaoshaona.com"
service_type = "web"
area = "mainland"
full_url_cache = false

origin {
origin_type = "ip"
origin_list = ["139.199.199.140"]
server_name = "test.zhaoshaona.com"
origin_pull_protocol = "follow"
}

https_config {
https_switch = "on"
http2_switch = "on"
ocsp_stapling_switch = "on"
spdy_switch = "on"
verify_client = "off"

force_redirect {
switch = "off"
}

server_certificate_config {
certificate_content = <<EOT
-----BEGIN CERTIFICATE-----
MIIDuDCCAqACCQDJd98Shn/cJTANBgkqhkiG9w0BAQsFADCBnTELMAkGA1UEBhMC
Q04xEDAOBgNVBAgMB1RpYW5qaW4xEDAOBgNVBAcMB1RpYW5qaW4xDjAMBgNVBAoM
BU1vY2hhMRcwFQYDVQQLDA5Nb2NoYSBTb2Z0d2FyZTEcMBoGA1UEAwwTdGVzdC56
aGFvc2hhb25hLmNvbTEjMCEGCSqGSIb3DQEJARYUeWFsaW5wZWlAdGVuY2VudC5j
b20wHhcNMjAwNTIwMDcyNDQyWhcNMzAwNTE4MDcyNDQyWjCBnTELMAkGA1UEBhMC
Q04xEDAOBgNVBAgMB1RpYW5qaW4xEDAOBgNVBAcMB1RpYW5qaW4xDjAMBgNVBAoM
BU1vY2hhMRcwFQYDVQQLDA5Nb2NoYSBTb2Z0d2FyZTEcMBoGA1UEAwwTdGVzdC56
aGFvc2hhb25hLmNvbTEjMCEGCSqGSIb3DQEJARYUeWFsaW5wZWlAdGVuY2VudC5j
b20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCgndm2xEWL7CaVQ/lb
TO6Gj4EqEp1tWygjdfqkUXADfsgMGPukYaZY+klV6AJzLcj8VD5iWgKa+V4kLHtf
yh66c45nZrdUVoF9CFTw2+B/LTa/UzsvbLTVOnEjVBjI1V5kVzliF5cK5OlQ258d
w6yFaccOgXqSkp9i57Y9pT1FIb691hsf2VHiVLizPYy3vvLQeN8RnXS3vK56BcQk
o+49H11T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W9t87cfZtFKcbKVcImLWucd9R7Ny4M4r6xlRKWpA==
-----END RSA PRIVATE KEY-----
EOT
message = "test"
}
}

tags = {
hello = "world"
Expand Down
13 changes: 13 additions & 0 deletions website/docs/r/cdn_domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ resource "tencentcloud_cdn_domain" "foo" {
ocsp_stapling_switch = "off"
spdy_switch = "off"
verify_client = "off"

force_redirect {
switch = "on"
redirect_type = "http"
redirect_status_code = 302
}
}

tags = {
Expand Down Expand Up @@ -91,10 +97,17 @@ The `client_certificate_config` object supports the following:

* `certificate_content` - (Required) Client Certificate PEM format, requires Base64 encoding.

The `force_redirect` object supports the following:

* `redirect_status_code` - (Optional) Access forced jump code. Valid values are `301` and `302`. When `switch` setting `off`, this property does not need to be set or set to `302`. Default value is `302`.
* `redirect_type` - (Optional) Access forced jump type. Valid values are `http` and `https`. `http` means force http redirect, `https` means force http redirect. When `switch` setting `off`, this property does not need to be set or set to `http`. Default value is `http`.
* `switch` - (Optional) Access forced jump configuration switch. Valid values are `on` and `off`. Default value is `off`.

The `https_config` object supports the following:

* `https_switch` - (Required) HTTPS configuration switch. Valid values are `on` and `off`.
* `client_certificate_config` - (Optional) Client certificate configuration information.
* `force_redirect` - (Optional) Access protocol mandatory jump configuration. It's a list and consist of at most one item.
* `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.
Expand Down