Skip to content

fix cdn domain https config product inconsistency after apply #418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 11 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
## 1.33.1 (Unreleased)

ENHANCEMENTS:
Resource: `tencentcloud_redis_instance` add new argument `type_id`,`redis_shard_num`,`redis_replicas_num`
Data Source: `tencentcloud_redis_instances` add new argument `type_id`,`redis_shard_num`,`redis_replicas_num`
Data Source: `tencentcloud_redis_zone_config` add output argument `type_id` and new output argument `type_id`,`redis_shard_nums`,`redis_replicas_nums`

* Resource: `tencentcloud_redis_instance` add new argument `type_id`, `redis_shard_num`, `redis_replicas_num`.
* Data Source: `tencentcloud_redis_instances` add new argument `type_id`, `redis_shard_num`, `redis_replicas_num`.
* Data Source: `tencentcloud_redis_zone_config` add output argument `type_id` and new output argument `type_id`, `redis_shard_nums`, `redis_replicas_nums`.

BUG FIXES:

* Resource: `tencentcloud_cdn_domain` fix `https_config` inconsistency after apply([#413](https://github.com/terraform-providers/terraform-provider-tencentcloud/issues/413)).

DEPRECATED:

* Resource: `tencentcloud_redis_instance`: optional argument `type` is no longer supported, replace by `type_id`.
* Data Source: `tencentcloud_redis_instances`: output argument `type` is no longer supported, replace by `type_id`
* Data Source: `tencentcloud_redis_zone_config`: output argument `type` is no longer supported, replace by `type_id`
* Data Source: `tencentcloud_redis_instances`: output argument `type` is no longer supported, replace by `type_id`.
* Data Source: `tencentcloud_redis_zone_config`: output argument `type` is no longer supported, replace by `type_id`.

## 1.33.0 (May 18, 2020)

Expand Down
3 changes: 2 additions & 1 deletion tencentcloud/extension_cdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ const (
CDN_SERVICE_NAME = "cdn"
CDN_RESOURCE_NAME_DOMAIN = "domain"

CDN_HOST_NOT_FOUND = "ResourceNotFound.CdnHostNotExists"
CDN_HOST_NOT_FOUND = "ResourceNotFound.CdnHostNotExists"
CDN_DOMAIN_CONFIG_ERROE = "FailedOperation.CdnConfigError"
)

var CDN_SERVICE_TYPE = []string{
Expand Down
82 changes: 64 additions & 18 deletions tencentcloud/resource_tc_cdn_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
cdn "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cdn/v20180606"
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
"github.com/terraform-providers/terraform-provider-tencentcloud/tencentcloud/internal/helper"
"github.com/terraform-providers/terraform-provider-tencentcloud/tencentcloud/ratelimit"
)
Expand Down Expand Up @@ -208,7 +209,7 @@ func resourceTencentCloudCdnDomain() *schema.Resource {
},
"certificate_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Server certificate name.",
},
"certificate_content": {
Expand All @@ -226,6 +227,16 @@ func resourceTencentCloudCdnDomain() *schema.Resource {
Optional: true,
Description: "Certificate remarks.",
},
"deploy_time": {
Type: schema.TypeString,
Computed: true,
Description: "Deploy time of server certificate.",
},
"expire_time": {
Type: schema.TypeString,
Computed: true,
Description: "Expire time of server certificate.",
},
},
},
},
Expand All @@ -238,14 +249,24 @@ func resourceTencentCloudCdnDomain() *schema.Resource {
Schema: map[string]*schema.Schema{
"certificate_name": {
Type: schema.TypeString,
Required: true,
Computed: true,
Description: "Client certificate name.",
},
"certificate_content": {
Type: schema.TypeString,
Optional: true,
Required: true,
Description: "Client Certificate PEM format, requires Base64 encoding.",
},
"deploy_time": {
Type: schema.TypeString,
Computed: true,
Description: "Deploy time of client certificate.",
},
"expire_time": {
Type: schema.TypeString,
Computed: true,
Description: "Expire time of client certificate.",
},
},
},
},
Expand Down Expand Up @@ -359,9 +380,6 @@ func resourceTencentCloudCdnDomainCreate(d *schema.ResourceData, meta interface{
if v := serverCert["certificate_id"]; v.(string) != "" {
request.Https.CertInfo.CertId = helper.String(v.(string))
}
if v := serverCert["certificate_name"]; v.(string) != "" {
request.Https.CertInfo.CertName = helper.String(v.(string))
}
if v := serverCert["certificate_content"]; v.(string) != "" {
request.Https.CertInfo.Certificate = helper.String(v.(string))
}
Expand All @@ -378,7 +396,6 @@ func resourceTencentCloudCdnDomainCreate(d *schema.ResourceData, meta interface{
if len(clientCerts) > 0 {
clientCert := clientCerts[0].(map[string]interface{})
request.Https.ClientCertInfo = &cdn.ClientCert{}
request.Https.ClientCertInfo.CertName = helper.String(clientCert["certificate_name"].(string))
if v := clientCert["certificate_content"]; v.(string) != "" {
request.Https.ClientCertInfo.Certificate = helper.String(v.(string))
}
Expand All @@ -391,8 +408,11 @@ func resourceTencentCloudCdnDomainCreate(d *schema.ResourceData, meta interface{
ratelimit.Check(request.GetAction())
_, err := meta.(*TencentCloudClient).apiV3Conn.UseCdnClient().AddCdnDomain(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
Expand Down Expand Up @@ -494,22 +514,52 @@ func resourceTencentCloudCdnDomainRead(d *schema.ResourceData, meta interface{})
httpsConfig["ocsp_stapling_switch"] = domainConfig.Https.OcspStapling
httpsConfig["spdy_switch"] = domainConfig.Https.Spdy
httpsConfig["verify_client"] = domainConfig.Https.VerifyClient
if domainConfig.Https.CertInfo != nil {

oldHttpsConfigs := make([]interface{}, 0)
if _, ok := d.GetOk("https_config"); ok {
oldHttpsConfigs = d.Get("https_config").([]interface{})
}
oldHttpsConfig := make(map[string]interface{})
if len(oldHttpsConfigs) > 0 {
oldHttpsConfig = oldHttpsConfigs[0].(map[string]interface{})
}
oldServerConfigs := make([]interface{}, 0)
if _, ok := oldHttpsConfig["server_certificate_config"]; ok {
oldServerConfigs = oldHttpsConfig["server_certificate_config"].([]interface{})
}
oldServerConfig := make(map[string]interface{})
if len(oldServerConfigs) > 0 {
oldServerConfig = oldServerConfigs[0].(map[string]interface{})
}
oldClientConfigs := make([]interface{}, 0)
if _, ok := oldHttpsConfig["client_certificate_config"]; ok {
oldClientConfigs = oldHttpsConfig["client_certificate_config"].([]interface{})
}
oldClientConfig := make(map[string]interface{})
if len(oldClientConfigs) > 0 {
oldClientConfig = oldClientConfigs[0].(map[string]interface{})
}

if domainConfig.Https.CertInfo != nil && domainConfig.Https.CertInfo.CertName != nil {
serverCertConfigs := make([]map[string]interface{}, 0, 1)
serverCertConfig := make(map[string]interface{}, 5)
serverCertConfig["certificate_id"] = domainConfig.Https.CertInfo.CertId
serverCertConfig["certificate_name"] = domainConfig.Https.CertInfo.CertName
serverCertConfig["certificate_content"] = domainConfig.Https.CertInfo.Certificate
serverCertConfig["private_key"] = domainConfig.Https.CertInfo.PrivateKey
serverCertConfig["certificate_content"] = oldServerConfig["certificate_content"]
serverCertConfig["private_key"] = oldServerConfig["private_key"]
serverCertConfig["message"] = domainConfig.Https.CertInfo.Message
serverCertConfig["deploy_time"] = domainConfig.Https.CertInfo.DeployTime
serverCertConfig["expire_time"] = domainConfig.Https.CertInfo.ExpireTime
serverCertConfigs = append(serverCertConfigs, serverCertConfig)
httpsConfig["server_certificate_config"] = serverCertConfigs
}
if domainConfig.Https.ClientCertInfo != nil {
if domainConfig.Https.ClientCertInfo != nil && domainConfig.Https.ClientCertInfo.CertName != nil {
clientCertConfigs := make([]map[string]interface{}, 0, 1)
clientCertConfig := make(map[string]interface{}, 2)
clientCertConfig["certificate_content"] = oldClientConfig["certificate_content"]
clientCertConfig["certificate_name"] = domainConfig.Https.ClientCertInfo.CertName
clientCertConfig["certificate_content"] = domainConfig.Https.ClientCertInfo.Certificate
clientCertConfig["deploy_time"] = domainConfig.Https.ClientCertInfo.DeployTime
clientCertConfig["expire_time"] = domainConfig.Https.ClientCertInfo.ExpireTime
clientCertConfigs = append(clientCertConfigs, clientCertConfig)
httpsConfig["client_certificate_config"] = clientCertConfigs
}
Expand Down Expand Up @@ -619,9 +669,6 @@ func resourceTencentCloudCdnDomainUpdate(d *schema.ResourceData, meta interface{
if v := serverCert["certificate_id"]; v.(string) != "" {
request.Https.CertInfo.CertId = helper.String(v.(string))
}
if v := serverCert["certificate_name"]; v.(string) != "" {
request.Https.CertInfo.CertName = helper.String(v.(string))
}
if v := serverCert["certificate_content"]; v.(string) != "" {
request.Https.CertInfo.Certificate = helper.String(v.(string))
}
Expand All @@ -638,7 +685,6 @@ func resourceTencentCloudCdnDomainUpdate(d *schema.ResourceData, meta interface{
if len(clientCerts) > 0 {
clientCert := clientCerts[0].(map[string]interface{})
request.Https.ClientCertInfo = &cdn.ClientCert{}
request.Https.ClientCertInfo.CertName = helper.String(clientCert["certificate_name"].(string))
if v := clientCert["certificate_content"]; v.(string) != "" {
request.Https.ClientCertInfo.Certificate = helper.String(v.(string))
}
Expand Down
84 changes: 73 additions & 11 deletions tencentcloud/resource_tc_cdn_domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,22 @@ func TestAccTencentCloudCdnDomain(t *testing.T) {
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", "off"),
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.http2_switch", "off"),
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.ocsp_stapling_switch", "off"),
resource.TestCheckResourceAttr("tencentcloud_cdn_domain.foo", "https_config.0.spdy_switch", "off"),
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"),
),
},
{
ResourceName: "tencentcloud_cdn_domain.foo",
ImportState: true,
ImportStateVerify: true,
ResourceName: "tencentcloud_cdn_domain.foo",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"https_config"},
},
},
})
Expand Down Expand Up @@ -149,11 +153,69 @@ resource "tencentcloud_cdn_domain" "foo" {
}

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

server_certificate_config {
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UaHs+dFfyFyd0unr/rAPf/
GO/BIO0NbBdRb3XORMuiLQN3xf+qgKfoS0kXYglDMGKbEAC/5o6ZMV6E2E/aFrxh
xmgKTZxCBVnOxlAy33UFs+qR8tpOnR4auAc0pNPA9QB4I7q17vGJRMyHAoGBAMFf
7nF2aJ/k0Fcl53Cabs/FIaAwL/GBvok6Ny8wWLwiMZCtsGUUywnUdN/qbfr2GwC5
g0w2iaxGqQPI+qw2qn0utAIfZ0Tz2VAH+P3aUTuG+M4XWHObHVXxBUqO61X9zgV2
sXRXcbDOx3HgZeDCjk0otcGVJoC3zgzaaEZi5mQVAoGAQer+2gQ1PUm27XmOmL78
bI+EjHbjhpKDbL95GnDrdKtIQZz8DuXBeEo6B+M6WDxBvpa0kyByrfmKo0jbW7JS
7JTYKqDuthL2MhVLx3dMa83pNVAZ7kqtdIGFL+TzvbSxnBk5VxDuhtC6Jd1rLfMA
jBNQ6eiOy5dzFCXkrnJspq8CgYAO4ISFsihmdMIakk31+cugrHfjzRFDMUopYJMy
TDPndXH+wX4aqLjeLrw3JeAEOL7nFV6mlGOPH3iNU/8FFMeVDezHZQca5O/JGnPr
g8pQHBg0MtOZQUvGet5/V/N/ECGzhegtHTUf9yic+DieTBmKkiE5nXHy4TE3B+6R
y7YR6QKBgQDUoNAFOnMZB4BQMeCb/pQQnzNkNTG+Y02eMKjo5eZZDfyusqIui29l
KKcVGqvwVh2r8ocP7OnrQPVK9ZW7BcoYiqM2DjdKyl7AtQKnvWfPMai++oXKzo0y
8sg7m1Ic26sKO9W9t87cfZtFKcbKVcImLWucd9R7Ny4M4r6xlRKWpA==
-----END RSA PRIVATE KEY-----
EOT
message = "test"
}
}

tags = {
Expand Down
4 changes: 1 addition & 3 deletions website/docs/r/cdn_domain.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ The following arguments are supported:

The `client_certificate_config` object supports the following:

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

The `https_config` object supports the following:

Expand All @@ -82,7 +81,6 @@ 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.
* `certificate_id` - (Optional) Server certificate ID.
* `certificate_name` - (Optional) Server certificate name.
* `message` - (Optional) Certificate remarks.
* `private_key` - (Optional) Server key information. This is required when uploading an external certificate.

Expand Down