Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
BUG FIXES:

* Resource: `tencentcloud_instance` fix `allocate_public_ip` inconsistency when eip is attached to the cvm.
* Resource: `tencentcloud_mysql_instance` fix auto-forcenew on `charge_type` and `pay_type` when upgrading terraform version. ([#459](https://github.com/terraform-providers/terraform-provider-tencentcloud/pull/459)).

## 1.38.1 (June 30, 2020)

Expand Down
64 changes: 39 additions & 25 deletions tencentcloud/resource_tc_mysql_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Example Usage
resource "tencentcloud_mysql_instance" "default" {
internet_service = 1
engine_version = "5.7"

charge_type = "POSTPAID"
root_password = "********"
slave_deploy_mode = 0
first_slave_zone = "ap-guangzhou-4"
Expand Down Expand Up @@ -62,11 +62,13 @@ func TencentMsyqlBasicInfo() map[string]*schema.Schema {
"pay_type": {
Type: schema.TypeInt,
Deprecated: "It has been deprecated from version 1.36.0.",
ForceNew: true,
Optional: true,
ValidateFunc: validateAllowedIntValue([]int{MysqlPayByMonth, MysqlPayByUse}),
ConflictsWith: []string{"charge_type", "prepaid_period"},
//Default: MysqlPayByUse,
DiffSuppressFunc: func(k, olds, news string, d *schema.ResourceData) bool {
return true
},
Default: -1,
Description: "Pay type of instance, 0: prepaid, 1: postpaid.",
},
"charge_type": {
Expand All @@ -76,24 +78,44 @@ func TencentMsyqlBasicInfo() map[string]*schema.Schema {
ValidateFunc: validateAllowedStringValue([]string{MYSQL_CHARGE_TYPE_PREPAID, MYSQL_CHARGE_TYPE_POSTPAID}),
ConflictsWith: []string{"pay_type", "period"},
Default: MYSQL_CHARGE_TYPE_POSTPAID,
Description: "Pay type of instance, valid values are `PREPAID`, `POSTPAID`. Default is `POSTPAID`.",
DiffSuppressFunc: func(k, olds, news string, d *schema.ResourceData) bool {
if (olds == "" && news == MYSQL_CHARGE_TYPE_POSTPAID) ||
(olds == MYSQL_CHARGE_TYPE_POSTPAID && news == "") {
if v, ok := d.GetOkExists("pay_type"); ok && v.(int) == MysqlPayByUse {
return true
}
} else if (olds == "" && news == MYSQL_CHARGE_TYPE_PREPAID) ||
(olds == MYSQL_CHARGE_TYPE_PREPAID && news == "") {
if v, ok := d.GetOkExists("pay_type"); ok && v.(int) == MysqlPayByMonth {
return true
}
}
return olds == news
},
Description: "Pay type of instance, valid values are `PREPAID`, `POSTPAID`. Default is `POSTPAID`.",
},
"period": {
Type: schema.TypeInt,
Deprecated: "It has been deprecated from version 1.36.0.",
Optional: true,
Default: 1,
Default: -1,
ConflictsWith: []string{"charge_type", "prepaid_period"},
ValidateFunc: validateAllowedIntValue(MYSQL_AVAILABLE_PERIOD),
Description: "Period of instance. NOTES: Only supported prepaid instance.",
DiffSuppressFunc: func(k, olds, news string, d *schema.ResourceData) bool {
return true
},
Description: "Period of instance. NOTES: Only supported prepaid instance.",
},
"prepaid_period": {
Type: schema.TypeInt,
Optional: true,
Default: 1,
ConflictsWith: []string{"pay_type", "period"},
ValidateFunc: validateAllowedIntValue(MYSQL_AVAILABLE_PERIOD),
Description: "Period of instance. NOTES: Only supported prepaid instance.",
DiffSuppressFunc: func(k, olds, news string, d *schema.ResourceData) bool {
return true
},
ValidateFunc: validateAllowedIntValue(MYSQL_AVAILABLE_PERIOD),
Description: "Period of instance. NOTES: Only supported prepaid instance.",
},
"auto_renew_flag": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -488,9 +510,9 @@ func mysqlCreateInstancePayByMonth(ctx context.Context, d *schema.ResourceData,

request := cdb.NewCreateDBInstanceRequest()

_, oldOk := d.GetOkExists("pay_type")
payType, oldOk := d.GetOkExists("pay_type")
var period int
if !oldOk {
if !oldOk || payType == -1 {
period = d.Get("prepaid_period").(int)
} else {
period = d.Get("period").(int)
Expand Down Expand Up @@ -663,24 +685,16 @@ func tencentMsyqlBasicInfoRead(ctx context.Context, d *schema.ResourceData, meta
d.SetId("")
return
}
_ = d.Set("instance_name", *mysqlInfo.InstanceName)

_, oldOk := d.GetOkExists("pay_type")
var periodKey string
if oldOk {
_ = d.Set("pay_type", int(*mysqlInfo.PayType))
periodKey = "period"
} else {
periodKey = "prepaid_period"

_ = d.Set("charge_type", MYSQL_CHARGE_TYPE[int(*mysqlInfo.PayType)])

}
_ = d.Set("instance_name", *mysqlInfo.InstanceName)

_ = d.Set("charge_type", MYSQL_CHARGE_TYPE[int(*mysqlInfo.PayType)])
_ = d.Set("pay_type", -1)
_ = d.Set("period", -1)
if int(*mysqlInfo.PayType) == MysqlPayByMonth {
tempInt, _ := d.Get(periodKey).(int)
tempInt, _ := d.Get("prepaid_period").(int)
if tempInt == 0 {
_ = d.Set(periodKey, 1)
_ = d.Set("prepaid_period", 1)
}
}

Expand Down Expand Up @@ -1339,7 +1353,7 @@ func getPayType(d *schema.ResourceData) (payType interface{}) {
chargeType := d.Get("charge_type")
payType, oldOk := d.GetOkExists("pay_type")

if !oldOk {
if !oldOk || payType == -1 {
if chargeType == MYSQL_CHARGE_TYPE_PREPAID {
payType = MysqlPayByMonth
} else {
Expand Down
8 changes: 4 additions & 4 deletions website/docs/r/mysql_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Provides a mysql instance resource to create master database instances.

```hcl
resource "tencentcloud_mysql_instance" "default" {
internet_service = 1
engine_version = "5.7"

internet_service = 1
engine_version = "5.7"
charge_type = "POSTPAID"
root_password = "********"
slave_deploy_mode = 0
first_slave_zone = "ap-guangzhou-4"
Expand Down Expand Up @@ -61,7 +61,7 @@ The following arguments are supported:
* `internet_service` - (Optional) Indicates whether to enable the access to an instance from public network: 0 - No, 1 - Yes.
* `intranet_port` - (Optional) Public access port, rang form 1024 to 65535 and default value is 3306.
* `parameters` - (Optional) List of parameters to use.
* `pay_type` - (Optional, ForceNew, **Deprecated**) It has been deprecated from version 1.36.0. Pay type of instance, 0: prepaid, 1: postpaid.
* `pay_type` - (Optional, **Deprecated**) It has been deprecated from version 1.36.0. Pay type of instance, 0: prepaid, 1: postpaid.
* `period` - (Optional, **Deprecated**) It has been deprecated from version 1.36.0. Period of instance. NOTES: Only supported prepaid instance.
* `prepaid_period` - (Optional) Period of instance. NOTES: Only supported prepaid instance.
* `project_id` - (Optional) Project ID, default value is 0.
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/mysql_readonly_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ The following arguments are supported:
* `charge_type` - (Optional, ForceNew) Pay type of instance, valid values are `PREPAID`, `POSTPAID`. Default is `POSTPAID`.
* `force_delete` - (Optional) Indicate whether to delete instance directly or not. Default is false. If set true, the instance will be deleted instead of staying recycle bin. Note: only works for `PREPAID` instance. When the main mysql instance set true, this para of the readonly mysql instance will not take effect.
* `intranet_port` - (Optional) Public access port, rang form 1024 to 65535 and default value is 3306.
* `pay_type` - (Optional, ForceNew, **Deprecated**) It has been deprecated from version 1.36.0. Pay type of instance, 0: prepaid, 1: postpaid.
* `pay_type` - (Optional, **Deprecated**) It has been deprecated from version 1.36.0. Pay type of instance, 0: prepaid, 1: postpaid.
* `period` - (Optional, **Deprecated**) It has been deprecated from version 1.36.0. Period of instance. NOTES: Only supported prepaid instance.
* `prepaid_period` - (Optional) Period of instance. NOTES: Only supported prepaid instance.
* `security_groups` - (Optional) Security groups to use.
Expand Down