|
| 1 | +/* |
| 2 | +Provides a resource to create a ssl commit_certificate_information |
| 3 | +
|
| 4 | +Example Usage |
| 5 | +
|
| 6 | +```hcl |
| 7 | +resource "tencentcloud_ssl_pay_certificate" "example" { |
| 8 | + product_id = 33 |
| 9 | + domain_num = 1 |
| 10 | + alias = "example-ssl-update" |
| 11 | + project_id = 0 |
| 12 | + wait_commit_flag = true |
| 13 | + information { |
| 14 | + csr_type = "online" |
| 15 | + certificate_domain = "www.domain.com" |
| 16 | + organization_name = "test-update" |
| 17 | + organization_division = "test" |
| 18 | + organization_address = "test" |
| 19 | + organization_country = "CN" |
| 20 | + organization_city = "test" |
| 21 | + organization_region = "test" |
| 22 | + postal_code = "0755" |
| 23 | + phone_area_code = "0755" |
| 24 | + phone_number = "12345678901" |
| 25 | + verify_type = "DNS" |
| 26 | + admin_first_name = "test" |
| 27 | + admin_last_name = "test" |
| 28 | + admin_phone_num = "12345678901" |
| 29 | + admin_email = "test@tencent.com" |
| 30 | + admin_position = "dev" |
| 31 | + contact_first_name = "test" |
| 32 | + contact_last_name = "test" |
| 33 | + contact_email = "test@tencent.com" |
| 34 | + contact_number = "12345678901" |
| 35 | + contact_position = "dev" |
| 36 | + } |
| 37 | +} |
| 38 | +resource "tencentcloud_ssl_commit_certificate_information" "example" { |
| 39 | + product_id = 33 |
| 40 | + certificate_id = tencentcloud_ssl_pay_certificate.example.certificate_id |
| 41 | +} |
| 42 | +``` |
| 43 | +
|
| 44 | +*/ |
| 45 | +package tencentcloud |
| 46 | + |
| 47 | +import ( |
| 48 | + "context" |
| 49 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 50 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 51 | + "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" |
| 52 | + ssl "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssl/v20191205" |
| 53 | + "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper" |
| 54 | + "log" |
| 55 | +) |
| 56 | + |
| 57 | +func resourceTencentCloudSslCommitCertificateInformation() *schema.Resource { |
| 58 | + return &schema.Resource{ |
| 59 | + Create: resourceTencentCloudSslCommitCertificateInformationCreate, |
| 60 | + Read: resourceTencentCloudSslCommitCertificateInformationRead, |
| 61 | + Delete: resourceTencentCloudSslCommitCertificateInformationDelete, |
| 62 | + Schema: map[string]*schema.Schema{ |
| 63 | + "product_id": { |
| 64 | + Type: schema.TypeInt, |
| 65 | + Required: true, |
| 66 | + ForceNew: true, |
| 67 | + ValidateFunc: validateIntegerInRange(3, 56), |
| 68 | + Description: "Certificate commodity ID. Valid value ranges: (3~42). `3` means SecureSite enhanced Enterprise Edition (EV Pro), " + |
| 69 | + "`4` means SecureSite enhanced (EV), `5` means SecureSite Enterprise Professional Edition (OV Pro), " + |
| 70 | + "`6` means SecureSite Enterprise (OV), `7` means SecureSite Enterprise Type (OV) wildcard, " + |
| 71 | + "`8` means Geotrust enhanced (EV), `9` means Geotrust enterprise (OV), " + |
| 72 | + "`10` means Geotrust enterprise (OV) wildcard, `11` means TrustAsia domain type multi-domain SSL certificate, " + |
| 73 | + "`12` means TrustAsia domain type ( DV) wildcard, `13` means TrustAsia enterprise wildcard (OV) SSL certificate (D3), " + |
| 74 | + "`14` means TrustAsia enterprise (OV) SSL certificate (D3), `15` means TrustAsia enterprise multi-domain (OV) SSL certificate (D3), " + |
| 75 | + "`16` means TrustAsia Enhanced (EV) SSL Certificate (D3), `17` means TrustAsia Enhanced Multiple Domain (EV) SSL Certificate (D3), " + |
| 76 | + "`18` means GlobalSign Enterprise (OV) SSL Certificate, `19` means GlobalSign Enterprise Wildcard (OV) SSL Certificate, " + |
| 77 | + "`20` means GlobalSign Enhanced (EV) SSL Certificate, `21` means TrustAsia Enterprise Wildcard Multiple Domain (OV) SSL Certificate (D3), " + |
| 78 | + "`22` means GlobalSign Enterprise Multiple Domain (OV) SSL Certificate, `23` means GlobalSign Enterprise Multiple Wildcard Domain name (OV) SSL certificate, " + |
| 79 | + "`24` means GlobalSign enhanced multi-domain (EV) SSL certificate, `25` means Wotrus domain type certificate, " + |
| 80 | + "`26` means Wotrus domain type multi-domain certificate, `27` means Wotrus domain type wildcard certificate, " + |
| 81 | + "`28` means Wotrus enterprise type certificate, `29` means Wotrus enterprise multi-domain certificate, " + |
| 82 | + "`30` means Wotrus enterprise wildcard certificate, `31` means Wotrus enhanced certificate, " + |
| 83 | + "`32` means Wotrus enhanced multi-domain certificate, `33` means WoTrus National Secret Domain name Certificate, " + |
| 84 | + "`34` means WoTrus National Secret Domain name Certificate (multiple domain names), `35` WoTrus National Secret Domain name Certificate (wildcard), " + |
| 85 | + "`37` means WoTrus State Secret Enterprise Certificate, `38` means WoTrus State Secret Enterprise Certificate (multiple domain names), " + |
| 86 | + "`39` means WoTrus State Secret Enterprise Certificate (wildcard), `40` means WoTrus National secret enhanced certificate, " + |
| 87 | + "`41` means WoTrus National Secret enhanced Certificate (multiple domain names), `42` means TrustAsia- Domain name Certificate (wildcard multiple domain names), " + |
| 88 | + "`43` means DNSPod Enterprise (OV) SSL Certificate, `44` means DNSPod- Enterprise (OV) wildcard SSL certificate, " + |
| 89 | + "`45` means DNSPod Enterprise (OV) Multi-domain name SSL Certificate, `46` means DNSPod enhanced (EV) SSL certificate, " + |
| 90 | + "`47` means DNSPod enhanced (EV) multi-domain name SSL certificate, `48` means DNSPod Domain name Type (DV) SSL Certificate, " + |
| 91 | + "`49` means DNSPod Domain name Type (DV) wildcard SSL certificate, `50` means DNSPod domain name type (DV) multi-domain name SSL certificate, " + |
| 92 | + "`51` means DNSPod (State Secret) Enterprise (OV) SSL certificate, `52` DNSPod (National Secret) Enterprise (OV) wildcard SSL certificate, " + |
| 93 | + "`53` means DNSPod (National Secret) Enterprise (OV) multi-domain SSL certificate, `54` means DNSPod (National Secret) Domain Name (DV) SSL certificate, " + |
| 94 | + "`55` means DNSPod (National Secret) Domain Name Type (DV) wildcard SSL certificate, `56` means DNSPod (National Secret) Domain Name Type (DV) multi-domain SSL certificate.", |
| 95 | + }, |
| 96 | + "certificate_id": { |
| 97 | + Required: true, |
| 98 | + ForceNew: true, |
| 99 | + Type: schema.TypeString, |
| 100 | + Description: "Certificate Id.", |
| 101 | + }, |
| 102 | + |
| 103 | + "verify_type": { |
| 104 | + Optional: true, |
| 105 | + ForceNew: true, |
| 106 | + Type: schema.TypeString, |
| 107 | + Description: "Domain name verification method.", |
| 108 | + }, |
| 109 | + "confirm_letter": { |
| 110 | + Type: schema.TypeString, |
| 111 | + Optional: true, |
| 112 | + ForceNew: true, |
| 113 | + Description: "The base64-encoded certificate confirmation file should be in jpg, jpeg, png, pdf, and the size should be between 1kb and 1.4M. Note: it only works when product_id is set to 8, 9 or 10.", |
| 114 | + }, |
| 115 | + }, |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +func resourceTencentCloudSslCommitCertificateInformationCreate(d *schema.ResourceData, meta interface{}) error { |
| 120 | + defer logElapsed("resource.tencentcloud_ssl_commit_certificate_information.create")() |
| 121 | + defer inconsistentCheck(d, meta)() |
| 122 | + |
| 123 | + logId := getLogId(contextNil) |
| 124 | + ctx := context.WithValue(context.TODO(), logIdKey, logId) |
| 125 | + sslService := SSLService{client: meta.(*TencentCloudClient).apiV3Conn} |
| 126 | + |
| 127 | + var ( |
| 128 | + request = ssl.NewCommitCertificateInformationRequest() |
| 129 | + productId = int64(d.Get("product_id").(int)) |
| 130 | + certificateId string |
| 131 | + ) |
| 132 | + if v, ok := d.GetOk("certificate_id"); ok { |
| 133 | + certificateId = v.(string) |
| 134 | + request.CertificateId = helper.String(v.(string)) |
| 135 | + } |
| 136 | + |
| 137 | + if v, ok := d.GetOk("verify_type"); ok { |
| 138 | + request.VerifyType = helper.String(v.(string)) |
| 139 | + } |
| 140 | + |
| 141 | + err := resource.Retry(writeRetryTimeout, func() *resource.RetryError { |
| 142 | + result, e := meta.(*TencentCloudClient).apiV3Conn.UseSSLCertificateClient().CommitCertificateInformation(request) |
| 143 | + if e != nil { |
| 144 | + return retryError(e) |
| 145 | + } else { |
| 146 | + log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString()) |
| 147 | + } |
| 148 | + return nil |
| 149 | + }) |
| 150 | + if err != nil { |
| 151 | + log.Printf("[CRITAL]%s create ssl commitCertificateInformation failed, reason:%+v", logId, err) |
| 152 | + return err |
| 153 | + } |
| 154 | + |
| 155 | + if IsContainProductId(productId, GEOTRUST_OV_EV_TYPE) { |
| 156 | + confirmLetter := d.Get("confirm_letter").(string) |
| 157 | + uploadConfirmLetterRequest := ssl.NewUploadConfirmLetterRequest() |
| 158 | + uploadConfirmLetterRequest.CertificateId = helper.String(certificateId) |
| 159 | + uploadConfirmLetterRequest.ConfirmLetter = helper.String(confirmLetter) |
| 160 | + if err = resource.Retry(writeRetryTimeout, func() *resource.RetryError { |
| 161 | + if err = sslService.UploadConfirmLetter(ctx, uploadConfirmLetterRequest); err != nil { |
| 162 | + if sdkError, ok := err.(*errors.TencentCloudSDKError); ok { |
| 163 | + code := sdkError.GetCode() |
| 164 | + if code == InvalidParam || code == CertificateNotFound { |
| 165 | + return resource.NonRetryableError(sdkError) |
| 166 | + } |
| 167 | + } |
| 168 | + return retryError(err) |
| 169 | + } |
| 170 | + return nil |
| 171 | + }); err != nil { |
| 172 | + return err |
| 173 | + } |
| 174 | + } |
| 175 | + |
| 176 | + d.SetId(certificateId) |
| 177 | + |
| 178 | + return nil |
| 179 | +} |
| 180 | +func resourceTencentCloudSslCommitCertificateInformationRead(d *schema.ResourceData, meta interface{}) error { |
| 181 | + defer logElapsed("resource.tencentcloud_ssl_pay_certificate.read")() |
| 182 | + defer inconsistentCheck(d, meta)() |
| 183 | + return nil |
| 184 | +} |
| 185 | +func resourceTencentCloudSslCommitCertificateInformationDelete(d *schema.ResourceData, meta interface{}) error { |
| 186 | + defer logElapsed("resource.tencentcloud_ssl_commit_certificate_information.delete")() |
| 187 | + defer inconsistentCheck(d, meta)() |
| 188 | + |
| 189 | + return nil |
| 190 | +} |
0 commit comments