Skip to content

Commit 0f7dbfd

Browse files
author
ttomzhou
committed
merge upstream
2 parents 22a6e7b + b0f8cdd commit 0f7dbfd

13 files changed

+473
-106
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
ENHANCEMENTS:
44

55
* Resource: `tencentcloud_clb_listener` support configure HTTP health check for TCP listener([#539](https://github.com/tencentcloudstack/terraform-provider-tencentcloud/issues/539)).
6+
* Resource: `tencentcloud_clb_listener` add computed argument `target_type`.
67
* Data Source: `tencentcloud_clb_listeners` support getting HTTP health check config for TCP listener.
78

9+
DEPRECATED:
10+
* Resource: `tencentcloud_clb_target_group_attachment`: optional argument `targrt_group_id` is no longer supported, replace by `target_group_id`.
11+
12+
813
## 1.47.0 (November 13, 2020)
914

1015
ENHANCEMENTS:

examples/tencentcloud-cdn/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ resource "tencentcloud_cdn_domain" "foo" {
1515
ocsp_stapling_switch = "off"
1616
spdy_switch = "off"
1717
verify_client = "off"
18+
19+
force_redirect {
20+
switch = "on"
21+
}
1822
}
1923

2024
tags = {

tencentcloud/extension_cdn.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ var CDN_ORIGIN_PULL_PROTOCOL = []string{
5858
CDN_ORIGIN_PULL_PROTOCOL_FOLLOW,
5959
}
6060

61+
var CDN_FORCE_REDIRECT_TYPE = []string{
62+
CDN_ORIGIN_PULL_PROTOCOL_HTTP,
63+
CDN_ORIGIN_PULL_PROTOCOL_HTTPS,
64+
}
65+
6166
var CDN_AREA = []string{
6267
CDN_AREA_MAINLAND,
6368
CDN_AREA_OVERSEAS,

tencentcloud/resource_tc_cdn_domain.go

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ resource "tencentcloud_cdn_domain" "foo" {
2222
ocsp_stapling_switch = "off"
2323
spdy_switch = "off"
2424
verify_client = "off"
25+
26+
force_redirect {
27+
switch = "on"
28+
redirect_type = "http"
29+
redirect_status_code = 302
30+
}
2531
}
2632
2733
tags = {
@@ -304,6 +310,40 @@ func resourceTencentCloudCdnDomain() *schema.Resource {
304310
},
305311
},
306312
},
313+
"force_redirect": {
314+
Type: schema.TypeList,
315+
Optional: true,
316+
Computed: true,
317+
MaxItems: 1,
318+
Description: "Access protocol mandatory jump configuration. It's a list and consist of at most one item.",
319+
Elem: &schema.Resource{
320+
Schema: map[string]*schema.Schema{
321+
"switch": {
322+
Type: schema.TypeString,
323+
Optional: true,
324+
Default: CDN_SWITCH_OFF,
325+
ValidateFunc: validateAllowedStringValue(CDN_SWITCH),
326+
Description: "Access forced jump configuration switch. Valid values are `on` and `off`. Default value is `off`.",
327+
},
328+
"redirect_type": {
329+
Type: schema.TypeString,
330+
Optional: true,
331+
Default: CDN_ORIGIN_PULL_PROTOCOL_HTTP,
332+
ValidateFunc: validateAllowedStringValue(CDN_FORCE_REDIRECT_TYPE),
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`.",
335+
},
336+
"redirect_status_code": {
337+
Type: schema.TypeInt,
338+
Optional: true,
339+
Default: 302,
340+
ValidateFunc: validateAllowedIntValue([]int{301, 302}),
341+
Description: "Access forced jump code. Valid values are `301` and `302`. " +
342+
"When `switch` setting `off`, this property does not need to be set or set to `302`. Default value is `302`.",
343+
},
344+
},
345+
},
346+
},
307347
},
308348
},
309349
},
@@ -435,6 +475,23 @@ func resourceTencentCloudCdnDomainCreate(d *schema.ResourceData, meta interface{
435475
}
436476
}
437477
}
478+
if v, ok := config["force_redirect"]; ok {
479+
forceRedirect := v.([]interface{})
480+
if len(forceRedirect) > 0 {
481+
var redirect cdn.ForceRedirect
482+
redirectMap := forceRedirect[0].(map[string]interface{})
483+
if sw := redirectMap["switch"]; sw.(string) != "" {
484+
redirect.Switch = helper.String(sw.(string))
485+
}
486+
if rt := redirectMap["redirect_type"]; rt.(string) != "" {
487+
redirect.RedirectType = helper.String(rt.(string))
488+
}
489+
if rsc := redirectMap["redirect_status_code"]; rsc.(int) != 0 {
490+
redirect.RedirectStatusCode = helper.Int64(int64(rsc.(int)))
491+
}
492+
request.ForceRedirect = &redirect
493+
}
494+
}
438495
}
439496
}
440497

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

544601
httpsConfigs := make([]map[string]interface{}, 0, 1)
545-
httpsConfig := make(map[string]interface{}, 7)
602+
httpsConfig := make(map[string]interface{}, 8)
546603
httpsConfig["https_switch"] = domainConfig.Https.Switch
547604
httpsConfig["http2_switch"] = domainConfig.Https.Http2
548605
httpsConfig["ocsp_stapling_switch"] = domainConfig.Https.OcspStapling
@@ -597,6 +654,15 @@ func resourceTencentCloudCdnDomainRead(d *schema.ResourceData, meta interface{})
597654
clientCertConfigs = append(clientCertConfigs, clientCertConfig)
598655
httpsConfig["client_certificate_config"] = clientCertConfigs
599656
}
657+
if domainConfig.ForceRedirect != nil {
658+
httpsConfig["force_redirect"] = []map[string]interface{}{
659+
{
660+
"switch": domainConfig.ForceRedirect.Switch,
661+
"redirect_type": domainConfig.ForceRedirect.RedirectType,
662+
"redirect_status_code": domainConfig.ForceRedirect.RedirectStatusCode,
663+
},
664+
}
665+
}
600666
httpsConfigs = append(httpsConfigs, httpsConfig)
601667
_ = d.Set("https_config", httpsConfigs)
602668

@@ -724,6 +790,23 @@ func resourceTencentCloudCdnDomainUpdate(d *schema.ResourceData, meta interface{
724790
}
725791
}
726792
}
793+
if v, ok := config["force_redirect"]; ok {
794+
forceRedirect := v.([]interface{})
795+
if len(forceRedirect) > 0 {
796+
var redirect cdn.ForceRedirect
797+
redirectMap := forceRedirect[0].(map[string]interface{})
798+
if sw := redirectMap["switch"]; sw.(string) != "" {
799+
redirect.Switch = helper.String(sw.(string))
800+
}
801+
if rt := redirectMap["redirect_type"]; rt.(string) != "" {
802+
redirect.RedirectType = helper.String(rt.(string))
803+
}
804+
if rsc := redirectMap["redirect_status_code"]; rsc.(int) != 0 {
805+
redirect.RedirectStatusCode = helper.Int64(int64(rsc.(int)))
806+
}
807+
request.ForceRedirect = &redirect
808+
}
809+
}
727810
}
728811
}
729812

tencentcloud/resource_tc_cdn_domain_test.go

Lines changed: 150 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ func TestAccTencentCloudCdnDomain(t *testing.T) {
2828
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.origin_list.#", "1"),
2929
),
3030
},
31+
{
32+
ResourceName: "tencentcloud_cdn_domain.foo",
33+
ImportState: true,
34+
ImportStateVerify: true,
35+
ImportStateVerifyIgnore: []string{"https_config"},
36+
},
37+
},
38+
})
39+
}
40+
41+
func TestAccTencentCloudCdnDomainWithHTTPs(t *testing.T) {
42+
resource.Test(t, resource.TestCase{
43+
PreCheck: func() { testAccPreCheck(t) },
44+
Providers: testAccProviders,
45+
CheckDestroy: testAccCheckCdnDomainDestroy,
46+
Steps: []resource.TestStep{
3147
{
3248
Config: testAccCdnDomainFull,
3349
Check: resource.ComposeTestCheckFunc(
@@ -48,6 +64,34 @@ func TestAccTencentCloudCdnDomain(t *testing.T) {
4864
resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.deploy_time"),
4965
resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.expire_time"),
5066
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "tags.hello", "world"),
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"),
69+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.redirect_status_code", "302"),
70+
),
71+
},
72+
{
73+
Config: testAccCdnDomainFullUpdate,
74+
Check: resource.ComposeTestCheckFunc(
75+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "domain", "test.zhaoshaona.com"),
76+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "service_type", "web"),
77+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "area", "mainland"),
78+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "full_url_cache", "false"),
79+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.origin_type", "ip"),
80+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.origin_list.#", "1"),
81+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.server_name", "test.zhaoshaona.com"),
82+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "origin.0.origin_pull_protocol", "follow"),
83+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.https_switch", "on"),
84+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.http2_switch", "on"),
85+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.ocsp_stapling_switch", "on"),
86+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.spdy_switch", "on"),
87+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.verify_client", "off"),
88+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.message", "test"),
89+
resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.deploy_time"),
90+
resource.TestCheckResourceAttrSet("tencentcloud_cdn_domain.foo", "https_config.0.server_certificate_config.0.expire_time"),
91+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "tags.hello", "world"),
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"),
94+
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.force_redirect.0.redirect_status_code", "302"),
5195
),
5296
},
5397
{
@@ -140,24 +184,30 @@ resource "tencentcloud_cdn_domain" "foo" {
140184

141185
const testAccCdnDomainFull = `
142186
resource "tencentcloud_cdn_domain" "foo" {
143-
domain = "test.zhaoshaona.com"
144-
service_type = "web"
145-
area = "mainland"
187+
domain = "test.zhaoshaona.com"
188+
service_type = "web"
189+
area = "mainland"
146190
full_url_cache = false
147191
148192
origin {
149-
origin_type = "ip"
150-
origin_list = ["139.199.199.140"]
151-
server_name = "test.zhaoshaona.com"
193+
origin_type = "ip"
194+
origin_list = ["139.199.199.140"]
195+
server_name = "test.zhaoshaona.com"
152196
origin_pull_protocol = "follow"
153197
}
154198
155199
https_config {
156-
https_switch = "on"
157-
http2_switch = "on"
200+
https_switch = "on"
201+
http2_switch = "on"
158202
ocsp_stapling_switch = "on"
159-
spdy_switch = "on"
160-
verify_client = "off"
203+
spdy_switch = "on"
204+
verify_client = "off"
205+
206+
force_redirect {
207+
switch = "on"
208+
redirect_type = "https"
209+
redirect_status_code = 302
210+
}
161211
162212
server_certificate_config {
163213
certificate_content = <<EOT
@@ -216,7 +266,97 @@ KKcVGqvwVh2r8ocP7OnrQPVK9ZW7BcoYiqM2DjdKyl7AtQKnvWfPMai++oXKzo0y
216266
EOT
217267
message = "test"
218268
}
269+
}
270+
271+
tags = {
272+
hello = "world"
219273
}
274+
}
275+
`
276+
277+
const testAccCdnDomainFullUpdate = `
278+
resource "tencentcloud_cdn_domain" "foo" {
279+
domain = "test.zhaoshaona.com"
280+
service_type = "web"
281+
area = "mainland"
282+
full_url_cache = false
283+
284+
origin {
285+
origin_type = "ip"
286+
origin_list = ["139.199.199.140"]
287+
server_name = "test.zhaoshaona.com"
288+
origin_pull_protocol = "follow"
289+
}
290+
291+
https_config {
292+
https_switch = "on"
293+
http2_switch = "on"
294+
ocsp_stapling_switch = "on"
295+
spdy_switch = "on"
296+
verify_client = "off"
297+
298+
force_redirect {
299+
switch = "off"
300+
}
301+
302+
server_certificate_config {
303+
certificate_content = <<EOT
304+
-----BEGIN CERTIFICATE-----
305+
MIIDuDCCAqACCQDJd98Shn/cJTANBgkqhkiG9w0BAQsFADCBnTELMAkGA1UEBhMC
306+
Q04xEDAOBgNVBAgMB1RpYW5qaW4xEDAOBgNVBAcMB1RpYW5qaW4xDjAMBgNVBAoM
307+
BU1vY2hhMRcwFQYDVQQLDA5Nb2NoYSBTb2Z0d2FyZTEcMBoGA1UEAwwTdGVzdC56
308+
aGFvc2hhb25hLmNvbTEjMCEGCSqGSIb3DQEJARYUeWFsaW5wZWlAdGVuY2VudC5j
309+
b20wHhcNMjAwNTIwMDcyNDQyWhcNMzAwNTE4MDcyNDQyWjCBnTELMAkGA1UEBhMC
310+
Q04xEDAOBgNVBAgMB1RpYW5qaW4xEDAOBgNVBAcMB1RpYW5qaW4xDjAMBgNVBAoM
311+
BU1vY2hhMRcwFQYDVQQLDA5Nb2NoYSBTb2Z0d2FyZTEcMBoGA1UEAwwTdGVzdC56
312+
aGFvc2hhb25hLmNvbTEjMCEGCSqGSIb3DQEJARYUeWFsaW5wZWlAdGVuY2VudC5j
313+
b20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCgndm2xEWL7CaVQ/lb
314+
TO6Gj4EqEp1tWygjdfqkUXADfsgMGPukYaZY+klV6AJzLcj8VD5iWgKa+V4kLHtf
315+
yh66c45nZrdUVoF9CFTw2+B/LTa/UzsvbLTVOnEjVBjI1V5kVzliF5cK5OlQ258d
316+
w6yFaccOgXqSkp9i57Y9pT1FIb691hsf2VHiVLizPYy3vvLQeN8RnXS3vK56BcQk
317+
o+49H11TAsrIh0C5maF0jp/7poSQkrX0kjfX4+gK/mC4Dn3PgK464Ko5OR45IGji
318+
D368/klCK1bqIshlv4owEfgzAEQMPUQ0CfuvXTX85aojM48RiYiDmYveaICtYnSR
319+
04MTAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAHWUpfePVt3LjZVDS3OmQ7rTG8zc
320+
zwZgJfxP0f4ZNo/9t53SNsQ0UM/+7sqnBKOjsWfgyFqSh9cfN0Bnsn3gmvPXmD5R
321+
nCa9qr9IO+FP9Ke4KKn0Ndx1sWJN3B6D8bUTnvFIkJoRsvsqNi24o2uKrUdcAYHL
322+
5BVtrVe8E55i0A5WosC8KWv4ZJxTacvuxVjfyroKzxsLwOQvCqBNSuZLg1HYUeG6
323+
XIj0/acmysb8S82Lxm39E82DbPdUO3Z0TlGL7umlAV947/6eGvPhszjnhBlxVo3p
324+
tmHdyqfHxWbkTW4bnO/Gu+Sll6a3n1uyQ/onXuXH3pBZoXLp3Jj+CV1+N6E=
325+
-----END CERTIFICATE-----
326+
EOT
327+
328+
private_key = <<EOT
329+
-----BEGIN RSA PRIVATE KEY-----
330+
MIIEpAIBAAKCAQEAoJ3ZtsRFi+wmlUP5W0zuho+BKhKdbVsoI3X6pFFwA37IDBj7
331+
pGGmWPpJVegCcy3I/FQ+YloCmvleJCx7X8oeunOOZ2a3VFaBfQhU8Nvgfy02v1M7
332+
L2y01TpxI1QYyNVeZFc5YheXCuTpUNufHcOshWnHDoF6kpKfYue2PaU9RSG+vdYb
333+
H9lR4lS4sz2Mt77y0HjfEZ10t7yuegXEJKPuPR9dUwLKyIdAuZmhdI6f+6aEkJK1
334+
9JI31+PoCv5guA59z4CuOuCqOTkeOSBo4g9+vP5JQitW6iLIZb+KMBH4MwBEDD1E
335+
NAn7r101/OWqIzOPEYmIg5mL3miArWJ0kdODEwIDAQABAoIBAQCW2uuLX9k6THkI
336+
pSlleWJm/A4C6Cz4cy/F7p+VCfA9OCzIQAbKI/VLiPisORdj+tLVPILDeWsNB75G
337+
F4lhNMObt8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eZZDfyusqIui29l
353+
KKcVGqvwVh2r8ocP7OnrQPVK9ZW7BcoYiqM2DjdKyl7AtQKnvWfPMai++oXKzo0y
354+
8sg7m1Ic26sKO9W9t87cfZtFKcbKVcImLWucd9R7Ny4M4r6xlRKWpA==
355+
-----END RSA PRIVATE KEY-----
356+
EOT
357+
message = "test"
358+
}
359+
}
220360
221361
tags = {
222362
hello = "world"

0 commit comments

Comments
 (0)