Skip to content

Commit ef47b6e

Browse files
WeiMengXSWeiMengXS
andauthored
feat: ssl-operation-2 (#2175)
* feat: changelog * feat: changelog * feat: e2e --------- Co-authored-by: WeiMengXS <nickcchen@tencent.com>
1 parent d90d408 commit ef47b6e

21 files changed

+1336
-0
lines changed

.changelog/2175.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_replace_certificate_operation
3+
```
4+
5+
```release-note:new-resource
6+
tencentcloud_ssl_revoke_certificate_operation
7+
```
8+
9+
```release-note:new-resource
10+
tencentcloud_ssl_update_certificate_instance_operation
11+
```
12+
13+
```release-note:new-resource
14+
tencentcloud_ssl_update_certificate_record_retry_operation
15+
```
16+
17+
```release-note:new-resource
18+
tencentcloud_ssl_update_certificate_record_rollback_operation
19+
```
20+
21+
```release-note:new-resource
22+
tencentcloud_ssl_upload_revoke_letter_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_replace_certificate_operation
925+
tencentcloud_ssl_revoke_certificate_operation
926+
tencentcloud_ssl_update_certificate_instance_operation
927+
tencentcloud_ssl_update_certificate_record_retry_operation
928+
tencentcloud_ssl_update_certificate_record_rollback_operation
929+
tencentcloud_ssl_upload_revoke_letter_operation
924930
tencentcloud_ssl_complete_certificate_operation
925931
tencentcloud_ssl_check_certificate_chain_operation
926932
tencentcloud_ssl_deploy_certificate_instance_operation
@@ -3358,6 +3364,12 @@ func Provider() *schema.Provider {
33583364
"tencentcloud_ssl_download_certificate_operation": resourceTencentCloudSslDownloadCertificateOperation(),
33593365
"tencentcloud_cwp_license_order": resourceTencentCloudCwpLicenseOrder(),
33603366
"tencentcloud_cwp_license_bind_attachment": resourceTencentCloudCwpLicenseBindAttachment(),
3367+
"tencentcloud_ssl_replace_certificate_operation": resourceTencentCloudSslReplaceCertificateOperation(),
3368+
"tencentcloud_ssl_revoke_certificate_operation": resourceTencentCloudSslRevokeCertificateOperation(),
3369+
"tencentcloud_ssl_update_certificate_instance_operation": resourceTencentCloudSslUpdateCertificateInstanceOperation(),
3370+
"tencentcloud_ssl_update_certificate_record_retry_operation": resourceTencentCloudSslUpdateCertificateRecordRetryOperation(),
3371+
"tencentcloud_ssl_update_certificate_record_rollback_operation": resourceTencentCloudSslUpdateCertificateRecordRollbackOperation(),
3372+
"tencentcloud_ssl_upload_revoke_letter_operation": resourceTencentCloudSslUploadRevokeLetterOperation(),
33613373
},
33623374

33633375
ConfigureFunc: providerConfigure,
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
/*
2+
Provides a resource to create a ssl replace_certificate
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_ssl_replace_certificate_operation" "replace_certificate" {
8+
certificate_id = "8L6JsWq2"
9+
valid_type = "DNS_AUTO"
10+
csr_type = "online"
11+
}
12+
```
13+
14+
Import
15+
16+
ssl replace_certificate can be imported using the id, e.g.
17+
18+
```
19+
terraform import tencentcloud_ssl_replace_certificate_operation.replace_certificate replace_certificate_id
20+
```
21+
*/
22+
package tencentcloud
23+
24+
import (
25+
"log"
26+
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 resourceTencentCloudSslReplaceCertificateOperation() *schema.Resource {
34+
return &schema.Resource{
35+
Create: resourceTencentCloudSslReplaceCertificateCreate,
36+
Read: resourceTencentCloudSslReplaceCertificateRead,
37+
Delete: resourceTencentCloudSslReplaceCertificateDelete,
38+
Importer: &schema.ResourceImporter{
39+
State: schema.ImportStatePassthrough,
40+
},
41+
Schema: map[string]*schema.Schema{
42+
"certificate_id": {
43+
Required: true,
44+
ForceNew: true,
45+
Type: schema.TypeString,
46+
Description: "Certificate ID.",
47+
},
48+
49+
"valid_type": {
50+
Required: true,
51+
ForceNew: true,
52+
Type: schema.TypeString,
53+
Description: "Verification type: DNS_AUTO = automatic DNS verification (this verification type is only supported for domain names that are resolved by Tencent Cloud and have normal resolution status), DNS = manual DNS verification, FILE = file verification.",
54+
},
55+
56+
"csr_type": {
57+
Optional: true,
58+
ForceNew: true,
59+
Type: schema.TypeString,
60+
Description: "Type, default Original. Available options: Original = original certificate CSR, Upload = manual upload, Online = online generation.",
61+
},
62+
63+
"csr_content": {
64+
Optional: true,
65+
ForceNew: true,
66+
Type: schema.TypeString,
67+
Description: "CSR Content.",
68+
},
69+
70+
"csr_key_password": {
71+
Optional: true,
72+
ForceNew: true,
73+
Type: schema.TypeString,
74+
Description: "KEY Password.",
75+
},
76+
77+
"reason": {
78+
Optional: true,
79+
ForceNew: true,
80+
Type: schema.TypeString,
81+
Description: "Reason for reissue.",
82+
},
83+
84+
"cert_csr_encrypt_algo": {
85+
Optional: true,
86+
ForceNew: true,
87+
Type: schema.TypeString,
88+
Description: "CSR encryption method, optional: RSA, ECC, SM2. (Selectable only if CsrType is Online), default is RSA.",
89+
},
90+
91+
"cert_csr_key_parameter": {
92+
Optional: true,
93+
ForceNew: true,
94+
Type: schema.TypeString,
95+
Description: "CSR encryption parameter, when CsrEncryptAlgo is RSA, you can choose 2048, 4096, etc., and the default is 2048; when CsrEncryptAlgo is ECC, you can choose prime256v1, secp384r1, etc., and the default is prime256v1;.",
96+
},
97+
},
98+
}
99+
}
100+
101+
func resourceTencentCloudSslReplaceCertificateCreate(d *schema.ResourceData, meta interface{}) error {
102+
defer logElapsed("resource.tencentcloud_ssl_replace_certificate_operation.create")()
103+
defer inconsistentCheck(d, meta)()
104+
105+
logId := getLogId(contextNil)
106+
107+
var (
108+
request = ssl.NewReplaceCertificateRequest()
109+
response = ssl.NewReplaceCertificateResponse()
110+
certificateId uint64
111+
)
112+
if v, ok := d.GetOk("certificate_id"); ok {
113+
request.CertificateId = helper.String(v.(string))
114+
}
115+
116+
if v, ok := d.GetOk("valid_type"); ok {
117+
request.ValidType = helper.String(v.(string))
118+
}
119+
120+
if v, ok := d.GetOk("csr_type"); ok {
121+
request.CsrType = helper.String(v.(string))
122+
}
123+
124+
if v, ok := d.GetOk("csr_content"); ok {
125+
request.CsrContent = helper.String(v.(string))
126+
}
127+
128+
if v, ok := d.GetOk("csr_key_password"); ok {
129+
request.CsrkeyPassword = helper.String(v.(string))
130+
}
131+
132+
if v, ok := d.GetOk("reason"); ok {
133+
request.Reason = helper.String(v.(string))
134+
}
135+
136+
if v, ok := d.GetOk("cert_csr_encrypt_algo"); ok {
137+
request.CertCSREncryptAlgo = helper.String(v.(string))
138+
}
139+
140+
if v, ok := d.GetOk("cert_csr_key_parameter"); ok {
141+
request.CertCSRKeyParameter = helper.String(v.(string))
142+
}
143+
144+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
145+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseSSLCertificateClient().ReplaceCertificate(request)
146+
if e != nil {
147+
return retryError(e)
148+
} else {
149+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
150+
}
151+
response = result
152+
return nil
153+
})
154+
if err != nil {
155+
log.Printf("[CRITAL]%s operate ssl replaceCertificate failed, reason:%+v", logId, err)
156+
return err
157+
}
158+
if response != nil && response.Response != nil && response.Response.CertificateId != nil {
159+
certificateId = helper.StrToUInt64(*response.Response.CertificateId)
160+
}
161+
162+
d.SetId(helper.UInt64ToStr(certificateId))
163+
164+
return resourceTencentCloudSslReplaceCertificateRead(d, meta)
165+
}
166+
167+
func resourceTencentCloudSslReplaceCertificateRead(d *schema.ResourceData, meta interface{}) error {
168+
defer logElapsed("resource.tencentcloud_ssl_replace_certificate_operation.read")()
169+
defer inconsistentCheck(d, meta)()
170+
171+
return nil
172+
}
173+
174+
func resourceTencentCloudSslReplaceCertificateDelete(d *schema.ResourceData, meta interface{}) error {
175+
defer logElapsed("resource.tencentcloud_ssl_replace_certificate_operation.delete")()
176+
defer inconsistentCheck(d, meta)()
177+
178+
return nil
179+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package tencentcloud
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
)
8+
9+
func TestAccTencentCloudSslReplaceCertificateResource_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: testAccSslReplaceCertificate,
19+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ssl_replace_certificate_operation.replace_certificate", "id"),
20+
resource.TestCheckResourceAttr("tencentcloud_ssl_replace_certificate_operation.replace_certificate", "certificate_id", "8hUkH3xC"),
21+
resource.TestCheckResourceAttr("tencentcloud_ssl_replace_certificate_operation.replace_certificate", "valid_type", "DNS_AUTO"),
22+
resource.TestCheckResourceAttr("tencentcloud_ssl_replace_certificate_operation.replace_certificate", "csr_type", "online"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
const testAccSslReplaceCertificate = `
30+
31+
resource "tencentcloud_ssl_replace_certificate_operation" "replace_certificate" {
32+
certificate_id = "8hUkH3xC"
33+
valid_type = "DNS_AUTO"
34+
csr_type = "online"
35+
}
36+
37+
`
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
Provides a resource to create a ssl revoke_certificate
3+
4+
Example Usage
5+
6+
```hcl
7+
resource "tencentcloud_ssl_revoke_certificate_operation" "revoke_certificate" {
8+
certificate_id = "7zUGkVab"
9+
}
10+
```
11+
12+
Import
13+
14+
ssl revoke_certificate can be imported using the id, e.g.
15+
16+
```
17+
terraform import tencentcloud_ssl_revoke_certificate_operation.revoke_certificate revoke_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+
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
28+
ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205"
29+
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
30+
)
31+
32+
func resourceTencentCloudSslRevokeCertificateOperation() *schema.Resource {
33+
return &schema.Resource{
34+
Create: resourceTencentCloudSslRevokeCertificateCreate,
35+
Read: resourceTencentCloudSslRevokeCertificateRead,
36+
Delete: resourceTencentCloudSslRevokeCertificateDelete,
37+
Importer: &schema.ResourceImporter{
38+
State: schema.ImportStatePassthrough,
39+
},
40+
Schema: map[string]*schema.Schema{
41+
"certificate_id": {
42+
Required: true,
43+
ForceNew: true,
44+
Type: schema.TypeString,
45+
Description: "Certificate ID.",
46+
},
47+
48+
"reason": {
49+
Optional: true,
50+
ForceNew: true,
51+
Type: schema.TypeString,
52+
Description: "Reasons for revoking certificate.",
53+
},
54+
},
55+
}
56+
}
57+
58+
func resourceTencentCloudSslRevokeCertificateCreate(d *schema.ResourceData, meta interface{}) error {
59+
defer logElapsed("resource.tencentcloud_ssl_revoke_certificate_operation.create")()
60+
defer inconsistentCheck(d, meta)()
61+
62+
logId := getLogId(contextNil)
63+
64+
var (
65+
request = ssl.NewRevokeCertificateRequest()
66+
certificateId string
67+
)
68+
if v, ok := d.GetOk("certificate_id"); ok {
69+
certificateId = v.(string)
70+
request.CertificateId = helper.String(v.(string))
71+
}
72+
73+
if v, ok := d.GetOk("reason"); ok {
74+
request.Reason = helper.String(v.(string))
75+
}
76+
77+
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
78+
result, e := meta.(*TencentCloudClient).apiV3Conn.UseSSLCertificateClient().RevokeCertificate(request)
79+
if e != nil {
80+
if sdkerr, ok := e.(*sdkErrors.TencentCloudSDKError); ok {
81+
if sdkerr.Code == "FailedOperation.OrderAlreadyReplaced" {
82+
return nil
83+
}
84+
}
85+
return retryError(e)
86+
} else {
87+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
88+
}
89+
return nil
90+
})
91+
if err != nil {
92+
log.Printf("[CRITAL]%s operate ssl revokeCertificate failed, reason:%+v", logId, err)
93+
return err
94+
}
95+
96+
d.SetId(certificateId)
97+
98+
return resourceTencentCloudSslRevokeCertificateRead(d, meta)
99+
}
100+
101+
func resourceTencentCloudSslRevokeCertificateRead(d *schema.ResourceData, meta interface{}) error {
102+
defer logElapsed("resource.tencentcloud_ssl_revoke_certificate_operation.read")()
103+
defer inconsistentCheck(d, meta)()
104+
105+
return nil
106+
}
107+
108+
func resourceTencentCloudSslRevokeCertificateDelete(d *schema.ResourceData, meta interface{}) error {
109+
defer logElapsed("resource.tencentcloud_ssl_revoke_certificate_operation.delete")()
110+
defer inconsistentCheck(d, meta)()
111+
112+
return nil
113+
}

0 commit comments

Comments
 (0)