Skip to content

Commit 52d6526

Browse files
author
hhermanwang
committed
remove sqlserver baisc instance good_num, modify code review question
1 parent 42962d2 commit 52d6526

7 files changed

+63
-74
lines changed

tencentcloud/data_source_tc_sqlserver_basic_instances.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Use this data source to query SQL Server Basic instances
2+
Use this data source to query SQL Server basic instances
33
44
Example Usage
55
@@ -11,7 +11,7 @@ resource "tencentcloud_sqlserver_basic_instance" "test" {
1111
charge_type = "POSTPAID_BY_HOUR"
1212
vpc_id = "vpc-26w7r56z"
1313
subnet_id = "subnet-lvlr6eeu"
14-
machine_type ="CLOUD_PREMIUM"
14+
machine_type = "CLOUD_PREMIUM"
1515
project_id = 0
1616
memory = 2
1717
storage = 10
@@ -41,22 +41,22 @@ func dataSourceTencentCloudSqlserverBasicInstances() *schema.Resource {
4141
"id": {
4242
Type: schema.TypeString,
4343
Optional: true,
44-
Description: "ID of the SQL Server Basic instance to be query.",
44+
Description: "ID of the SQL Server basic instance to be query.",
4545
},
4646
"project_id": {
4747
Type: schema.TypeInt,
4848
Optional: true,
49-
Description: "Project ID of the SQL Server Basic instance to be query.",
49+
Description: "Project ID of the SQL Server basic instance to be query.",
5050
},
5151
"vpc_id": {
5252
Type: schema.TypeString,
5353
Optional: true,
54-
Description: "Vpc ID of the SQL Server Basic instance to be query.",
54+
Description: "Vpc ID of the SQL Server basic instance to be query.",
5555
},
5656
"subnet_id": {
5757
Type: schema.TypeString,
5858
Optional: true,
59-
Description: "Subnet ID of the SQL Server Basic instance to be query.",
59+
Description: "Subnet ID of the SQL Server basic instance to be query.",
6060
},
6161
"result_output_file": {
6262
Type: schema.TypeString,
@@ -66,28 +66,28 @@ func dataSourceTencentCloudSqlserverBasicInstances() *schema.Resource {
6666
"instance_list": {
6767
Type: schema.TypeList,
6868
Computed: true,
69-
Description: "A list of SQL Server Basic instances. Each element contains the following attributes.",
69+
Description: "A list of SQL Server basic instances. Each element contains the following attributes.",
7070
Elem: &schema.Resource{
7171
Schema: map[string]*schema.Schema{
7272
"id": {
7373
Type: schema.TypeString,
7474
Computed: true,
75-
Description: "ID of the SQL Server Basic instance.",
75+
Description: "ID of the SQL Server basic instance.",
7676
},
7777
"name": {
7878
Type: schema.TypeString,
7979
Computed: true,
80-
Description: "Name of the SQL Server Basic instance.",
80+
Description: "Name of the SQL Server basic instance.",
8181
},
8282
"charge_type": {
8383
Type: schema.TypeString,
8484
Computed: true,
85-
Description: "Pay type of the SQL Server Basic instance. For now, only `POSTPAID_BY_HOUR` is valid.",
85+
Description: "Pay type of the SQL Server basic instance. For now, only `POSTPAID_BY_HOUR` is valid.",
8686
},
8787
"engine_version": {
8888
Type: schema.TypeString,
8989
Computed: true,
90-
Description: "Version of the SQL Server Basic database engine. Allowed values are `2008R2`(SQL Server 2008 Enerprise), `2012SP3`(SQL Server 2012 Enterprise), `2016SP1` (SQL Server 2016 Enterprise), `201602`(SQL Server 2016 Standard) and `2017`(SQL Server 2017 Enterprise). Default is `2008R2`.",
90+
Description: "Version of the SQL Server basic database engine. Allowed values are `2008R2`(SQL Server 2008 Enerprise), `2012SP3`(SQL Server 2012 Enterprise), `2016SP1` (SQL Server 2016 Enterprise), `201602`(SQL Server 2016 Standard) and `2017`(SQL Server 2017 Enterprise). Default is `2008R2`.",
9191
},
9292
"vpc_id": {
9393
Type: schema.TypeString,
@@ -112,7 +112,7 @@ func dataSourceTencentCloudSqlserverBasicInstances() *schema.Resource {
112112
"cpu": {
113113
Type: schema.TypeInt,
114114
Computed: true,
115-
Description: "The CPU number of the SQL Server Basic instance.",
115+
Description: "The CPU number of the SQL Server basic instance.",
116116
},
117117
"project_id": {
118118
Type: schema.TypeInt,
@@ -142,17 +142,17 @@ func dataSourceTencentCloudSqlserverBasicInstances() *schema.Resource {
142142
"create_time": {
143143
Type: schema.TypeString,
144144
Computed: true,
145-
Description: "Create time of the SQL Server Basic instance.",
145+
Description: "Create time of the SQL Server basic instance.",
146146
},
147147
"status": {
148148
Type: schema.TypeInt,
149149
Computed: true,
150-
Description: "Status of the SQL Server Basic instance. 1 for applying, 2 for running, 3 for running with limit, 4 for isolated, 5 for recycling, 6 for recycled, 7 for running with task, 8 for off-line, 9 for expanding, 10 for migrating, 11 for readonly, 12 for rebooting.",
150+
Description: "Status of the SQL Server basic instance. 1 for applying, 2 for running, 3 for running with limit, 4 for isolated, 5 for recycling, 6 for recycled, 7 for running with task, 8 for off-line, 9 for expanding, 10 for migrating, 11 for readonly, 12 for rebooting.",
151151
},
152152
"tags": {
153153
Type: schema.TypeMap,
154154
Computed: true,
155-
Description: "Tags of the SQL Server Basic instance.",
155+
Description: "Tags of the SQL Server basic instance.",
156156
},
157157
},
158158
},

tencentcloud/data_source_tc_sqlserver_basic_instances_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ resource "tencentcloud_sqlserver_basic_instance" "test" {
6666
charge_type = "POSTPAID_BY_HOUR"
6767
vpc_id = tencentcloud_vpc.foo.id
6868
subnet_id = tencentcloud_subnet.foo.id
69-
machine_type ="CLOUD_PREMIUM"
69+
machine_type = "CLOUD_PREMIUM"
7070
project_id = 0
7171
memory = 2
7272
storage = 20

tencentcloud/resource_tc_sqlserver_basic_instance.go

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Provides a SQL Server instance resource to create Basic database instances.
2+
Provides a SQL Server instance resource to create basic database instances.
33
44
Example Usage
55
@@ -15,7 +15,6 @@ resource "tencentcloud_sqlserver_basic_instance" "foo" {
1515
storage = 20
1616
cpu = 1
1717
machine_type = "CLOUD_PREMIUM"
18-
goods_num = 1
1918
maintenance_week_set = [1,2,3]
2019
maintenance_start_time = "09:00"
2120
maintenance_time_span = 3
@@ -28,7 +27,7 @@ resource "tencentcloud_sqlserver_basic_instance" "foo" {
2827
```
2928
Import
3029
31-
SQL Server Basic instance can be imported using the id, e.g.
30+
SQL Server basic instance can be imported using the id, e.g.
3231
3332
```
3433
$ terraform import tencentcloud_sqlserver_basic_instance.foo mssql-3cdq7kx5
@@ -61,12 +60,12 @@ func resourceTencentCloudSqlserverBasicInstance() *schema.Resource {
6160
Type: schema.TypeString,
6261
Required: true,
6362
ValidateFunc: validateStringLengthInRange(1, 60),
64-
Description: "Name of the SQL Server Basic instance.",
63+
Description: "Name of the SQL Server basic instance.",
6564
},
6665
"cpu": {
6766
Type: schema.TypeInt,
6867
Required: true,
69-
Description: "The CPU number of the SQL Server Basic instance.",
68+
Description: "The CPU number of the SQL Server basic instance.",
7069
},
7170
"storage": {
7271
Type: schema.TypeInt,
@@ -90,14 +89,7 @@ func resourceTencentCloudSqlserverBasicInstance() *schema.Resource {
9089
Default: COMMON_PAYTYPE_POSTPAID,
9190
ForceNew: true,
9291
ValidateFunc: validateAllowedStringValue([]string{COMMON_PAYTYPE_PREPAID, COMMON_PAYTYPE_POSTPAID}),
93-
Description: "Pay type of the SQL Server Basic instance. For now, only `POSTPAID_BY_HOUR` is valid.",
94-
},
95-
"goods_num": {
96-
Type: schema.TypeInt,
97-
Optional: true,
98-
Default: 1,
99-
ValidateFunc: validateIntegerInRange(1, 10),
100-
Description: "Purchase several instances this time, the default value is 1. The value does not exceed 10.",
92+
Description: "Pay type of the SQL Server basic instance. For now, only `POSTPAID_BY_HOUR` is valid.",
10193
},
10294
"vpc_id": {
10395
Type: schema.TypeString,
@@ -116,7 +108,7 @@ func resourceTencentCloudSqlserverBasicInstance() *schema.Resource {
116108
ForceNew: true,
117109
Optional: true,
118110
Default: "2008R2",
119-
Description: "Version of the SQL Server Basic database engine. Allowed values are `2008R2`(SQL Server 2008 Enerprise), `2012SP3`(SQL Server 2012 Enterprise), `2016SP1` (SQL Server 2016 Enterprise), `201602`(SQL Server 2016 Standard) and `2017`(SQL Server 2017 Enterprise). Default is `2008R2`.",
111+
Description: "Version of the SQL Server basic database engine. Allowed values are `2008R2`(SQL Server 2008 Enerprise), `2012SP3`(SQL Server 2012 Enterprise), `2016SP1` (SQL Server 2016 Enterprise), `201602`(SQL Server 2016 Standard) and `2017`(SQL Server 2017 Enterprise). Default is `2008R2`.",
120112
},
121113
"period": {
122114
Type: schema.TypeInt,
@@ -197,17 +189,17 @@ func resourceTencentCloudSqlserverBasicInstance() *schema.Resource {
197189
"create_time": {
198190
Type: schema.TypeString,
199191
Computed: true,
200-
Description: "Create time of the SQL Server Basic instance.",
192+
Description: "Create time of the SQL Server basic instance.",
201193
},
202194
"status": {
203195
Type: schema.TypeInt,
204196
Computed: true,
205-
Description: "Status of the SQL Server Basic instance. 1 for applying, 2 for running, 3 for running with limit, 4 for isolated, 5 for recycling, 6 for recycled, 7 for running with task, 8 for off-line, 9 for expanding, 10 for migrating, 11 for readonly, 12 for rebooting.",
197+
Description: "Status of the SQL Server basic instance. 1 for applying, 2 for running, 3 for running with limit, 4 for isolated, 5 for recycling, 6 for recycled, 7 for running with task, 8 for off-line, 9 for expanding, 10 for migrating, 11 for readonly, 12 for rebooting.",
206198
},
207199
"tags": {
208200
Type: schema.TypeMap,
209201
Optional: true,
210-
Description: "The tags of the SQL Server Basic instance.",
202+
Description: "The tags of the SQL Server basic instance.",
211203
},
212204
},
213205
}
@@ -247,7 +239,6 @@ func resourceTencentCloudSqlserverBasicInstanceCreate(d *schema.ResourceData, me
247239
paramMap["vpcId"] = d.Get("vpc_id").(string)
248240
paramMap["machineType"] = d.Get("machine_type").(string)
249241
paramMap["payType"] = payType
250-
paramMap["goodsNum"] = d.Get("goods_num").(int)
251242
paramMap["engineVersion"] = d.Get("engine_version").(string)
252243
paramMap["period"] = d.Get("period").(int)
253244
paramMap["autoVoucher"] = d.Get("auto_voucher").(int)
@@ -348,12 +339,14 @@ func resourceTencentCloudSqlserverBasicInstanceRead(d *schema.ResourceData, meta
348339
_ = d.Set("machine_type", instance.Type)
349340
if int(*chargeType) == 1 {
350341
_ = d.Set("charge_type", COMMON_PAYTYPE_PREPAID)
342+
_ = d.Set("auto_renew", instance.RenewFlag)
351343
} else {
352344
_ = d.Set("charge_type", COMMON_PAYTYPE_POSTPAID)
345+
_ = d.Set("auto_renew", 0)
353346
}
354347
_ = d.Set("name", instance.Name)
355348
_ = d.Set("engine_version", instance.Version)
356-
_ = d.Set("auto_renew", instance.RenewFlag)
349+
357350
_ = d.Set("availability_zone", instance.Zone)
358351
_ = d.Set("project_id", instance.ProjectId)
359352
_ = d.Set("create_time", instance.CreateTime)
@@ -646,7 +639,7 @@ func resourceTencentCLoudSqlserverBasicInstanceDelete(d *schema.ResourceData, me
646639
return retryError(inErr)
647640
}
648641
if has {
649-
inErr = fmt.Errorf("delete SQL Server Basic instance %s fail, instance still exists from SDK DescribeSqlserverInstanceById", instanceId)
642+
inErr = fmt.Errorf("delete SQL Server basic instance %s fail, instance still exists from SDK DescribeSqlserverInstanceById", instanceId)
650643
return resource.RetryableError(inErr)
651644
}
652645
return nil

tencentcloud/resource_tc_sqlserver_basic_instance_test.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func TestAccTencentCloudSqlserverBasicInstanceResource(t *testing.T) {
4040
resource.TestCheckResourceAttrSet(testSqlserverBasicInstanceResourceKey, "auto_renew"),
4141
resource.TestCheckResourceAttr(testSqlserverBasicInstanceResourceKey, "security_groups.#", "1"),
4242
resource.TestCheckResourceAttr(testSqlserverBasicInstanceResourceKey, "tags.test", "test"),
43-
resource.TestCheckResourceAttr(testSqlserverBasicInstanceResourceKey, "goods_num", "1"),
4443
resource.TestCheckResourceAttr(testSqlserverBasicInstanceResourceKey, "maintenance_start_time", "09:00"),
4544
resource.TestCheckResourceAttr(testSqlserverBasicInstanceResourceKey, "maintenance_time_span", "3"),
4645
resource.TestCheckResourceAttr(testSqlserverBasicInstanceResourceKey, "maintenance_week_set.#", "3"),
@@ -77,7 +76,7 @@ func TestAccTencentCloudSqlserverBasicInstanceResource(t *testing.T) {
7776
ResourceName: testSqlserverBasicInstanceResourceKey,
7877
ImportState: true,
7978
ImportStateVerify: true,
80-
ImportStateVerifyIgnore: []string{"auto_voucher", "goods_num", "period"},
79+
ImportStateVerifyIgnore: []string{"auto_voucher", "period"},
8180
},
8281
},
8382
})
@@ -157,7 +156,6 @@ resource "tencentcloud_sqlserver_basic_instance" "test" {
157156
storage = 20
158157
cpu = 1
159158
machine_type = "CLOUD_PREMIUM"
160-
goods_num = 1
161159
maintenance_week_set = [1,2,3]
162160
maintenance_start_time = "09:00"
163161
maintenance_time_span = 3
@@ -181,7 +179,6 @@ resource "tencentcloud_sqlserver_basic_instance" "test" {
181179
storage = 100
182180
cpu = 1
183181
machine_type = "CLOUD_PREMIUM"
184-
goods_num = 1
185182
maintenance_week_set = [1,2,3,4]
186183
maintenance_start_time = "08:00"
187184
maintenance_time_span = 4

tencentcloud/service_tencentcloud_sqlserver.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,6 @@ func (me *SqlserverService) CreateSqlserverBasicInstance(ctx context.Context, pa
14011401
vpcId = paramMap["vpcId"].(string)
14021402
machineType = paramMap["machineType"].(string)
14031403
payType = paramMap["payType"].(string)
1404-
goodsNum = paramMap["goodsNum"].(int)
14051404
dbVersion = paramMap["engineVersion"].(string)
14061405
period = paramMap["period"].(int)
14071406
autoRenew = paramMap["autoRenew"].(int)
@@ -1415,7 +1414,7 @@ func (me *SqlserverService) CreateSqlserverBasicInstance(ctx context.Context, pa
14151414
request.VpcId = &vpcId
14161415
request.MachineType = &machineType
14171416
request.InstanceChargeType = &payType
1418-
request.GoodsNum = helper.IntUint64(goodsNum)
1417+
request.GoodsNum = helper.IntUint64(1)
14191418
request.DBVersion = &dbVersion
14201419
request.Period = helper.IntInt64(period)
14211420
request.AutoRenewFlag = helper.IntInt64(autoRenew)
@@ -1496,21 +1495,23 @@ func (me *SqlserverService) UpgradeSqlserverBasicInstance(ctx context.Context, i
14961495
return err
14971496
}
14981497

1499-
//check status not expanding
1498+
// prepaid expansion number of retries
15001499
retryCount := 0
15011500
errRet = resource.Retry(10*readRetryTimeout, func() *resource.RetryError {
15021501
instance, has, err := me.DescribeSqlserverInstanceById(ctx, instanceId)
15031502
if err != nil {
15041503
return resource.NonRetryableError(errors.WithStack(err))
15051504
}
15061505
if !has {
1507-
return resource.NonRetryableError(fmt.Errorf("cannot find SQL Server Basic instance %s", instanceId))
1506+
return resource.NonRetryableError(fmt.Errorf("cannot find SQL Server basic instance %s", instanceId))
15081507
}
1508+
// Status == 9, expanding
15091509
if int(*instance.Status) == 9 {
1510-
return resource.RetryableError(fmt.Errorf("expanding , SQL Server Basic instance ID %s, status %d.... ", instanceId, *instance.Status))
1511-
} else if int(*instance.Status) == 2 && *instance.PayMode == 1 && retryCount < 2 {
1510+
return resource.RetryableError(fmt.Errorf("expanding , SQL Server basic instance ID %s, status %d.... ", instanceId, *instance.Status))
1511+
// After UpgradeDBInstance of the prepaid instance, the status does not immediately change to 9 and is still 2, so we need to query it again
1512+
} else if *instance.PayMode == 1 && int(*instance.Status) == 2 && retryCount < 2 {
15121513
retryCount++
1513-
return resource.RetryableError(fmt.Errorf("expanding , SQL Server Basic Prepaid instance ID %s, status %d.... ", instanceId, *instance.Status))
1514+
return resource.RetryableError(fmt.Errorf("expanding , SQL Server basic Prepaid instance ID %s, status %d.... ", instanceId, *instance.Status))
15141515
} else {
15151516
return nil
15161517
}

website/docs/d/sqlserver_basic_instances.html.markdown

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ layout: "tencentcloud"
44
page_title: "TencentCloud: tencentcloud_sqlserver_basic_instances"
55
sidebar_current: "docs-tencentcloud-datasource-sqlserver_basic_instances"
66
description: |-
7-
Use this data source to query SQL Server Basic instances
7+
Use this data source to query SQL Server basic instances
88
---
99

1010
# tencentcloud_sqlserver_basic_instances
1111

12-
Use this data source to query SQL Server Basic instances
12+
Use this data source to query SQL Server basic instances
1313

1414
## Example Usage
1515

@@ -37,30 +37,30 @@ resource "tencentcloud_sqlserver_basic_instance" "test" {
3737

3838
The following arguments are supported:
3939

40-
* `id` - (Optional) ID of the SQL Server Basic instance to be query.
41-
* `project_id` - (Optional) Project ID of the SQL Server Basic instance to be query.
40+
* `id` - (Optional) ID of the SQL Server basic instance to be query.
41+
* `project_id` - (Optional) Project ID of the SQL Server basic instance to be query.
4242
* `result_output_file` - (Optional) Used to save results.
43-
* `subnet_id` - (Optional) Subnet ID of the SQL Server Basic instance to be query.
44-
* `vpc_id` - (Optional) Vpc ID of the SQL Server Basic instance to be query.
43+
* `subnet_id` - (Optional) Subnet ID of the SQL Server basic instance to be query.
44+
* `vpc_id` - (Optional) Vpc ID of the SQL Server basic instance to be query.
4545

4646
## Attributes Reference
4747

4848
In addition to all arguments above, the following attributes are exported:
4949

50-
* `instance_list` - A list of SQL Server Basic instances. Each element contains the following attributes.
50+
* `instance_list` - A list of SQL Server basic instances. Each element contains the following attributes.
5151
* `availability_zone` - Availability zone.
52-
* `charge_type` - Pay type of the SQL Server Basic instance. For now, only `POSTPAID_BY_HOUR` is valid.
53-
* `cpu` - The CPU number of the SQL Server Basic instance.
54-
* `create_time` - Create time of the SQL Server Basic instance.
55-
* `engine_version` - Version of the SQL Server Basic database engine. Allowed values are `2008R2`(SQL Server 2008 Enerprise), `2012SP3`(SQL Server 2012 Enterprise), `2016SP1` (SQL Server 2016 Enterprise), `201602`(SQL Server 2016 Standard) and `2017`(SQL Server 2017 Enterprise). Default is `2008R2`.
56-
* `id` - ID of the SQL Server Basic instance.
52+
* `charge_type` - Pay type of the SQL Server basic instance. For now, only `POSTPAID_BY_HOUR` is valid.
53+
* `cpu` - The CPU number of the SQL Server basic instance.
54+
* `create_time` - Create time of the SQL Server basic instance.
55+
* `engine_version` - Version of the SQL Server basic database engine. Allowed values are `2008R2`(SQL Server 2008 Enerprise), `2012SP3`(SQL Server 2012 Enterprise), `2016SP1` (SQL Server 2016 Enterprise), `201602`(SQL Server 2016 Standard) and `2017`(SQL Server 2017 Enterprise). Default is `2008R2`.
56+
* `id` - ID of the SQL Server basic instance.
5757
* `memory` - Memory size (in GB). Allowed value must be larger than `memory` that data source `tencentcloud_sqlserver_specinfos` provides.
58-
* `name` - Name of the SQL Server Basic instance.
58+
* `name` - Name of the SQL Server basic instance.
5959
* `project_id` - Project ID, default value is 0.
60-
* `status` - Status of the SQL Server Basic instance. 1 for applying, 2 for running, 3 for running with limit, 4 for isolated, 5 for recycling, 6 for recycled, 7 for running with task, 8 for off-line, 9 for expanding, 10 for migrating, 11 for readonly, 12 for rebooting.
60+
* `status` - Status of the SQL Server basic instance. 1 for applying, 2 for running, 3 for running with limit, 4 for isolated, 5 for recycling, 6 for recycled, 7 for running with task, 8 for off-line, 9 for expanding, 10 for migrating, 11 for readonly, 12 for rebooting.
6161
* `storage` - Disk size (in GB). Allowed value must be a multiple of 10. The storage must be set with the limit of `storage_min` and `storage_max` which data source `tencentcloud_sqlserver_specinfos` provides.
6262
* `subnet_id` - ID of subnet.
63-
* `tags` - Tags of the SQL Server Basic instance.
63+
* `tags` - Tags of the SQL Server basic instance.
6464
* `used_storage` - Used storage.
6565
* `vip` - IP for private access.
6666
* `vpc_id` - ID of VPC.

0 commit comments

Comments
 (0)