diff --git a/CHANGELOG.md b/CHANGELOG.md index 448933e0ad..58185e5136 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,18 +1,24 @@ ## 1.33.1 (Unreleased) ENHANCEMENTS: -Resource: `tencentcloud_redis_instance` add new argument `type_id`,`redis_shard_num`,`redis_replicas_num` -Resource: `tencentcloud_ccn_attachment` add new type `CNN_INSTANCE_TYPE_VPNGW` for field `instance_type` -Resource: `tencentcloud_vpn_gateway` add new type `CCN` for field `type` -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` -Data Source: `tencentcloud_ccn_instances` add new type `VPNGW` for field `instance_type` -Data Source: `tencentcloud_vpn_gateways` add new type `CCN` for field `type` + +* 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` +* Data Source: `tencentcloud_ccn_instances` add new type `VPNGW` for field `instance_type` +* Data Source: `tencentcloud_vpn_gateways` add new type `CCN` for field `type` +* Resource: `tencentcloud_redis_instance` add new argument `type_id`, `redis_shard_num`, `redis_replicas_num` +* Resource: `tencentcloud_ccn_attachment` add new type `CNN_INSTANCE_TYPE_VPNGW` for field `instance_type` +* Resource: `tencentcloud_vpn_gateway` add new type `CCN` for field `type` + +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) diff --git a/tencentcloud/extension_cdn.go b/tencentcloud/extension_cdn.go index bbf9b3de28..39ff745560 100644 --- a/tencentcloud/extension_cdn.go +++ b/tencentcloud/extension_cdn.go @@ -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{ diff --git a/tencentcloud/resource_tc_cdn_domain.go b/tencentcloud/resource_tc_cdn_domain.go index 613d00c91a..e8aeb83a3c 100644 --- a/tencentcloud/resource_tc_cdn_domain.go +++ b/tencentcloud/resource_tc_cdn_domain.go @@ -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" ) @@ -208,7 +209,7 @@ func resourceTencentCloudCdnDomain() *schema.Resource { }, "certificate_name": { Type: schema.TypeString, - Optional: true, + Computed: true, Description: "Server certificate name.", }, "certificate_content": { @@ -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.", + }, }, }, }, @@ -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.", + }, }, }, }, @@ -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)) } @@ -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)) } @@ -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 @@ -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 } @@ -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)) } @@ -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)) } diff --git a/tencentcloud/resource_tc_cdn_domain_test.go b/tencentcloud/resource_tc_cdn_domain_test.go index 244a9c84aa..f65f35c890 100644 --- a/tencentcloud/resource_tc_cdn_domain_test.go +++ b/tencentcloud/resource_tc_cdn_domain_test.go @@ -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"}, }, }, }) @@ -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 { + certificate_content = <