Skip to content

Commit 3c2795f

Browse files
committed
[code review]
1. fix review for retry
1 parent 964f2b9 commit 3c2795f

File tree

4 files changed

+62
-64
lines changed

4 files changed

+62
-64
lines changed

tencentcloud/data_source_tc_cynosdb_clusters.go

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
2323
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
24+
cynosdb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cynosdb/v20190107"
2425
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
2526
)
2627

@@ -163,57 +164,56 @@ func dataSourceTencentCloudCynosdbClustersRead(d *schema.ResourceData, meta inte
163164
client: meta.(*TencentCloudClient).apiV3Conn,
164165
}
165166

166-
err := resource.Retry(readRetryTimeout, func() *resource.RetryError {
167-
clusters, e := cynosdbService.DescribeClusters(ctx, params)
168-
if e != nil {
169-
return retryError(e)
167+
var clusters []*cynosdb.CynosdbCluster
168+
var err error
169+
err = resource.Retry(readRetryTimeout, func() *resource.RetryError {
170+
clusters, err = cynosdbService.DescribeClusters(ctx, params)
171+
if err != nil {
172+
return retryError(err)
170173
}
171-
ids := make([]string, 0, len(clusters))
172-
clusterList := make([]map[string]interface{}, 0, len(clusters))
173-
for _, cluster := range clusters {
174-
if clusterType != "" && clusterType != *cluster.DbType {
175-
continue
176-
}
177-
mapping := map[string]interface{}{
178-
"cluster_id": cluster.ClusterId,
179-
"cluster_name": cluster.ClusterName,
180-
"cluster_limit": cluster.StorageLimit,
181-
"db_type": cluster.DbType,
182-
"available_zone": cluster.Zone,
183-
"project_id": cluster.ProjectID,
184-
"create_time": cluster.CreateTime,
185-
"cluster_status": cluster.Status,
186-
"auto_renew_flag": cluster.RenewFlag,
187-
"port": cluster.Vport,
188-
"vpc_id": cluster.VpcId,
189-
"subnet_id": cluster.SubnetId,
190-
"db_version": cluster.DbVersion,
191-
"charge_type": CYNOSDB_CHARGE_TYPE[*cluster.PayMode],
192-
}
193-
194-
clusterList = append(clusterList, mapping)
195-
ids = append(ids, *cluster.ClusterId)
196-
}
197-
198-
d.SetId(helper.DataResourceIdsHash(ids))
199-
if e = d.Set("cluster_list", clusterList); e != nil {
200-
log.Printf("[CRITAL]%s provider set cluster list fail, reason:%s\n ", logId, e.Error())
201-
return resource.NonRetryableError(e)
202-
}
203-
204-
output, ok := d.GetOk("result_output_file")
205-
if ok && output.(string) != "" {
206-
if e := writeToFile(output.(string), clusterList); e != nil {
207-
return resource.NonRetryableError(e)
208-
}
209-
}
210-
211174
return nil
212175
})
213176
if err != nil {
214177
log.Printf("[CRITAL]%s read cynosdb clusters failed, reason:%s\n ", logId, err.Error())
215178
return err
216179
}
217180

181+
ids := make([]string, 0, len(clusters))
182+
clusterList := make([]map[string]interface{}, 0, len(clusters))
183+
for _, cluster := range clusters {
184+
if clusterType != "" && clusterType != *cluster.DbType {
185+
continue
186+
}
187+
mapping := map[string]interface{}{
188+
"cluster_id": cluster.ClusterId,
189+
"cluster_name": cluster.ClusterName,
190+
"cluster_limit": cluster.StorageLimit,
191+
"db_type": cluster.DbType,
192+
"available_zone": cluster.Zone,
193+
"project_id": cluster.ProjectID,
194+
"create_time": cluster.CreateTime,
195+
"cluster_status": cluster.Status,
196+
"auto_renew_flag": cluster.RenewFlag,
197+
"port": cluster.Vport,
198+
"vpc_id": cluster.VpcId,
199+
"subnet_id": cluster.SubnetId,
200+
"db_version": cluster.DbVersion,
201+
"charge_type": CYNOSDB_CHARGE_TYPE[*cluster.PayMode],
202+
}
203+
204+
clusterList = append(clusterList, mapping)
205+
ids = append(ids, *cluster.ClusterId)
206+
}
207+
208+
d.SetId(helper.DataResourceIdsHash(ids))
209+
_ = d.Set("cluster_list", clusterList)
210+
211+
output, ok := d.GetOk("result_output_file")
212+
if ok && output.(string) != "" {
213+
if err = writeToFile(output.(string), clusterList); err != nil {
214+
return err
215+
}
216+
}
217+
218218
return nil
219219
}

tencentcloud/extension_cynosdb.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ func TencentCynosdbClusterBaseInfo() map[string]*schema.Schema {
101101
"project_id": {
102102
Type: schema.TypeInt,
103103
Optional: true,
104+
ForceNew: true,
104105
Default: 0,
105106
Description: "ID of the project. `0` by default.",
106107
},
@@ -113,16 +114,19 @@ func TencentCynosdbClusterBaseInfo() map[string]*schema.Schema {
113114
"vpc_id": {
114115
Type: schema.TypeString,
115116
Required: true,
117+
ForceNew: true,
116118
Description: "ID of the VPC.",
117119
},
118120
"subnet_id": {
119121
Type: schema.TypeString,
120122
Required: true,
123+
ForceNew: true,
121124
Description: "ID of the subnet within this VPC.",
122125
},
123126
"port": {
124127
Type: schema.TypeInt,
125128
Optional: true,
129+
ForceNew: true,
126130
Default: 5432,
127131
Description: "Port of CynosDB cluster.",
128132
},
@@ -141,16 +145,19 @@ func TencentCynosdbClusterBaseInfo() map[string]*schema.Schema {
141145
"storage_limit": {
142146
Type: schema.TypeInt,
143147
Required: true,
148+
ForceNew: true,
144149
Description: "Storage limit of CynosDB cluster instance, unit in GB.",
145150
},
146151
"cluster_name": {
147152
Type: schema.TypeString,
148153
Required: true,
154+
ForceNew: true,
149155
Description: "Name of CynosDB cluster.",
150156
},
151157
"password": {
152158
Type: schema.TypeString,
153159
Required: true,
160+
ForceNew: true,
154161
Sensitive: true,
155162
Description: "Password of `root` account.",
156163
},
@@ -166,12 +173,14 @@ func TencentCynosdbClusterBaseInfo() map[string]*schema.Schema {
166173
"prepaid_period": {
167174
Type: schema.TypeInt,
168175
Optional: true,
176+
ForceNew: true,
169177
ValidateFunc: validateAllowedIntValue(CYNOSDB_PREPAID_PERIOD),
170178
Description: "The tenancy (time unit is month) of the prepaid instance. Valid values are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36. NOTE: it only works when charge_type is set to `PREPAID`.",
171179
},
172180
"auto_renew_flag": {
173181
Type: schema.TypeInt,
174182
Optional: true,
183+
ForceNew: true,
175184
Default: 0,
176185
Description: "Auto renew flag. Valid values are `0`(MANUAL_RENEW), `1`(AUTO_RENEW). Default value is `0`. Only works for PREPAID cluster.",
177186
},

tencentcloud/resource_tc_cynosdb_cluster.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -397,17 +397,6 @@ func resourceTencentCloudCynosdbClusterUpdate(d *schema.ResourceData, meta inter
397397
region = client.Region
398398
)
399399

400-
// check unsupported field modification
401-
unsupported := []string{
402-
"project_id", "vpc_id", "subnet_id", "port", "storage_limit", "cluster_name",
403-
"password", "prepaid_period", "auto_renew_flag",
404-
}
405-
for _, v := range unsupported {
406-
if d.HasChange(v) {
407-
return fmt.Errorf("[CRITAL] field %s is not allowed to be modified", v)
408-
}
409-
}
410-
411400
d.Partial(true)
412401

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

website/docs/r/cynosdb_cluster.html.markdown

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,24 @@ resource "tencentcloud_cynosdb_cluster" "foo" {
5858
The following arguments are supported:
5959

6060
* `available_zone` - (Required, ForceNew) The available zone of the CynosDB Cluster.
61-
* `cluster_name` - (Required) Name of CynosDB cluster.
61+
* `cluster_name` - (Required, ForceNew) Name of CynosDB cluster.
6262
* `db_type` - (Required, ForceNew) Type of CynosDB, and available values include `MYSQL`.
6363
* `db_version` - (Required, ForceNew) Version of CynosDB, which is related to `db_type`. For `MYSQL`, available value is `5.7`.
6464
* `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.
6565
* `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.
66-
* `password` - (Required) Password of `root` account.
67-
* `storage_limit` - (Required) Storage limit of CynosDB cluster instance, unit in GB.
68-
* `subnet_id` - (Required) ID of the subnet within this VPC.
69-
* `vpc_id` - (Required) ID of the VPC.
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.
66+
* `password` - (Required, ForceNew) Password of `root` account.
67+
* `storage_limit` - (Required, ForceNew) Storage limit of CynosDB cluster instance, unit in GB.
68+
* `subnet_id` - (Required, ForceNew) ID of the subnet within this VPC.
69+
* `vpc_id` - (Required, ForceNew) ID of the VPC.
70+
* `auto_renew_flag` - (Optional, ForceNew) 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.
7474
* `instance_maintain_start_time` - (Optional) Offset time from 00:00, unit in second. For example, 03:00am should be `10800`. `10800` by default.
7575
* `instance_maintain_weekdays` - (Optional) Weekdays for maintenance. `["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]` by default.
76-
* `port` - (Optional) Port of CynosDB cluster.
77-
* `prepaid_period` - (Optional) The tenancy (time unit is month) of the prepaid instance. Valid values are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36. NOTE: it only works when charge_type is set to `PREPAID`.
78-
* `project_id` - (Optional) ID of the project. `0` by default.
76+
* `port` - (Optional, ForceNew) Port of CynosDB cluster.
77+
* `prepaid_period` - (Optional, ForceNew) The tenancy (time unit is month) of the prepaid instance. Valid values are 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 24, 36. NOTE: it only works when charge_type is set to `PREPAID`.
78+
* `project_id` - (Optional, ForceNew) ID of the project. `0` by default.
7979
* `ro_group_sg` - (Optional) IDs of security group for `ro_group`.
8080
* `rw_group_sg` - (Optional) IDs of security group for `rw_group`.
8181
* `tags` - (Optional) The tags of the CynosDB cluster.

0 commit comments

Comments
 (0)