Skip to content

Commit 6037a88

Browse files
authored
Feat/ssl add param (#2421)
* feat: doc * feat: doc * feat: changelog * feat: changelog * feat: fix * feat: fix
1 parent a539d9f commit 6037a88

File tree

5 files changed

+136
-51
lines changed

5 files changed

+136
-51
lines changed

.changelog/2421.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
resource/tencentcloud_ssl_update_certificate_instance_operation: Support upload ca
3+
```

tencentcloud/resource_tc_ssl_update_certificate_instance_operation.go

Lines changed: 94 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ import (
1212

1313
func resourceTencentCloudSslUpdateCertificateInstanceOperation() *schema.Resource {
1414
return &schema.Resource{
15-
Create: resourceTencentCloudSslUpdateCertificateInstanceCreate,
16-
Read: resourceTencentCloudSslUpdateCertificateInstanceRead,
17-
Delete: resourceTencentCloudSslUpdateCertificateInstanceDelete,
15+
Create: resourceTencentCloudSslUpdateCertificateInstanceOperationCreate,
16+
Read: resourceTencentCloudSslUpdateCertificateInstanceOperationRead,
17+
Delete: resourceTencentCloudSslUpdateCertificateInstanceOperationDelete,
1818
Importer: &schema.ResourceImporter{
1919
State: schema.ImportStatePassthrough,
2020
},
2121
Schema: map[string]*schema.Schema{
2222
"certificate_id": {
23-
Required: true,
23+
Optional: true,
2424
ForceNew: true,
2525
Type: schema.TypeString,
2626
Description: "Update new certificate ID.",
@@ -40,14 +40,14 @@ func resourceTencentCloudSslUpdateCertificateInstanceOperation() *schema.Resourc
4040
Elem: &schema.Schema{
4141
Type: schema.TypeString,
4242
},
43-
Description: "The resource type that needs to be deployed. The parameter value is optional: clb,cdn,waf,live,ddos,teo,apigateway,vod,tke,tcb.",
43+
Description: "The resource type that needs to be deployed. The parameter value is optional: clb, cdn, waf, live, ddos, teo, apigateway, vod, tke, tcb.",
4444
},
4545

4646
"resource_types_regions": {
4747
Optional: true,
4848
ForceNew: true,
4949
Type: schema.TypeList,
50-
Description: "List of regions where cloud resources need to be deployed.",
50+
Description: "List of regions where cloud resources need to be deploye.",
5151
Elem: &schema.Resource{
5252
Schema: map[string]*schema.Schema{
5353
"resource_type": {
@@ -66,11 +66,55 @@ func resourceTencentCloudSslUpdateCertificateInstanceOperation() *schema.Resourc
6666
},
6767
},
6868
},
69+
70+
"certificate_public_key": {
71+
Optional: true,
72+
ForceNew: true,
73+
Sensitive: true,
74+
Type: schema.TypeString,
75+
Description: "Certificate public key. If you upload the certificate public key, CertificateId does not need to be passed.",
76+
},
77+
78+
"certificate_private_key": {
79+
Optional: true,
80+
ForceNew: true,
81+
Sensitive: true,
82+
Type: schema.TypeString,
83+
Description: "Certificate private key. If you upload the certificate public key, CertificateId does not need to be passed.",
84+
},
85+
86+
"expiring_notification_switch": {
87+
Optional: true,
88+
ForceNew: true,
89+
Type: schema.TypeInt,
90+
Description: "Whether to ignore expiration reminders for old certificates 0: Do not ignore notifications. 1: Ignore the notification and ignore the OldCertificateId expiration reminder.",
91+
},
92+
93+
"repeatable": {
94+
Optional: true,
95+
ForceNew: true,
96+
Type: schema.TypeBool,
97+
Description: "Whether the same certificate is allowed to be uploaded repeatedly. If you choose to upload the certificate, you can configure this parameter.",
98+
},
99+
100+
"allow_download": {
101+
Optional: true,
102+
ForceNew: true,
103+
Type: schema.TypeBool,
104+
Description: "Whether to allow downloading, if you choose to upload the certificate, you can configure this parameter.",
105+
},
106+
107+
"project_id": {
108+
Optional: true,
109+
ForceNew: true,
110+
Type: schema.TypeInt,
111+
Description: "Project ID, if you choose to upload the certificate, you can configure this parameter.",
112+
},
69113
},
70114
}
71115
}
72116

73-
func resourceTencentCloudSslUpdateCertificateInstanceCreate(d *schema.ResourceData, meta interface{}) error {
117+
func resourceTencentCloudSslUpdateCertificateInstanceOperationCreate(d *schema.ResourceData, meta interface{}) error {
74118
defer logElapsed("resource.tencentcloud_ssl_update_certificate_instance_operation.create")()
75119
defer inconsistentCheck(d, meta)()
76120

@@ -92,67 +136,93 @@ func resourceTencentCloudSslUpdateCertificateInstanceCreate(d *schema.ResourceDa
92136
if v, ok := d.GetOk("resource_types"); ok {
93137
resourceTypesSet := v.(*schema.Set).List()
94138
for i := range resourceTypesSet {
95-
resourceTypes := resourceTypesSet[i].(string)
96-
request.ResourceTypes = append(request.ResourceTypes, &resourceTypes)
139+
if resourceTypesSet[i] != nil {
140+
resourceTypes := resourceTypesSet[i].(string)
141+
request.ResourceTypes = append(request.ResourceTypes, &resourceTypes)
142+
}
97143
}
98144
}
99145

100146
if v, ok := d.GetOk("resource_types_regions"); ok {
101147
for _, item := range v.([]interface{}) {
102-
resourceTypeRegions := ssl.ResourceTypeRegions{}
103148
dMap := item.(map[string]interface{})
149+
resourceTypeRegions := ssl.ResourceTypeRegions{}
104150
if v, ok := dMap["resource_type"]; ok {
105151
resourceTypeRegions.ResourceType = helper.String(v.(string))
106152
}
107153
if v, ok := dMap["regions"]; ok {
108154
regionsSet := v.(*schema.Set).List()
109155
for i := range regionsSet {
110-
regions := regionsSet[i].(string)
111-
resourceTypeRegions.Regions = append(resourceTypeRegions.Regions, &regions)
156+
if regionsSet[i] != nil {
157+
regions := regionsSet[i].(string)
158+
resourceTypeRegions.Regions = append(resourceTypeRegions.Regions, &regions)
159+
}
112160
}
113161
}
114162
request.ResourceTypesRegions = append(request.ResourceTypesRegions, &resourceTypeRegions)
115163
}
116164
}
117165

166+
if v, ok := d.GetOk("certificate_public_key"); ok {
167+
request.CertificatePublicKey = helper.String(v.(string))
168+
}
169+
170+
if v, ok := d.GetOk("certificate_private_key"); ok {
171+
request.CertificatePrivateKey = helper.String(v.(string))
172+
}
173+
174+
if v, _ := d.GetOkExists("expiring_notification_switch"); v != nil {
175+
request.ExpiringNotificationSwitch = helper.IntUint64(v.(int))
176+
}
177+
178+
if v, _ := d.GetOkExists("repeatable"); v != nil {
179+
request.Repeatable = helper.Bool(v.(bool))
180+
}
181+
182+
if v, _ := d.GetOkExists("allow_download"); v != nil {
183+
request.AllowDownload = helper.Bool(v.(bool))
184+
}
185+
186+
if v, _ := d.GetOkExists("project_id"); v != nil {
187+
request.ProjectId = helper.IntUint64(v.(int))
188+
}
189+
118190
err := resource.Retry(writeRetryTimeout, func() *resource.RetryError {
119191
result, e := meta.(*TencentCloudClient).apiV3Conn.UseSSLCertificateClient().UpdateCertificateInstance(request)
120192
if e != nil {
121193
return retryError(e)
122194
} else {
123195
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
124196
}
125-
if result.Response.DeployStatus == nil {
126-
err := fmt.Errorf("api[%s] status is nil", request.GetAction())
127-
return retryError(err)
197+
response = result
198+
if response == nil || response.Response == nil || response.Response.DeployRecordId == nil {
199+
return resource.RetryableError(fmt.Errorf("operate ssl updateCertificateInstanceOperation response is null"))
128200
}
129-
130-
if *result.Response.DeployStatus < 0 {
131-
err := fmt.Errorf("status is %d, need retry", *result.Response.DeployStatus)
132-
return retryError(err)
201+
if *response.Response.DeployRecordId == uint64(0) {
202+
return resource.RetryableError(fmt.Errorf("operate ssl updateCertificateInstanceOperation not done"))
133203
}
134-
response = result
135204
return nil
136205
})
206+
137207
if err != nil {
138-
log.Printf("[CRITAL]%s operate ssl updateCertificateInstance failed, reason:%+v", logId, err)
208+
log.Printf("[CRITAL]%s operate ssl updateCertificateInstanceOperation failed, reason:%+v", logId, err)
139209
return err
140210
}
141211

142212
deployRecordId = *response.Response.DeployRecordId
143213
d.SetId(helper.UInt64ToStr(deployRecordId))
144214

145-
return resourceTencentCloudSslUpdateCertificateInstanceRead(d, meta)
215+
return resourceTencentCloudSslUpdateCertificateInstanceOperationRead(d, meta)
146216
}
147217

148-
func resourceTencentCloudSslUpdateCertificateInstanceRead(d *schema.ResourceData, meta interface{}) error {
218+
func resourceTencentCloudSslUpdateCertificateInstanceOperationRead(d *schema.ResourceData, meta interface{}) error {
149219
defer logElapsed("resource.tencentcloud_ssl_update_certificate_instance_operation.read")()
150220
defer inconsistentCheck(d, meta)()
151221

152222
return nil
153223
}
154224

155-
func resourceTencentCloudSslUpdateCertificateInstanceDelete(d *schema.ResourceData, meta interface{}) error {
225+
func resourceTencentCloudSslUpdateCertificateInstanceOperationDelete(d *schema.ResourceData, meta interface{}) error {
156226
defer logElapsed("resource.tencentcloud_ssl_update_certificate_instance_operation.delete")()
157227
defer inconsistentCheck(d, meta)()
158228

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package tencentcloud
22

33
import (
4-
"testing"
5-
64
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
5+
"testing"
76
)
87

9-
func TestAccTencentCloudSslUpdateCertificateInstanceResource_basic(t *testing.T) {
8+
func TestAccTencentCloudSslUpdateCertificateInstanceOperationResource_basic(t *testing.T) {
109
t.Parallel()
1110
resource.Test(t, resource.TestCase{
1211
PreCheck: func() {
@@ -15,22 +14,22 @@ func TestAccTencentCloudSslUpdateCertificateInstanceResource_basic(t *testing.T)
1514
Providers: testAccProviders,
1615
Steps: []resource.TestStep{
1716
{
18-
Config: testAccSslUpdateCertificateInstance,
17+
Config: testAccSslUpdateCertificateInstanceOperation,
1918
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_ssl_update_certificate_instance_operation.update_certificate_instance", "id"),
20-
resource.TestCheckResourceAttr("tencentcloud_ssl_update_certificate_instance_operation.update_certificate_instance", "certificate_id", "7REHyHM1"),
21-
resource.TestCheckResourceAttr("tencentcloud_ssl_update_certificate_instance_operation.update_certificate_instance", "old_certificate_id", "9D3qRt7r"),
22-
resource.TestCheckResourceAttr("tencentcloud_ssl_update_certificate_instance_operation.update_certificate_instance", "resource_types.0", "cdn"),
19+
resource.TestCheckResourceAttr("tencentcloud_ssl_update_certificate_instance_operation.update_certificate_instance", "certificate_id", "AMpBxwPq"),
20+
resource.TestCheckResourceAttr("tencentcloud_ssl_update_certificate_instance_operation.update_certificate_instance", "old_certificate_id", "AN1Gys3l"),
21+
resource.TestCheckResourceAttrSet("tencentcloud_ssl_update_certificate_instance_operation.update_certificate_instance", "resource_types.0"),
2322
),
2423
},
2524
},
2625
})
2726
}
2827

29-
const testAccSslUpdateCertificateInstance = `
28+
const testAccSslUpdateCertificateInstanceOperation = `
3029
3130
resource "tencentcloud_ssl_update_certificate_instance_operation" "update_certificate_instance" {
32-
certificate_id = "7REHyHM1"
33-
old_certificate_id = "9D3qRt7r"
31+
certificate_id = "AMpBxwPq"
32+
old_certificate_id = "AN1Gys3l"
3433
resource_types = ["cdn"]
3534
}
3635
`

tencentcloud/services/ssl/resource_tc_ssl_update_certificate_instance_operation.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@ resource "tencentcloud_ssl_update_certificate_instance_operation" "update_certif
99
resource_types = ["cdn"]
1010
}
1111
```
12+
Upload certificate
1213

13-
Import
14-
15-
ssl update_certificate_instance can be imported using the id, e.g.
16-
14+
```hcl
15+
resource "tencentcloud_ssl_update_certificate_instance_operation" "update_certificate_instance" {
16+
old_certificate_id = "xxx"
17+
certificate_public_key = file("xxx.crt")
18+
certificate_private_key= file("xxx.key")
19+
repeatable= true
20+
resource_types = ["cdn"]
21+
}
1722
```
18-
terraform import tencentcloud_ssl_update_certificate_instance_operation.update_certificate_instance update_certificate_instance_id
19-
```

website/docs/r/ssl_update_certificate_instance_operation.html.markdown

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,32 @@ resource "tencentcloud_ssl_update_certificate_instance_operation" "update_certif
2121
}
2222
```
2323

24+
### Upload certificate
25+
26+
```hcl
27+
resource "tencentcloud_ssl_update_certificate_instance_operation" "update_certificate_instance" {
28+
old_certificate_id = "xxx"
29+
certificate_public_key = file("xxx.crt")
30+
certificate_private_key = file("xxx.key")
31+
repeatable = true
32+
resource_types = ["cdn"]
33+
}
34+
```
35+
2436
## Argument Reference
2537

2638
The following arguments are supported:
2739

28-
* `certificate_id` - (Required, String, ForceNew) Update new certificate ID.
2940
* `old_certificate_id` - (Required, String, ForceNew) Update the original certificate ID.
30-
* `resource_types` - (Required, Set: [`String`], ForceNew) The resource type that needs to be deployed. The parameter value is optional: clb,cdn,waf,live,ddos,teo,apigateway,vod,tke,tcb.
31-
* `resource_types_regions` - (Optional, List, ForceNew) List of regions where cloud resources need to be deployed.
41+
* `resource_types` - (Required, Set: [`String`], ForceNew) The resource type that needs to be deployed. The parameter value is optional: clb, cdn, waf, live, ddos, teo, apigateway, vod, tke, tcb.
42+
* `allow_download` - (Optional, Bool, ForceNew) Whether to allow downloading, if you choose to upload the certificate, you can configure this parameter.
43+
* `certificate_id` - (Optional, String, ForceNew) Update new certificate ID.
44+
* `certificate_private_key` - (Optional, String, ForceNew) Certificate private key. If you upload the certificate public key, CertificateId does not need to be passed.
45+
* `certificate_public_key` - (Optional, String, ForceNew) Certificate public key. If you upload the certificate public key, CertificateId does not need to be passed.
46+
* `expiring_notification_switch` - (Optional, Int, ForceNew) Whether to ignore expiration reminders for old certificates 0: Do not ignore notifications. 1: Ignore the notification and ignore the OldCertificateId expiration reminder.
47+
* `project_id` - (Optional, Int, ForceNew) Project ID, if you choose to upload the certificate, you can configure this parameter.
48+
* `repeatable` - (Optional, Bool, ForceNew) Whether the same certificate is allowed to be uploaded repeatedly. If you choose to upload the certificate, you can configure this parameter.
49+
* `resource_types_regions` - (Optional, List, ForceNew) List of regions where cloud resources need to be deploye.
3250

3351
The `resource_types_regions` object supports the following:
3452

@@ -43,11 +61,3 @@ In addition to all arguments above, the following attributes are exported:
4361

4462

4563

46-
## Import
47-
48-
ssl update_certificate_instance can be imported using the id, e.g.
49-
50-
```
51-
terraform import tencentcloud_ssl_update_certificate_instance_operation.update_certificate_instance update_certificate_instance_id
52-
```
53-

0 commit comments

Comments
 (0)