Skip to content

Commit 68468ef

Browse files
author
mikatong
committed
update resource
1 parent 10c216f commit 68468ef

11 files changed

+226
-189
lines changed

tencentcloud/provider.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2223,9 +2223,8 @@ func Provider() *schema.Provider {
22232223
"tencentcloud_bi_embed_token_apply": bi.ResourceTencentCloudBiEmbedTokenApply(),
22242224
"tencentcloud_bi_embed_interval_apply": bi.ResourceTencentCloudBiEmbedIntervalApply(),
22252225
"tencentcloud_cdwpg_instance": cdwpg.ResourceTencentCloudCdwpgInstance(),
2226-
"tencentcloud_cdwpg_account": cdwpg.ResourceTencentCloudCdwpgAccount(),
2226+
"tencentcloud_cdwpg_reset_account_password": cdwpg.ResourceTencentCloudCdwpgResetAccountPassword(),
22272227
"tencentcloud_cdwpg_restart_instance": cdwpg.ResourceTencentCloudCdwpgRestartInstance(),
2228-
"tencentcloud_cdwpg_upgrade_instance": cdwpg.ResourceTencentCloudCdwpgUpgradeInstance(),
22292228
"tencentcloud_cdwpg_userhba": cdwpg.ResourceTencentCloudCdwpgUserhba(),
22302229
"tencentcloud_cdwpg_dbconfig": cdwpg.ResourceTencentCloudCdwpgDbconfig(),
22312230
"tencentcloud_clickhouse_keyval_config": cdwch.ResourceTencentCloudClickhouseKeyvalConfig(),

tencentcloud/provider.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2254,8 +2254,8 @@ Resource
22542254
tencentcloud_cdwpg_instance
22552255
tencentcloud_cdwpg_dbconfig
22562256
tencentcloud_cdwpg_account
2257+
tencentcloud_cdwpg_reset_account_password
22572258
tencentcloud_cdwpg_restart_instance
2258-
tencentcloud_cdwpg_upgrade_instance
22592259
tencentcloud_cdwpg_userhba
22602260

22612261
CSIP

tencentcloud/services/cdwpg/resource_tc_cdwpg_account.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

tencentcloud/services/cdwpg/resource_tc_cdwpg_instance.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ func ResourceTencentCloudCdwpgInstance() *schema.Resource {
143143
Optional: true,
144144
Description: "Tag description list.",
145145
},
146+
"product_version": {
147+
Optional: true,
148+
Type: schema.TypeString,
149+
Description: "Version.",
150+
},
146151
},
147152
}
148153
}
@@ -224,6 +229,9 @@ func resourceTencentCloudCdwpgInstanceCreate(d *schema.ResourceData, meta interf
224229
request.Resources = append(request.Resources, &resourceSpecNew)
225230
}
226231
}
232+
if v, ok := d.GetOk("product_version"); ok {
233+
request.ProductVersion = helper.String(v.(string))
234+
}
227235

228236
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
229237
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCdwpgClient().CreateInstanceByApi(request)
@@ -366,6 +374,10 @@ func resourceTencentCloudCdwpgInstanceRead(d *schema.ResourceData, meta interfac
366374

367375
}
368376

377+
if instance.Version != nil {
378+
_ = d.Set("product_version", instance.Version)
379+
}
380+
369381
tcClient := meta.(tccommon.ProviderMeta).GetAPIV3Conn()
370382
tagService := svctag.NewTagService(tcClient)
371383
tags, err := tagService.DescribeResourceTags(ctx, "cdwpg", "cdwpgInstance", tcClient.Region, d.Id())
@@ -437,6 +449,62 @@ func resourceTencentCloudCdwpgInstanceUpdate(d *schema.ResourceData, meta interf
437449
}
438450
}
439451

452+
if d.HasChange("product_version") {
453+
if v, ok := d.GetOk("product_version"); ok {
454+
request := cdwpg.NewUpgradeInstanceRequest()
455+
request.InstanceId = helper.String(instanceId)
456+
request.PackageVersion = helper.String(v.(string))
457+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
458+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCdwpgV20201230Client().UpgradeInstance(request)
459+
if e != nil {
460+
return tccommon.RetryError(e)
461+
} else {
462+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
463+
}
464+
return nil
465+
})
466+
if err != nil {
467+
log.Printf("[CRITAL]%s create cdwpg upgrade instance failed, reason:%+v", logId, err)
468+
return err
469+
}
470+
471+
service := CdwpgService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
472+
conf := tccommon.BuildStateChangeConf([]string{}, []string{"Serving"}, 10*tccommon.ReadRetryTimeout, time.Second, service.InstanceStateRefreshFunc(instanceId, []string{}))
473+
474+
if _, e := conf.WaitForState(); e != nil {
475+
return e
476+
}
477+
}
478+
}
479+
480+
if d.HasChange("product_version") {
481+
if v, ok := d.GetOk("product_version"); ok {
482+
request := cdwpg.NewUpgradeInstanceRequest()
483+
request.InstanceId = helper.String(instanceId)
484+
request.PackageVersion = helper.String(v.(string))
485+
err := resource.Retry(tccommon.WriteRetryTimeout, func() *resource.RetryError {
486+
result, e := meta.(tccommon.ProviderMeta).GetAPIV3Conn().UseCdwpgV20201230Client().UpgradeInstance(request)
487+
if e != nil {
488+
return tccommon.RetryError(e)
489+
} else {
490+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), result.ToJsonString())
491+
}
492+
return nil
493+
})
494+
if err != nil {
495+
log.Printf("[CRITAL]%s create cdwpg upgrade instance failed, reason:%+v", logId, err)
496+
return err
497+
}
498+
499+
service := CdwpgService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
500+
conf := tccommon.BuildStateChangeConf([]string{}, []string{"Serving"}, 10*tccommon.ReadRetryTimeout, time.Second, service.InstanceStateRefreshFunc(instanceId, []string{}))
501+
502+
if _, e := conf.WaitForState(); e != nil {
503+
return e
504+
}
505+
}
506+
}
507+
440508
if d.HasChange("resources") {
441509
if v, ok := d.GetOk("resources"); ok {
442510
resources := v.([]interface{})

tencentcloud/services/cdwpg/resource_tc_cdwpg_instance_test.go

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,37 @@ func TestAccTencentCloudCdwpgInstanceResource_basic(t *testing.T) {
5252
})
5353
}
5454

55+
func TestAccTencentCloudCdwpgInstanceResource_withVersion(t *testing.T) {
56+
t.Parallel()
57+
resource.Test(t, resource.TestCase{
58+
PreCheck: func() { tcacctest.AccPreCheckCommon(t, tcacctest.ACCOUNT_TYPE_PREPAY) },
59+
Providers: tcacctest.AccProviders,
60+
Steps: []resource.TestStep{
61+
{
62+
Config: testAccCdwpgInstanceWithVersion,
63+
Check: resource.ComposeTestCheckFunc(
64+
resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_instance.instance", "id"),
65+
resource.TestCheckResourceAttr("tencentcloud_cdwpg_instance.instance", "product_version", "3.16.9.3"),
66+
),
67+
},
68+
{
69+
Config: testAccCdwpgInstanceWithVersionUpdate,
70+
Check: resource.ComposeTestCheckFunc(
71+
resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_instance.instance", "id"),
72+
resource.TestCheckResourceAttr("tencentcloud_cdwpg_instance.instance", "instance_name", "test_pg_update"),
73+
resource.TestCheckResourceAttr("tencentcloud_cdwpg_instance.instance", "product_version", "3.16.9.4"),
74+
),
75+
},
76+
{
77+
ResourceName: "tencentcloud_cdwpg_instance.instance",
78+
ImportState: true,
79+
ImportStateVerify: true,
80+
ImportStateVerifyIgnore: []string{"admin_password"},
81+
},
82+
},
83+
})
84+
}
85+
5586
const testAccCdwpgInstance = `
5687
resource "tencentcloud_cdwpg_instance" "instance" {
5788
instance_name = "test_pg"
@@ -177,3 +208,89 @@ resource "tencentcloud_cdwpg_instance" "instance" {
177208
}
178209
}
179210
`
211+
212+
const testAccCdwpgInstanceWithVersion = `
213+
resource "tencentcloud_cdwpg_instance" "instance" {
214+
instance_name = "test_pg"
215+
zone = "ap-guangzhou-6"
216+
user_vpc_id = "vpc-axrsmmrv"
217+
user_subnet_id = "subnet-o6qcrhzo"
218+
charge_properties {
219+
renew_flag = 0
220+
time_span = 1
221+
time_unit = "h"
222+
charge_type = "POSTPAID_BY_HOUR"
223+
224+
}
225+
admin_password = "bWJSZDVtVmZkNExJ"
226+
resources {
227+
spec_name = "S_4_16_H_CN"
228+
count = 2
229+
disk_spec {
230+
disk_type = "CLOUD_HSSD"
231+
disk_size = 200
232+
disk_count = 1
233+
}
234+
type = "cn"
235+
236+
}
237+
resources {
238+
spec_name = "S_4_16_H_CN"
239+
count = 2
240+
disk_spec {
241+
disk_type = "CLOUD_HSSD"
242+
disk_size = 20
243+
disk_count = 10
244+
}
245+
type = "dn"
246+
247+
}
248+
tags = {
249+
"tagKey" = "tagValue"
250+
}
251+
product_version = "3.16.9.3"
252+
}
253+
`
254+
255+
const testAccCdwpgInstanceWithVersionUpdate = `
256+
resource "tencentcloud_cdwpg_instance" "instance" {
257+
instance_name = "test_pg"
258+
zone = "ap-guangzhou-6"
259+
user_vpc_id = "vpc-axrsmmrv"
260+
user_subnet_id = "subnet-o6qcrhzo"
261+
charge_properties {
262+
renew_flag = 0
263+
time_span = 1
264+
time_unit = "h"
265+
charge_type = "POSTPAID_BY_HOUR"
266+
267+
}
268+
admin_password = "bWJSZDVtVmZkNExJ"
269+
resources {
270+
spec_name = "S_4_16_H_CN"
271+
count = 2
272+
disk_spec {
273+
disk_type = "CLOUD_HSSD"
274+
disk_size = 200
275+
disk_count = 1
276+
}
277+
type = "cn"
278+
279+
}
280+
resources {
281+
spec_name = "S_4_16_H_CN"
282+
count = 2
283+
disk_spec {
284+
disk_type = "CLOUD_HSSD"
285+
disk_size = 20
286+
disk_count = 10
287+
}
288+
type = "dn"
289+
290+
}
291+
tags = {
292+
"tagKey" = "tagValue"
293+
}
294+
product_version = "3.16.9.4"
295+
}
296+
`

tencentcloud/services/cdwpg/resource_tc_cdwpg_account.go renamed to tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import (
1414
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
1515
)
1616

17-
func ResourceTencentCloudCdwpgAccount() *schema.Resource {
17+
func ResourceTencentCloudCdwpgResetAccountPassword() *schema.Resource {
1818
return &schema.Resource{
19-
Create: resourceTencentCloudCdwpgAccountCreate,
20-
Read: resourceTencentCloudCdwpgAccountRead,
21-
Update: resourceTencentCloudCdwpgAccountUpdate,
22-
Delete: resourceTencentCloudCdwpgAccountDelete,
19+
Create: resourceTencentCloudCdwpgResetAccountPasswordCreate,
20+
Read: resourceTencentCloudCdwpgResetAccountPasswordRead,
21+
Update: resourceTencentCloudCdwpgResetAccountPasswordUpdate,
22+
Delete: resourceTencentCloudCdwpgResetAccountPasswordDelete,
2323
Importer: &schema.ResourceImporter{
2424
State: schema.ImportStatePassthrough,
2525
},
@@ -48,20 +48,20 @@ func ResourceTencentCloudCdwpgAccount() *schema.Resource {
4848
}
4949
}
5050

51-
func resourceTencentCloudCdwpgAccountCreate(d *schema.ResourceData, meta interface{}) error {
52-
defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_account.create")()
51+
func resourceTencentCloudCdwpgResetAccountPasswordCreate(d *schema.ResourceData, meta interface{}) error {
52+
defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_reset_account_password.create")()
5353
defer tccommon.InconsistentCheck(d, meta)()
5454

5555
instanceId := d.Get("instance_id").(string)
5656
userName := d.Get("user_name").(string)
5757

5858
d.SetId(strings.Join([]string{instanceId, userName}, tccommon.FILED_SP))
5959

60-
return resourceTencentCloudCdwpgAccountUpdate(d, meta)
60+
return resourceTencentCloudCdwpgResetAccountPasswordUpdate(d, meta)
6161
}
6262

63-
func resourceTencentCloudCdwpgAccountRead(d *schema.ResourceData, meta interface{}) error {
64-
defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_account.read")()
63+
func resourceTencentCloudCdwpgResetAccountPasswordRead(d *schema.ResourceData, meta interface{}) error {
64+
defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_reset_account_password.read")()
6565
defer tccommon.InconsistentCheck(d, meta)()
6666

6767
logId := tccommon.GetLogId(tccommon.ContextNil)
@@ -99,8 +99,8 @@ func resourceTencentCloudCdwpgAccountRead(d *schema.ResourceData, meta interface
9999
return nil
100100
}
101101

102-
func resourceTencentCloudCdwpgAccountUpdate(d *schema.ResourceData, meta interface{}) error {
103-
defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_account.update")()
102+
func resourceTencentCloudCdwpgResetAccountPasswordUpdate(d *schema.ResourceData, meta interface{}) error {
103+
defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_reset_account_password.update")()
104104
defer tccommon.InconsistentCheck(d, meta)()
105105

106106
logId := tccommon.GetLogId(tccommon.ContextNil)
@@ -149,11 +149,11 @@ func resourceTencentCloudCdwpgAccountUpdate(d *schema.ResourceData, meta interfa
149149
}
150150
}
151151

152-
return resourceTencentCloudCdwpgAccountRead(d, meta)
152+
return resourceTencentCloudCdwpgResetAccountPasswordRead(d, meta)
153153
}
154154

155-
func resourceTencentCloudCdwpgAccountDelete(d *schema.ResourceData, meta interface{}) error {
156-
defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_account.delete")()
155+
func resourceTencentCloudCdwpgResetAccountPasswordDelete(d *schema.ResourceData, meta interface{}) error {
156+
defer tccommon.LogElapsed("resource.tencentcloud_cdwpg_reset_account_password.delete")()
157157
defer tccommon.InconsistentCheck(d, meta)()
158158

159159
return nil
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Provides a resource to reset cdwpg account password
2+
3+
Example Usage
4+
5+
```hcl
6+
resource "tencentcloud_cdwpg_reset_account_password" "cdwpg_reset_account_password" {
7+
instance_id = "cdwpg-zpiemnyd"
8+
user_name = "dbadmin"
9+
new_password = "testpassword"
10+
}
11+
```
12+
13+
Import
14+
15+
cdwpg reset account password can be imported using the id, e.g.
16+
17+
```
18+
terraform import tencentcloud_cdwpg_reset_account_password.cdwpg_account cdwpg_reset_account_password_id
19+
```

tencentcloud/services/cdwpg/resource_tc_cdwpg_account_test.go renamed to tencentcloud/services/cdwpg/resource_tc_cdwpg_reset_account_password_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
tcacctest "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/acctest"
99
)
1010

11-
func TestAccTencentCloudCdwpgAccountResource_basic(t *testing.T) {
11+
func TestAccTencentCloudCdwpgResetAccountPasswordResource_basic(t *testing.T) {
1212
t.Parallel()
1313
resource.Test(t, resource.TestCase{
1414
PreCheck: func() {
@@ -17,9 +17,9 @@ func TestAccTencentCloudCdwpgAccountResource_basic(t *testing.T) {
1717
Providers: tcacctest.AccProviders,
1818
Steps: []resource.TestStep{{
1919
Config: testAccCdwpgAccount,
20-
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_account.cdwpg_account", "id")),
20+
Check: resource.ComposeTestCheckFunc(resource.TestCheckResourceAttrSet("tencentcloud_cdwpg_reset_account_password.cdwpg_account", "id")),
2121
}, {
22-
ResourceName: "tencentcloud_cdwpg_account.cdwpg_account",
22+
ResourceName: "tencentcloud_cdwpg_reset_account_password.cdwpg_account",
2323
ImportState: true,
2424
ImportStateVerify: true,
2525
ImportStateVerifyIgnore: []string{"new_password"},
@@ -28,8 +28,8 @@ func TestAccTencentCloudCdwpgAccountResource_basic(t *testing.T) {
2828
}
2929

3030
const testAccCdwpgAccount = `
31-
resource "tencentcloud_cdwpg_account" "cdwpg_account" {
32-
instance_id = "cdwpg-zpiemnyd"
31+
resource "tencentcloud_cdwpg_reset_account_password" "cdwpg_account" {
32+
instance_id = "cdwpg-r3xgk6w3"
3333
user_name = "dbadmin"
3434
new_password = "testpassword"
3535
}

0 commit comments

Comments
 (0)