-
Notifications
You must be signed in to change notification settings - Fork 144
feat: ssl-operation-2 #2175
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
feat: ssl-operation-2 #2175
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
```release-note:new-resource | ||
tencentcloud_ssl_replace_certificate_operation | ||
``` | ||
|
||
```release-note:new-resource | ||
tencentcloud_ssl_revoke_certificate_operation | ||
``` | ||
|
||
```release-note:new-resource | ||
tencentcloud_ssl_update_certificate_instance_operation | ||
``` | ||
|
||
```release-note:new-resource | ||
tencentcloud_ssl_update_certificate_record_retry_operation | ||
``` | ||
|
||
```release-note:new-resource | ||
tencentcloud_ssl_update_certificate_record_rollback_operation | ||
``` | ||
|
||
```release-note:new-resource | ||
tencentcloud_ssl_upload_revoke_letter_operation | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 179 additions & 0 deletions
179
tencentcloud/resource_tc_ssl_replace_certificate_operation.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
/* | ||
Provides a resource to create a ssl replace_certificate | ||
|
||
Example Usage | ||
|
||
```hcl | ||
resource "tencentcloud_ssl_replace_certificate_operation" "replace_certificate" { | ||
certificate_id = "8L6JsWq2" | ||
valid_type = "DNS_AUTO" | ||
csr_type = "online" | ||
} | ||
``` | ||
|
||
Import | ||
|
||
ssl replace_certificate can be imported using the id, e.g. | ||
|
||
``` | ||
terraform import tencentcloud_ssl_replace_certificate_operation.replace_certificate replace_certificate_id | ||
``` | ||
*/ | ||
package tencentcloud | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205" | ||
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" | ||
) | ||
|
||
func resourceTencentCloudSslReplaceCertificateOperation() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceTencentCloudSslReplaceCertificateCreate, | ||
Read: resourceTencentCloudSslReplaceCertificateRead, | ||
Delete: resourceTencentCloudSslReplaceCertificateDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"certificate_id": { | ||
Required: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
Description: "Certificate ID.", | ||
}, | ||
|
||
"valid_type": { | ||
Required: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
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.", | ||
}, | ||
|
||
"csr_type": { | ||
Optional: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
Description: "Type, default Original. Available options: Original = original certificate CSR, Upload = manual upload, Online = online generation.", | ||
}, | ||
|
||
"csr_content": { | ||
Optional: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
Description: "CSR Content.", | ||
}, | ||
|
||
"csr_key_password": { | ||
Optional: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
Description: "KEY Password.", | ||
}, | ||
|
||
"reason": { | ||
Optional: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
Description: "Reason for reissue.", | ||
}, | ||
|
||
"cert_csr_encrypt_algo": { | ||
Optional: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
Description: "CSR encryption method, optional: RSA, ECC, SM2. (Selectable only if CsrType is Online), default is RSA.", | ||
}, | ||
|
||
"cert_csr_key_parameter": { | ||
Optional: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
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;.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceTencentCloudSslReplaceCertificateCreate(d *schema.ResourceData, meta interface{}) error { | ||
defer logElapsed("resource.tencentcloud_ssl_replace_certificate_operation.create")() | ||
defer inconsistentCheck(d, meta)() | ||
|
||
logId := getLogId(contextNil) | ||
|
||
var ( | ||
request = ssl.NewReplaceCertificateRequest() | ||
response = ssl.NewReplaceCertificateResponse() | ||
certificateId uint64 | ||
) | ||
if v, ok := d.GetOk("certificate_id"); ok { | ||
request.CertificateId = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("valid_type"); ok { | ||
request.ValidType = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("csr_type"); ok { | ||
request.CsrType = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("csr_content"); ok { | ||
request.CsrContent = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("csr_key_password"); ok { | ||
request.CsrkeyPassword = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("reason"); ok { | ||
request.Reason = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("cert_csr_encrypt_algo"); ok { | ||
request.CertCSREncryptAlgo = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("cert_csr_key_parameter"); ok { | ||
request.CertCSRKeyParameter = helper.String(v.(string)) | ||
} | ||
|
||
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { | ||
result, e := meta.(*TencentCloudClient).apiV3Conn.UseSSLCertificateClient().ReplaceCertificate(request) | ||
if e != nil { | ||
return retryError(e) | ||
} else { | ||
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) | ||
} | ||
response = result | ||
return nil | ||
}) | ||
if err != nil { | ||
log.Printf("[CRITAL]%s operate ssl replaceCertificate failed, reason:%+v", logId, err) | ||
return err | ||
} | ||
if response != nil && response.Response != nil && response.Response.CertificateId != nil { | ||
certificateId = helper.StrToUInt64(*response.Response.CertificateId) | ||
} | ||
|
||
d.SetId(helper.UInt64ToStr(certificateId)) | ||
|
||
return resourceTencentCloudSslReplaceCertificateRead(d, meta) | ||
} | ||
|
||
func resourceTencentCloudSslReplaceCertificateRead(d *schema.ResourceData, meta interface{}) error { | ||
defer logElapsed("resource.tencentcloud_ssl_replace_certificate_operation.read")() | ||
defer inconsistentCheck(d, meta)() | ||
|
||
return nil | ||
} | ||
|
||
func resourceTencentCloudSslReplaceCertificateDelete(d *schema.ResourceData, meta interface{}) error { | ||
defer logElapsed("resource.tencentcloud_ssl_replace_certificate_operation.delete")() | ||
defer inconsistentCheck(d, meta)() | ||
|
||
return nil | ||
} |
37 changes: 37 additions & 0 deletions
37
tencentcloud/resource_tc_ssl_replace_certificate_operation_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package tencentcloud | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccTencentCloudSslReplaceCertificateResource_basic(t *testing.T) { | ||
t.Parallel() | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { | ||
testAccPreCheckCommon(t, ACCOUNT_TYPE_SSL) | ||
}, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccSslReplaceCertificate, | ||
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ssl_replace_certificate_operation.replace_certificate", "id"), | ||
resource.TestCheckResourceAttr("tencentcloud_ssl_replace_certificate_operation.replace_certificate", "certificate_id", "8hUkH3xC"), | ||
resource.TestCheckResourceAttr("tencentcloud_ssl_replace_certificate_operation.replace_certificate", "valid_type", "DNS_AUTO"), | ||
resource.TestCheckResourceAttr("tencentcloud_ssl_replace_certificate_operation.replace_certificate", "csr_type", "online"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccSslReplaceCertificate = ` | ||
|
||
resource "tencentcloud_ssl_replace_certificate_operation" "replace_certificate" { | ||
certificate_id = "8hUkH3xC" | ||
valid_type = "DNS_AUTO" | ||
csr_type = "online" | ||
} | ||
|
||
` |
113 changes: 113 additions & 0 deletions
113
tencentcloud/resource_tc_ssl_revoke_certificate_operation.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
Provides a resource to create a ssl revoke_certificate | ||
|
||
Example Usage | ||
|
||
```hcl | ||
resource "tencentcloud_ssl_revoke_certificate_operation" "revoke_certificate" { | ||
certificate_id = "7zUGkVab" | ||
} | ||
``` | ||
|
||
Import | ||
|
||
ssl revoke_certificate can be imported using the id, e.g. | ||
|
||
``` | ||
terraform import tencentcloud_ssl_revoke_certificate_operation.revoke_certificate revoke_certificate_id | ||
``` | ||
*/ | ||
package tencentcloud | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
sdkErrors "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" | ||
ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205" | ||
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" | ||
) | ||
|
||
func resourceTencentCloudSslRevokeCertificateOperation() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceTencentCloudSslRevokeCertificateCreate, | ||
Read: resourceTencentCloudSslRevokeCertificateRead, | ||
Delete: resourceTencentCloudSslRevokeCertificateDelete, | ||
Importer: &schema.ResourceImporter{ | ||
State: schema.ImportStatePassthrough, | ||
}, | ||
Schema: map[string]*schema.Schema{ | ||
"certificate_id": { | ||
Required: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
Description: "Certificate ID.", | ||
}, | ||
|
||
"reason": { | ||
Optional: true, | ||
ForceNew: true, | ||
Type: schema.TypeString, | ||
Description: "Reasons for revoking certificate.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceTencentCloudSslRevokeCertificateCreate(d *schema.ResourceData, meta interface{}) error { | ||
defer logElapsed("resource.tencentcloud_ssl_revoke_certificate_operation.create")() | ||
defer inconsistentCheck(d, meta)() | ||
|
||
logId := getLogId(contextNil) | ||
|
||
var ( | ||
request = ssl.NewRevokeCertificateRequest() | ||
certificateId string | ||
) | ||
if v, ok := d.GetOk("certificate_id"); ok { | ||
certificateId = v.(string) | ||
request.CertificateId = helper.String(v.(string)) | ||
} | ||
|
||
if v, ok := d.GetOk("reason"); ok { | ||
request.Reason = helper.String(v.(string)) | ||
} | ||
|
||
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { | ||
result, e := meta.(*TencentCloudClient).apiV3Conn.UseSSLCertificateClient().RevokeCertificate(request) | ||
if e != nil { | ||
if sdkerr, ok := e.(*sdkErrors.TencentCloudSDKError); ok { | ||
if sdkerr.Code == "FailedOperation.OrderAlreadyReplaced" { | ||
return nil | ||
} | ||
} | ||
return retryError(e) | ||
} else { | ||
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) | ||
} | ||
return nil | ||
}) | ||
if err != nil { | ||
log.Printf("[CRITAL]%s operate ssl revokeCertificate failed, reason:%+v", logId, err) | ||
return err | ||
} | ||
|
||
d.SetId(certificateId) | ||
|
||
return resourceTencentCloudSslRevokeCertificateRead(d, meta) | ||
} | ||
|
||
func resourceTencentCloudSslRevokeCertificateRead(d *schema.ResourceData, meta interface{}) error { | ||
defer logElapsed("resource.tencentcloud_ssl_revoke_certificate_operation.read")() | ||
defer inconsistentCheck(d, meta)() | ||
|
||
return nil | ||
} | ||
|
||
func resourceTencentCloudSslRevokeCertificateDelete(d *schema.ResourceData, meta interface{}) error { | ||
defer logElapsed("resource.tencentcloud_ssl_revoke_certificate_operation.delete")() | ||
defer inconsistentCheck(d, meta)() | ||
|
||
return nil | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个参数为啥是ForceNew呢
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没有update的,入参必须都是forceNew