Skip to content

Commit c226217

Browse files
committed
make default with -1 not "" cause "" will recognized with 0 which means prepaid in mysql
1 parent 5fcd2d6 commit c226217

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

tencentcloud/resource_tc_mysql_instance.go

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Example Usage
99
resource "tencentcloud_mysql_instance" "default" {
1010
internet_service = 1
1111
engine_version = "5.7"
12-
12+
charge_type = "POSTPAID"
1313
root_password = "********"
1414
slave_deploy_mode = 0
1515
first_slave_zone = "ap-guangzhou-4"
@@ -65,7 +65,10 @@ func TencentMsyqlBasicInfo() map[string]*schema.Schema {
6565
Optional: true,
6666
ValidateFunc: validateAllowedIntValue([]int{MysqlPayByMonth, MysqlPayByUse}),
6767
ConflictsWith: []string{"charge_type", "prepaid_period"},
68-
//Default: MysqlPayByUse,
68+
DiffSuppressFunc: func(k, olds, news string, d *schema.ResourceData) bool {
69+
return true
70+
},
71+
Default: -1,
6972
Description: "Pay type of instance, 0: prepaid, 1: postpaid.",
7073
},
7174
"charge_type": {
@@ -95,18 +98,24 @@ func TencentMsyqlBasicInfo() map[string]*schema.Schema {
9598
Type: schema.TypeInt,
9699
Deprecated: "It has been deprecated from version 1.36.0.",
97100
Optional: true,
98-
Default: 1,
101+
Default: -1,
99102
ConflictsWith: []string{"charge_type", "prepaid_period"},
100103
ValidateFunc: validateAllowedIntValue(MYSQL_AVAILABLE_PERIOD),
101-
Description: "Period of instance. NOTES: Only supported prepaid instance.",
104+
DiffSuppressFunc: func(k, olds, news string, d *schema.ResourceData) bool {
105+
return true
106+
},
107+
Description: "Period of instance. NOTES: Only supported prepaid instance.",
102108
},
103109
"prepaid_period": {
104110
Type: schema.TypeInt,
105111
Optional: true,
106112
Default: 1,
107113
ConflictsWith: []string{"pay_type", "period"},
108-
ValidateFunc: validateAllowedIntValue(MYSQL_AVAILABLE_PERIOD),
109-
Description: "Period of instance. NOTES: Only supported prepaid instance.",
114+
DiffSuppressFunc: func(k, olds, news string, d *schema.ResourceData) bool {
115+
return true
116+
},
117+
ValidateFunc: validateAllowedIntValue(MYSQL_AVAILABLE_PERIOD),
118+
Description: "Period of instance. NOTES: Only supported prepaid instance.",
110119
},
111120
"auto_renew_flag": {
112121
Type: schema.TypeInt,
@@ -501,9 +510,9 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData,
501510

502511
request := cdb.NewCreateDBInstanceRequest()
503512

504-
_, oldOk := d.GetOkExists("pay_type")
513+
payType, oldOk := d.GetOkExists("pay_type")
505514
var period int
506-
if !oldOk {
515+
if !oldOk || payType == -1 {
507516
period = d.Get("prepaid_period").(int)
508517
} else {
509518
period = d.Get("period").(int)
@@ -676,24 +685,16 @@ func tencentMsyqlBasicInfoRead(ctx context.Context, d *schema.ResourceData, meta
676685
d.SetId("")
677686
return
678687
}
679-
_ = d.Set("instance_name", *mysqlInfo.InstanceName)
680-
681-
_, oldOk := d.GetOkExists("pay_type")
682-
var periodKey string
683-
if oldOk {
684-
_ = d.Set("pay_type", int(*mysqlInfo.PayType))
685-
periodKey = "period"
686-
} else {
687-
periodKey = "prepaid_period"
688-
689-
_ = d.Set("charge_type", MYSQL_CHARGE_TYPE[int(*mysqlInfo.PayType)])
690688

691-
}
689+
_ = d.Set("instance_name", *mysqlInfo.InstanceName)
692690

691+
_ = d.Set("charge_type", MYSQL_CHARGE_TYPE[int(*mysqlInfo.PayType)])
692+
_ = d.Set("pay_type", -1)
693+
_ = d.Set("period", -1)
693694
if int(*mysqlInfo.PayType) == MysqlPayByMonth {
694-
tempInt, _ := d.Get(periodKey).(int)
695+
tempInt, _ := d.Get("prepaid_period").(int)
695696
if tempInt == 0 {
696-
_ = d.Set(periodKey, 1)
697+
_ = d.Set("prepaid_period", 1)
697698
}
698699
}
699700

@@ -1352,7 +1353,7 @@ func getPayType(d *schema.ResourceData) (payType interface{}) {
13521353
chargeType := d.Get("charge_type")
13531354
payType, oldOk := d.GetOkExists("pay_type")
13541355

1355-
if !oldOk {
1356+
if !oldOk || payType == -1 {
13561357
if chargeType == MYSQL_CHARGE_TYPE_PREPAID {
13571358
payType = MysqlPayByMonth
13581359
} else {

website/docs/r/mysql_instance.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Provides a mysql instance resource to create master database instances.
1616

1717
```hcl
1818
resource "tencentcloud_mysql_instance" "default" {
19-
internet_service = 1
20-
engine_version = "5.7"
21-
19+
internet_service = 1
20+
engine_version = "5.7"
21+
charge_type = "POSTPAID"
2222
root_password = "********"
2323
slave_deploy_mode = 0
2424
first_slave_zone = "ap-guangzhou-4"

0 commit comments

Comments
 (0)