Skip to content

Commit b49f40c

Browse files
WeiMengXSWeiMengXSandrew-tx
authored
feat: ssl-operation (#2174)
* feat: operation * feat: changelog * feat: changelog * feat: e2e --------- Co-authored-by: WeiMengXS <nickcchen@tencent.com> Co-authored-by: andrewjiang <104899514+andrew-tx@users.noreply.github.com>
1 parent 5a634f6 commit b49f40c

21 files changed

+1261
-0
lines changed

.changelog/2174.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
```release-note:new-resource
2+
tencentcloud_ssl_check_certificate_chain_operation
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_ssl_complete_certificate_operation
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_ssl_deploy_certificate_instance_operation
11+
```
12+
13+
```release-note:new-resource
14+
tencentcloud_ssl_deploy_certificate_record_retry_operation
15+
```
16+
17+
```release-note:new-resource
18+
tencentcloud_ssl_deploy_certificate_record_rollback_operation
19+
```
20+
21+
```release-note:new-resource
22+
tencentcloud_ssl_download_certificate_operation
23+
```

tencentcloud/provider.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,12 @@ SSL Certificates
921921
tencentcloud_ssl_certificate
922922
tencentcloud_ssl_pay_certificate
923923
tencentcloud_ssl_free_certificate
924+
tencentcloud_ssl_complete_certificate_operation
925+
tencentcloud_ssl_check_certificate_chain_operation
926+
tencentcloud_ssl_deploy_certificate_instance_operation
927+
tencentcloud_ssl_deploy_certificate_record_retry_operation
928+
tencentcloud_ssl_deploy_certificate_record_rollback_operation
929+
tencentcloud_ssl_download_certificate_operation
924930
925931
Secrets Manager(SSM)
926932
Data Source
@@ -3334,6 +3340,12 @@ func Provider() *schema.Provider {
33343340
"tencentcloud_cfw_nat_firewall_switch": resourceTencentCloudCfwNatFirewallSwitch(),
33353341
"tencentcloud_cfw_vpc_firewall_switch": resourceTencentCloudCfwVpcFirewallSwitch(),
33363342
"tencentcloud_cfw_edge_firewall_switch": resourceTencentCloudCfwEdgeFirewallSwitch(),
3343+
"tencentcloud_ssl_check_certificate_chain_operation": resourceTencentCloudSslCheckCertificateChainOperation(),
3344+
"tencentcloud_ssl_complete_certificate_operation": resourceTencentCloudSslCompleteCertificateOperation(),
3345+
"tencentcloud_ssl_deploy_certificate_instance_operation": resourceTencentCloudSslDeployCertificateInstanceOperation(),
3346+
"tencentcloud_ssl_deploy_certificate_record_retry_operation": resourceTencentCloudSslDeployCertificateRecordRetryOperation(),
3347+
"tencentcloud_ssl_deploy_certificate_record_rollback_operation": resourceTencentCloudSslDeployCertificateRecordRollbackOperation(),
3348+
"tencentcloud_ssl_download_certificate_operation": resourceTencentCloudSslDownloadCertificateOperation(),
33373349
"tencentcloud_cwp_license_order": resourceTencentCloudCwpLicenseOrder(),
33383350
"tencentcloud_cwp_license_bind_attachment": resourceTencentCloudCwpLicenseBindAttachment(),
33393351
},
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
Provides a resource to create a ssl check_certificate_chain
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_ssl_check_certificate_chain_operation" "check_certificate_chain" {
8+
certificate_chain = "-----BEGIN CERTIFICATE--·····---END CERTIFICATE-----"
9+
}
10+
```
11+
12+
Import
13+
14+
ssl check_certificate_chain can be imported using the id, e.g.
15+
16+
```
17+
terraform import tencentcloud_ssl_check_certificate_chain_operation.check_certificate_chain check_certificate_chain_id
18+
```
19+
*/
20+
package tencentcloud
21+
22+
import (
23+
"fmt"
24+
"log"
25+
26+
"github.com/hashicorp/go-uuid"
27+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
28+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
29+
ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
30+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
31+
)
32+
33+
func resourceTencentCloudSslCheckCertificateChainOperation() *schema.Resource {
34+
return &schema.Resource{
35+
Create: resourceTencentCloudSslCheckCertificateChainCreate,
36+
Read: resourceTencentCloudSslCheckCertificateChainRead,
37+
Delete: resourceTencentCloudSslCheckCertificateChainDelete,
38+
Importer: &schema.ResourceImporter{
39+
State: schema.ImportStatePassthrough,
40+
},
41+
Schema: map[string]*schema.Schema{
42+
"certificate_chain": {
43+
Required: true,
44+
ForceNew: true,
45+
Type: schema.TypeString,
46+
Description: "The certificate chain to check.",
47+
},
48+
},
49+
}
50+
}
51+
52+
func resourceTencentCloudSslCheckCertificateChainCreate(d *schema.ResourceData, meta interface{}) error {
53+
defer logElapsed("resource.tencentcloud_ssl_check_certificate_chain_operation.create")()
54+
defer inconsistentCheck(d, meta)()
55+
56+
logId := getLogId(contextNil)
57+
58+
var (
59+
request = ssl.NewCheckCertificateChainRequest()
60+
)
61+
if v, ok := d.GetOk("certificate_chain"); ok {
62+
request.CertificateChain = helper.String(v.(string))
63+
}
64+
65+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
66+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseSSLCertificateClient().CheckCertificateChain(request)
67+
if e != nil {
68+
return retryError(e)
69+
}
70+
if result != nil && result.Response != nil && !*result.Response.IsValid {
71+
err := fmt.Errorf("[DEBUG]%s Certificate chain failed to check, IsValid [%v]\n", logId, *result.Response.IsValid)
72+
return retryError(err)
73+
}
74+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
75+
return nil
76+
})
77+
if err != nil {
78+
log.Printf("[CRITAL]%s operate ssl checkCertificateChain failed, reason:%+v", logId, err)
79+
return err
80+
}
81+
id, err := uuid.GenerateUUID()
82+
if err != nil {
83+
return err
84+
}
85+
d.SetId(id)
86+
return resourceTencentCloudSslCheckCertificateChainRead(d, meta)
87+
}
88+
89+
func resourceTencentCloudSslCheckCertificateChainRead(d *schema.ResourceData, meta interface{}) error {
90+
defer logElapsed("resource.tencentcloud_ssl_check_certificate_chain_operation.read")()
91+
defer inconsistentCheck(d, meta)()
92+
93+
return nil
94+
}
95+
96+
func resourceTencentCloudSslCheckCertificateChainDelete(d *schema.ResourceData, meta interface{}) error {
97+
defer logElapsed("resource.tencentcloud_ssl_check_certificate_chain_operation.delete")()
98+
defer inconsistentCheck(d, meta)()
99+
100+
return nil
101+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudSslCheckCertificateChainResource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheckCommon(t, ACCOUNT_TYPE_SSL)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccSslCheckCertificateChain,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ssl_check_certificate_chain_operation.check_certificate_chain", "id"),
20+
resource.TestCheckResourceAttrSet("tencentcloud_ssl_check_certificate_chain_operation.check_certificate_chain", "certificate_chain"),
21+
),
22+
},
23+
},
24+
})
25+
}
26+
27+
const testAccSslCheckCertificateChain = `
28+
29+
resource "tencentcloud_ssl_check_certificate_chain_operation" "check_certificate_chain" {
30+
certificate_chain = <<EOT
31+
-----BEGIN CERTIFICATE-----
32+
MIIGgjCCBOqgAwIBAgIQD2LBHbHYKhfZEhJYSdrsXTANBgkqhkiG9w0BAQwFADBZ
33+
MQswCQYDVQQGEwJDTjElMCMGA1UEChMcVHJ1c3RBc2lhIFRlY2hub2xvZ2llcywg
34+
SW5jLjEjMCEGA1UEAxMaVHJ1c3RBc2lhIFJTQSBEViBUTFMgQ0EgRzIwHhcNMjMw
35+
NzMxMDAwMDAwWhcNMjQwNzMwMjM1OTU5WjAeMRww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YDVR0jBBgwFoAUoBEKIz6W8Qfs4q8p74Klf9AwpLQwHQYDVR0OBBYE
86+
FF86fBEQfgxncWHci6O1AANn9VccMA4GA1UdDwEB/wQEAwIBhjASBgNVHRMBAf8E
87+
CDAGAQH/AgEAMB0GA1UdJQQWMBQGCCsGAQUFBwMBBggrBgEFBQcDAjAiBgNVHSAE
88+
GzAZMA0GCysGAQQBsjEBAgIxMAgGBmeBDAECATBDBgNVHR8EPDA6MDigNqA0hjJo
89+
dHRwOi8vY3JsLmNvbW9kb2NhLmNvbS9BQUFDZXJ0aWZpY2F0ZVNlcnZpY2VzLmNy
90+
bDA0BggrBgEFBQcBAQQoMCYwJAYIKwYBBQUHMAGGGGh0dHA6Ly9vY3NwLmNvbW9k
91+
b2NhLmNvbTANBgkqhkiG9w0BAQsFAAOCAQEAHMUom5cxIje2IiFU7mOCsBr2F6CY
92+
eU5cyfQ/Aep9kAXYUDuWsaT85721JxeXFYkf4D/cgNd9+hxT8ZeDOJrn+ysqR7NO
93+
2K9AdqTdIY2uZPKmvgHOkvH2gQD6jc05eSPOwdY/10IPvmpgUKaGOa/tyygL8Og4
94+
3tYyoHipMMnS4OiYKakDJny0XVuchIP7ZMKiP07Q3FIuSS4omzR77kmc75/6Q9dP
95+
v4wa90UCOn1j6r7WhMmX3eT3Gsdj3WMe9bYD0AFuqa6MDyjIeXq08mVGraXiw73s
96+
Zale8OMckn/BU3O/3aFNLHLfET2H2hT6Wb3nwxjpLIfXmSVcVd8A58XH0g==
97+
-----END CERTIFICATE-----
98+
EOT
99+
}
100+
101+
`
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
Provides a resource to create a ssl complete_certificate
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_ssl_complete_certificate_operation" "complete_certificate" {
8+
certificate_id = "9Bfe1IBR"
9+
}
10+
```
11+
12+
Import
13+
14+
ssl complete_certificate can be imported using the id, e.g.
15+
16+
```
17+
terraform import tencentcloud_ssl_complete_certificate_operation.complete_certificate complete_certificate_id
18+
```
19+
*/
20+
package tencentcloud
21+
22+
import (
23+
"log"
24+
25+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
26+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
27+
ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
28+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
29+
)
30+
31+
func resourceTencentCloudSslCompleteCertificateOperation() *schema.Resource {
32+
return &schema.Resource{
33+
Create: resourceTencentCloudSslCompleteCertificateCreate,
34+
Read: resourceTencentCloudSslCompleteCertificateRead,
35+
Delete: resourceTencentCloudSslCompleteCertificateDelete,
36+
Importer: &schema.ResourceImporter{
37+
State: schema.ImportStatePassthrough,
38+
},
39+
Schema: map[string]*schema.Schema{
40+
"certificate_id": {
41+
Required: true,
42+
ForceNew: true,
43+
Type: schema.TypeString,
44+
Description: "Certificate ID.",
45+
},
46+
},
47+
}
48+
}
49+
50+
func resourceTencentCloudSslCompleteCertificateCreate(d *schema.ResourceData, meta interface{}) error {
51+
defer logElapsed("resource.tencentcloud_ssl_complete_certificate_operation.create")()
52+
defer inconsistentCheck(d, meta)()
53+
54+
logId := getLogId(contextNil)
55+
56+
var (
57+
request = ssl.NewCompleteCertificateRequest()
58+
response = ssl.NewCompleteCertificateResponse()
59+
certificateId string
60+
)
61+
if v, ok := d.GetOk("certificate_id"); ok {
62+
request.CertificateId = helper.String(v.(string))
63+
}
64+
65+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
66+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseSSLCertificateClient().CompleteCertificate(request)
67+
if e != nil {
68+
return retryError(e)
69+
} else {
70+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
71+
}
72+
response = result
73+
return nil
74+
})
75+
if err != nil {
76+
log.Printf("[CRITAL]%s operate ssl completeCertificate failed, reason:%+v", logId, err)
77+
return err
78+
}
79+
if response != nil && response.Response != nil && response.Response.CertificateId != nil {
80+
certificateId = *response.Response.CertificateId
81+
}
82+
d.SetId(certificateId)
83+
84+
return resourceTencentCloudSslCompleteCertificateRead(d, meta)
85+
}
86+
87+
func resourceTencentCloudSslCompleteCertificateRead(d *schema.ResourceData, meta interface{}) error {
88+
defer logElapsed("resource.tencentcloud_ssl_complete_certificate_operation.read")()
89+
defer inconsistentCheck(d, meta)()
90+
91+
return nil
92+
}
93+
94+
func resourceTencentCloudSslCompleteCertificateDelete(d *schema.ResourceData, meta interface{}) error {
95+
defer logElapsed("resource.tencentcloud_ssl_complete_certificate_operation.delete")()
96+
defer inconsistentCheck(d, meta)()
97+
98+
return nil
99+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudSslCompleteCertificateResource_basic(t *testing.T) {
10+
t.Parallel()
11+
resource.Test(t, resource.TestCase{
12+
PreCheck: func() {
13+
testAccPreCheckCommon(t, ACCOUNT_TYPE_SSL)
14+
},
15+
Providers: testAccProviders,
16+
Steps: []resource.TestStep{
17+
{
18+
Config: testAccSslCompleteCertificate,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ssl_complete_certificate_operation.complete_certificate", "id"),
20+
resource.TestCheckResourceAttr("tencentcloud_ssl_complete_certificate_operation.complete_certificate", "certificate_id", "709ahm2q"),
21+
),
22+
},
23+
},
24+
})
25+
}
26+
27+
const testAccSslCompleteCertificate = `
28+
29+
resource "tencentcloud_ssl_complete_certificate_operation" "complete_certificate" {
30+
certificate_id = "709ahm2q"
31+
}
32+
33+
`

0 commit comments

Comments
 (0)