Skip to content

Commit aba30e1

Browse files
author
ttomzhou
committed
fix cdn force redirect
1 parent a1e97fb commit aba30e1

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

tencentcloud/resource_tc_cdn_domain.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ resource "tencentcloud_cdn_domain" "foo" {
2424
verify_client = "off"
2525
2626
force_redirect {
27-
switch = "on"
27+
switch = "on"
28+
redirect_type = "http"
29+
redirect_status_code = 302
2830
}
2931
}
3032
@@ -326,18 +328,18 @@ func resourceTencentCloudCdnDomain() *schema.Resource {
326328
"redirect_type": {
327329
Type: schema.TypeString,
328330
Optional: true,
329-
Computed: true,
331+
Default: CDN_ORIGIN_PULL_PROTOCOL_HTTP,
330332
ValidateFunc: validateAllowedStringValue(CDN_FORCE_REDIRECT_TYPE),
331-
Description: "Access forced jump type. Valid values are `http` and `https`. " +
332-
"When `switch` setting `off`, this property does not need to be set or set to `http`.",
333+
Description: "Access forced jump type. Valid values are `http` and `https`. `http` means force http redirect, `https` means force http redirect. " +
334+
"When `switch` setting `off`, this property does not need to be set or set to `http`. Default value is `http`.",
333335
},
334336
"redirect_status_code": {
335337
Type: schema.TypeInt,
336338
Optional: true,
337-
Computed: true,
339+
Default: 302,
338340
ValidateFunc: validateAllowedIntValue([]int{301, 302}),
339341
Description: "Access forced jump code. Valid values are `301` and `302`. " +
340-
"When `switch` setting `off`, this property does not need to be set or set to `302`.",
342+
"When `switch` setting `off`, this property does not need to be set or set to `302`. Default value is `302`.",
341343
},
342344
},
343345
},
@@ -473,7 +475,7 @@ func resourceTencentCloudCdnDomainCreate(d *schema.ResourceData, meta interface{
473475
}
474476
}
475477
}
476-
if v := config["force_redirect"]; len(v.([]interface{})) > 0 {
478+
if v, ok := config["force_redirect"]; ok {
477479
forceRedirect := v.([]interface{})
478480
if len(forceRedirect) > 0 {
479481
var redirect cdn.ForceRedirect
@@ -788,7 +790,7 @@ func resourceTencentCloudCdnDomainUpdate(d *schema.ResourceData, meta interface{
788790
}
789791
}
790792
}
791-
if v := config["force_redirect"]; len(v.([]interface{})) > 0 {
793+
if v, ok := config["force_redirect"]; ok {
792794
forceRedirect := v.([]interface{})
793795
if len(forceRedirect) > 0 {
794796
var redirect cdn.ForceRedirect

tencentcloud/resource_tc_cdn_domain_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ func TestAccTencentCloudCdnDomainWithHTTPs(t *testing.T) {
6464
resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.deploy_time"),
6565
resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.expire_time"),
6666
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "tags.hello", "world"),
67-
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.switch", "off"),
68-
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.redirect_type", "http"),
67+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.switch", "on"),
68+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.redirect_type", "https"),
6969
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.redirect_status_code", "302"),
7070
),
7171
},
@@ -89,8 +89,8 @@ func TestAccTencentCloudCdnDomainWithHTTPs(t *testing.T) {
8989
resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.deploy_time"),
9090
resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.expire_time"),
9191
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "tags.hello", "world"),
92-
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.switch", "on"),
93-
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.redirect_type", "https"),
92+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.switch", "off"),
93+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.redirect_type", "http"),
9494
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.redirect_status_code", "302"),
9595
),
9696
},
@@ -203,6 +203,12 @@ resource "tencentcloud_cdn_domain" "foo" {
203203
spdy_switch = "on"
204204
verify_client = "off"
205205
206+
force_redirect {
207+
switch = "on"
208+
redirect_type = "https"
209+
redirect_status_code = 302
210+
}
211+
206212
server_certificate_config {
207213
certificate_content = <<EOT
208214
-----BEGIN CERTIFICATE-----
@@ -290,9 +296,7 @@ resource "tencentcloud_cdn_domain" "foo" {
290296
verify_client = "off"
291297
292298
force_redirect {
293-
switch = "on"
294-
redirect_type = "https"
295-
redirect_status_code = 302
299+
switch = "off"
296300
}
297301
298302
server_certificate_config {

website/docs/r/cdn_domain.html.markdown

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ resource "tencentcloud_cdn_domain" "foo" {
3434
verify_client = "off"
3535
3636
force_redirect {
37-
switch = "on"
37+
switch = "on"
38+
redirect_type = "http"
39+
redirect_status_code = 302
3840
}
3941
}
4042
@@ -97,8 +99,8 @@ The `client_certificate_config` object supports the following:
9799

98100
The `force_redirect` object supports the following:
99101

100-
* `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`.
101-
* `redirect_type` - (Optional) Access forced jump type. Valid values are `http` and `https`. When `switch` setting `off`, this property does not need to be set or set to `http`.
102+
* `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`.
103+
* `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`.
102104
* `switch` - (Optional) Access forced jump configuration switch. Valid values are `on` and `off`. Default value is `off`.
103105

104106
The `https_config` object supports the following:

0 commit comments

Comments
 (0)