Skip to content

Commit c706879

Browse files
committed
[fix for code review]
1. fix for code review
1 parent 810bf8b commit c706879

File tree

8 files changed

+23
-31
lines changed

8 files changed

+23
-31
lines changed

examples/tencentcloud-cynosdb/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ resource "tencentcloud_cynosdb_readonly_instance" "foo" {
6161
}
6262

6363
data "tencentcloud_cynosdb_clusters" "foo" {
64-
cluster_id = "cynosdbmysql-dzj5l8gz"
64+
cluster_id = tencentcloud_cynosdb_cluster.foo.id
6565
project_id = 0
6666
db_type = "MYSQL"
6767
cluster_name = "test"
6868
}
6969

7070
data "tencentcloud_cynosdb_instances" "foo" {
71-
instance_id = "cynosdbmysql-ins-0wln9u6w"
71+
instance_id = tencentcloud_cynosdb_readonly_instance.foo.id
7272
project_id = 0
7373
db_type = "MYSQL"
7474
instance_name = "test"

tencentcloud/extension_cynosdb.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ func TencentCynosdbClusterBaseInfo() map[string]*schema.Schema {
172172
"auto_renew_flag": {
173173
Type: schema.TypeInt,
174174
Optional: true,
175-
Description: "Auto renew flag. Valid values are `0`(MANUAL_RENEW), `1`(AUTO_RENEW). Only works for PREPAID cluster.",
175+
Default: 0,
176+
Description: "Auto renew flag. Valid values are `0`(MANUAL_RENEW), `1`(AUTO_RENEW). Default value is `0`. Only works for PREPAID cluster.",
176177
},
177178
"force_delete": {
178179
Type: schema.TypeBool,
@@ -210,7 +211,7 @@ func TencentCynosdbClusterBaseInfo() map[string]*schema.Schema {
210211
"rw_group_id": {
211212
Type: schema.TypeString,
212213
Computed: true,
213-
Description: "Id of read-write instance group.",
214+
Description: "ID of read-write instance group.",
214215
},
215216
"rw_group_instances": {
216217
Type: schema.TypeList,
@@ -260,7 +261,7 @@ func TencentCynosdbClusterBaseInfo() map[string]*schema.Schema {
260261
"ro_group_id": {
261262
Type: schema.TypeString,
262263
Computed: true,
263-
Description: "Id of read-only instance group.",
264+
Description: "ID of read-only instance group.",
264265
},
265266
"ro_group_instances": {
266267
Type: schema.TypeList,

tencentcloud/resource_tc_cynosdb_cluster.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter
120120
} else {
121121
return fmt.Errorf("prepaid period can not be empty when charge type is %s", CYNOSDB_CHARGE_TYPE_PREPAID)
122122
}
123-
if vv, ok := d.GetOk("auto_renew_flag"); ok {
124-
request.AutoRenewFlag = helper.IntInt64(vv.(int))
125-
}
123+
request.AutoRenewFlag = helper.IntInt64(d.Get("auto_renew_flag").(int))
126124
}
127125
}
128126
request.PayMode = &chargeType
@@ -149,7 +147,7 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter
149147
d.SetId(*response.Response.ClusterIds[0])
150148
id := d.Id()
151149

152-
_, has, err := cynosdbService.DescribeClusterById(ctx, id)
150+
_, _, has, err := cynosdbService.DescribeClusterById(ctx, id)
153151
if err != nil {
154152
return err
155153
}
@@ -166,7 +164,7 @@ func resourceTencentCloudCynosdbClusterCreate(d *schema.ResourceData, meta inter
166164
}
167165

168166
// set maintenance info
169-
cluster, _, err := cynosdbService.DescribeClusterById(ctx, id)
167+
_, cluster, _, err := cynosdbService.DescribeClusterById(ctx, id)
170168
if err != nil {
171169
return err
172170
}
@@ -251,7 +249,7 @@ func resourceTencentCloudCynosdbClusterRead(d *schema.ResourceData, meta interfa
251249

252250
client := meta.(*TencentCloudClient).apiV3Conn
253251
cynosdbService := CynosdbService{client: client}
254-
cluster, has, err := cynosdbService.DescribeClusterById(ctx, id)
252+
renewFlag, cluster, has, err := cynosdbService.DescribeClusterById(ctx, id)
255253
if err != nil {
256254
return err
257255
}
@@ -273,6 +271,7 @@ func resourceTencentCloudCynosdbClusterRead(d *schema.ResourceData, meta interfa
273271
_ = d.Set("cluster_status", cluster.Status)
274272
_ = d.Set("create_time", cluster.CreateTime)
275273
_ = d.Set("storage_used", *cluster.UsedStorage/1000/1000)
274+
_ = d.Set("auto_renew_flag", renewFlag)
276275

277276
//tag
278277
tagService := &TagService{client: client}

tencentcloud/resource_tc_cynosdb_cluster_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func TestAccTencentCloudCynosdbClusterResource(t *testing.T) {
7272
ResourceName: "tencentcloud_cynosdb_cluster.foo",
7373
ImportState: true,
7474
ImportStateVerify: true,
75-
ImportStateVerifyIgnore: []string{"password", "auto_renew_flag", "force_delete", "storage_limit"},
75+
ImportStateVerifyIgnore: []string{"password", "force_delete", "storage_limit"},
7676
},
7777
{
7878
Config: testAccCynosdbClusterPrepaid,
@@ -132,7 +132,7 @@ func testAccCheckCynosdbClusterDestroy(s *terraform.State) error {
132132
continue
133133
}
134134

135-
_, has, err := cynosdbService.DescribeClusterById(ctx, rs.Primary.ID)
135+
_, _, has, err := cynosdbService.DescribeClusterById(ctx, rs.Primary.ID)
136136
if err != nil {
137137
return err
138138
}
@@ -159,7 +159,7 @@ func testAccCheckCynosdbClusterExists(n string) resource.TestCheckFunc {
159159
cynosdbService := CynosdbService{
160160
client: testAccProvider.Meta().(*TencentCloudClient).apiV3Conn,
161161
}
162-
_, has, err := cynosdbService.DescribeClusterById(ctx, rs.Primary.ID)
162+
_, _, has, err := cynosdbService.DescribeClusterById(ctx, rs.Primary.ID)
163163
if err != nil {
164164
return err
165165
}

tencentcloud/resource_tc_cynosdb_readonly_instance.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ func resourceTencentCloudCynosdbReadonlyInstance() *schema.Resource {
5252
"cluster_id": {
5353
Type: schema.TypeString,
5454
Required: true,
55+
ForceNew: true,
5556
Description: "Cluster id which the readonly instance belongs to.",
5657
},
5758
"instance_name": {
5859
Type: schema.TypeString,
5960
Required: true,
61+
ForceNew: true,
6062
Description: "Name of instance.",
6163
},
6264
"force_delete": {
@@ -196,17 +198,6 @@ func resourceTencentCloudCynosdbReadonlyInstanceUpdate(d *schema.ResourceData, m
196198
cynosdbService = CynosdbService{client: client}
197199
)
198200

199-
// check unsupported field modification
200-
unsupported := []string{
201-
"cluster_id",
202-
"instance_name",
203-
}
204-
for _, v := range unsupported {
205-
if d.HasChange(v) {
206-
return fmt.Errorf("[CRITAL] field %s is not allowed to be modified", v)
207-
}
208-
}
209-
210201
d.Partial(true)
211202

212203
if d.HasChange("instance_cpu_core") || d.HasChange("instance_memory_size") {

tencentcloud/service_tencentcloud_cynosdb.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (me *CynosdbService) DescribeClusters(ctx context.Context, filters map[stri
5959
return
6060
}
6161

62-
func (me *CynosdbService) DescribeClusterById(ctx context.Context, clusterId string) (clusterInfo *cynosdb.CynosdbClusterDetail, has bool, errRet error) {
62+
func (me *CynosdbService) DescribeClusterById(ctx context.Context, clusterId string) (renewFlag int64, clusterInfo *cynosdb.CynosdbClusterDetail, has bool, errRet error) {
6363
logId := getLogId(ctx)
6464
request := cynosdb.NewDescribeClusterDetailRequest()
6565
request.ClusterId = &clusterId
@@ -84,6 +84,7 @@ func (me *CynosdbService) DescribeClusterById(ctx context.Context, clusterId str
8484
notExist = true
8585
return nil
8686
} else if *clusters[0].Status == CYNOSDB_STATUS_RUNNING {
87+
renewFlag = *clusters[0].RenewFlag
8788
return nil
8889
} else {
8990
return resource.RetryableError(fmt.Errorf("cynosdb cluster %s is still in processing", clusterId))

website/docs/r/cynosdb_cluster.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The following arguments are supported:
6767
* `storage_limit` - (Required) Storage limit of CynosDB cluster instance, unit in GB.
6868
* `subnet_id` - (Required) ID of the subnet within this VPC.
6969
* `vpc_id` - (Required) ID of the VPC.
70-
* `auto_renew_flag` - (Optional) Auto renew flag. Valid values are `0`(MANUAL_RENEW), `1`(AUTO_RENEW). Only works for PREPAID cluster.
70+
* `auto_renew_flag` - (Optional) Auto renew flag. Valid values are `0`(MANUAL_RENEW), `1`(AUTO_RENEW). Default value is `0`. Only works for PREPAID cluster.
7171
* `charge_type` - (Optional, ForceNew) The charge type of instance. Valid values are `PREPAID` and `POSTPAID_BY_HOUR`. Default value is `POSTPAID_BY_HOUR`.
7272
* `force_delete` - (Optional) Indicate whether to delete cluster instance directly or not. Default is false. If set true, the cluster and its `All RELATED INSTANCES` will be deleted instead of staying recycle bin. Note: works for both `PREPAID` and `POSTPAID_BY_HOUR` cluster.
7373
* `instance_maintain_duration` - (Optional) Duration time for maintenance, unit in second. `3600` by default.
@@ -95,14 +95,14 @@ In addition to all arguments above, the following attributes are exported:
9595
* `ro_group_addr` - Readonly addresses. Each element contains the following attributes:
9696
* `ip` - IP address for readonly connection.
9797
* `port` - Port number for readonly connection.
98-
* `ro_group_id` - Id of read-only instance group.
98+
* `ro_group_id` - ID of read-only instance group.
9999
* `ro_group_instances` - List of instances in the read-only instance group.
100100
* `instance_id` - ID of instance.
101101
* `instance_name` - Name of instance.
102102
* `rw_group_addr` - Read-write addresses. Each element contains the following attributes:
103103
* `ip` - IP address for read-write connection.
104104
* `port` - Port number for read-write connection.
105-
* `rw_group_id` - Id of read-write instance group.
105+
* `rw_group_id` - ID of read-write instance group.
106106
* `rw_group_instances` - List of instances in the read-write instance group.
107107
* `instance_id` - ID of instance.
108108
* `instance_name` - Name of instance.

website/docs/r/cynosdb_readonly_instance.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ resource "tencentcloud_cynosdb_readonly_instance" "foo" {
3939

4040
The following arguments are supported:
4141

42-
* `cluster_id` - (Required) Cluster id which the readonly instance belongs to.
42+
* `cluster_id` - (Required, ForceNew) Cluster id which the readonly instance belongs to.
4343
* `instance_cpu_core` - (Required) The number of CPU cores of read-write type instance in the CynosDB cluster. Note: modification of this field will take effect immediately, if want to upgrade on maintenance window, please upgrade from console.
4444
* `instance_memory_size` - (Required) Memory capacity of read-write type instance, unit in GB. Note: modification of this field will take effect immediately, if want to upgrade on maintenance window, please upgrade from console.
45-
* `instance_name` - (Required) Name of instance.
45+
* `instance_name` - (Required, ForceNew) Name of instance.
4646
* `force_delete` - (Optional) Indicate whether to delete readonly instance directly or not. Default is false. If set true, instance will be deleted instead of staying recycle bin. Note: works for both `PREPAID` and `POSTPAID_BY_HOUR` cluster.
4747
* `instance_maintain_duration` - (Optional) Duration time for maintenance, unit in second. `3600` by default.
4848
* `instance_maintain_start_time` - (Optional) Offset time from 00:00, unit in second. For example, 03:00am should be `10800`. `10800` by default.

0 commit comments

Comments
 (0)