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
47 changes: 39 additions & 8 deletions tencentcloud/resource_tc_mysql_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ func TencentMsyqlBasicInfo() map[string]*schema.Schema {
Optional: true,
Description: "Specify whether to enable fast upgrade when upgrade instance spec, available value: `1` - enabled, `0` - disabled.",
},
"device_type": {
Type: schema.TypeString,
Optional: true,
Description: "Specify device type, available values: `UNIVERSAL` (default), `EXCLUSIVE`, `BASIC`.",
},
"tags": {
Type: schema.TypeMap,
Optional: true,
Expand Down Expand Up @@ -448,6 +453,15 @@ func mysqlAllInstanceRoleSet(ctx context.Context, requestInter interface{}, d *s
requestByUse.ParamTemplateId = paramTemplateId
}
}

if v, ok := d.GetOk("device_type"); ok {
deviceType := helper.String(v.(string))
if okByMonth {
requestByMonth.DeviceType = deviceType
} else {
requestByUse.DeviceType = deviceType
}
}
return nil

}
Expand All @@ -459,7 +473,8 @@ func mysqlMasterInstanceRoleSet(ctx context.Context, requestInter interface{}, d
requestByMonth, okByMonth := requestInter.(*cdb.CreateDBInstanceRequest)
requestByUse, _ := requestInter.(*cdb.CreateDBInstanceHourRequest)

if parametersMap, ok := d.Get("parameters").(map[string]interface{}); ok {
isBasic := isBasicDevice(d)
if parametersMap, ok := d.Get("parameters").(map[string]interface{}); ok && !isBasic {
requestParamList := make([]*cdb.ParamInfo, 0, len(parametersMap))
for k, v := range parametersMap {
key := k
Expand Down Expand Up @@ -498,8 +513,8 @@ func mysqlMasterInstanceRoleSet(ctx context.Context, requestInter interface{}, d
}
}

if stringInterface, ok := d.GetOk("root_password"); ok {
str := stringInterface.(string)
if v, ok := d.GetOk("root_password"); ok && v.(string) != "" && !isBasic {
str := v.(string)
if okByMonth {
requestByMonth.Password = &str
} else {
Expand Down Expand Up @@ -672,10 +687,8 @@ func resourceTencentCloudMysqlInstanceCreate(d *schema.ResourceData, meta interf
vPort int
)

if v, ok := d.GetOk("root_password"); ok && v.(string) != "" {
if v, ok := d.GetOk("root_password"); ok {
password = v.(string)
} else {
return fmt.Errorf("`root_password` cannot be empty when creating")
}

// 8.0 does not support lower_case_table_names modified, skip this params
Expand Down Expand Up @@ -817,6 +830,11 @@ func tencentMsyqlBasicInfoRead(ctx context.Context, d *schema.ResourceData, meta
errRet = d.Set("subnet_id", mysqlInfo.UniqSubnetId)
}

isUniversal := mysqlInfo.DeviceType != nil && *mysqlInfo.DeviceType == "UNIVERSAL"
if _, ok := d.GetOk("device_type"); ok || !isUniversal {
_ = d.Set("device_type", mysqlInfo.DeviceType)
}

securityGroups, err := mysqlService.DescribeDBSecurityGroups(ctx, d.Id())
if err != nil {
sdkErr, ok := err.(*errors.TencentCloudSDKError)
Expand Down Expand Up @@ -1022,17 +1040,22 @@ func mysqlAllInstanceRoleUpdate(ctx context.Context, d *schema.ResourceData, met
}
}

if d.HasChange("mem_size") || d.HasChange("cpu") || d.HasChange("volume_size") {
if d.HasChange("mem_size") || d.HasChange("cpu") || d.HasChange("volume_size") || d.HasChange("device_type") {

memSize := int64(d.Get("mem_size").(int))
cpu := int64(d.Get("cpu").(int))
volumeSize := int64(d.Get("volume_size").(int))
deviceType := ""

fastUpgrade := int64(0)
if v, ok := d.GetOk("fast_upgrade"); ok {
fastUpgrade = int64(v.(int))
}
if v, ok := d.GetOk("device_type"); ok {
deviceType = v.(string)
}

asyncRequestId, err := mysqlService.UpgradeDBInstance(ctx, d.Id(), memSize, cpu, volumeSize, fastUpgrade)
asyncRequestId, err := mysqlService.UpgradeDBInstance(ctx, d.Id(), memSize, cpu, volumeSize, fastUpgrade, deviceType)

if err != nil {
return err
Expand Down Expand Up @@ -1470,3 +1493,11 @@ func getPayType(d *schema.ResourceData) (payType interface{}) {
}
return
}

func isBasicDevice(d *schema.ResourceData) bool {
v, ok := d.GetOk("device_type")
if !ok {
return false
}
return v.(string) == "BASIC"
}
80 changes: 75 additions & 5 deletions tencentcloud/resource_tc_mysql_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,36 @@ func testSweepMySQLInstance(region string) error {
return nil
}

func TestAccTencentCloudMysqlDeviceType(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMysqlMasterInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccMySQLDeviceType,
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckMysqlMasterInstanceExists("tencentcloud_mysql_instance.mysql_exclusive"),
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_exclusive", "device_type", "EXCLUSIVE"),
),
},
{
ResourceName: "tencentcloud_mysql_instance.mysql_exclusive",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"root_password", "prepaid_period", "first_slave_zone", "force_delete", "param_template_id", "fast_upgrade"},
},
{
Config: testAccMySQLDeviceTypeUpdate,
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckMysqlMasterInstanceExists("tencentcloud_mysql_instance.mysql_exclusive"),
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.mysql_exclusive", "device_type", "EXCLUSIVE"),
),
},
},
})
}

func TestAccTencentCloudMysqlMasterInstance_fullslave(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -276,6 +306,51 @@ func testAccCheckMysqlMasterInstanceExists(n string) resource.TestCheckFunc {
}
}

const testAccMySQLDeviceType = `
variable "temporary_param_tmpl_id" {
default = 16954
}

resource "tencentcloud_mysql_instance" "mysql_exclusive" {
charge_type = "POSTPAID"
mem_size = 16000
cpu = 2
volume_size = 50
instance_name = "testAccMysqlBasic"
engine_version = "5.7"
intranet_port = 3360
root_password = "test1234"
availability_zone = "ap-guangzhou-3"
first_slave_zone = "ap-guangzhou-3"
force_delete = true
device_type = "EXCLUSIVE"
param_template_id = var.temporary_param_tmpl_id
}
`

const testAccMySQLDeviceTypeUpdate = `
variable "temporary_param_tmpl_id" {
default = 16954
}

resource "tencentcloud_mysql_instance" "mysql_exclusive" {
charge_type = "POSTPAID"
mem_size = 16000
cpu = 2
volume_size = 50
instance_name = "testAccMysql"
engine_version = "5.7"
intranet_port = 3360
root_password = "test1234"
availability_zone = "ap-guangzhou-3"
first_slave_zone = "ap-guangzhou-3"
force_delete = true
device_type = "EXCLUSIVE"
fast_upgrade = 1
param_template_id = var.temporary_param_tmpl_id
}
`

func testAccMysqlMasterInstance_basic() string {
return `
resource "tencentcloud_mysql_instance" "mysql_master" {
Expand All @@ -294,10 +369,6 @@ resource "tencentcloud_mysql_instance" "mysql_master" {

func testAccMysqlMasterInstance_fullslave() string {
return `
variable "temporary_param_tmpl_id" {
default = 16954
}

resource "tencentcloud_mysql_instance" "mysql_master" {
charge_type = "POSTPAID"
mem_size = 1000
Expand All @@ -311,7 +382,6 @@ resource "tencentcloud_mysql_instance" "mysql_master" {
first_slave_zone = "ap-guangzhou-3"
second_slave_zone = "ap-guangzhou-3"
slave_sync_mode = 2
param_template_id = var.temporary_param_tmpl_id
force_delete = true
}`
}
Expand Down
4 changes: 4 additions & 0 deletions tencentcloud/resource_tc_mysql_readonly_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ func mysqlCreateReadonlyInstancePayByMonth(ctx context.Context, d *schema.Resour
request.MasterRegion = &masterRegion
}

if v, ok := d.GetOk("device_type"); ok {
request.DeviceType = helper.String(v.(string))
}

autoRenewFlag := int64(d.Get("auto_renew_flag").(int))
request.AutoRenewFlag = &autoRenewFlag

Expand Down
5 changes: 4 additions & 1 deletion tencentcloud/service_tencentcloud_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ func (me *MysqlService) ModifyDBInstanceVipVport(ctx context.Context, mysqlId, v
}

func (me *MysqlService) UpgradeDBInstance(ctx context.Context, mysqlId string,
memSize, cpu, volumeSize, fastUpgrade int64) (asyncRequestId string, errRet error) {
memSize, cpu, volumeSize, fastUpgrade int64, deviceType string) (asyncRequestId string, errRet error) {

logId := getLogId(ctx)

Expand All @@ -1121,6 +1121,9 @@ func (me *MysqlService) UpgradeDBInstance(ctx context.Context, mysqlId string,
request.Volume = &volumeSize
request.WaitSwitch = &waitSwitch
request.FastUpgrade = &fastUpgrade
if deviceType != "" {
request.DeviceType = &deviceType
}

defer func() {
if errRet != nil {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/mysql_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ The following arguments are supported:
* `availability_zone` - (Optional, ForceNew) Indicates which availability zone will be used.
* `charge_type` - (Optional, ForceNew) Pay type of instance. Valid values:`PREPAID`, `POSTPAID`. Default is `POSTPAID`.
* `cpu` - (Optional) CPU cores.
* `device_type` - (Optional) Specify device type, available values: `UNIVERSAL` (default), `EXCLUSIVE`, `BASIC`.
* `engine_version` - (Optional, ForceNew) The version number of the database engine to use. Supported versions include 5.5/5.6/5.7/8.0, and default is 5.7.
* `fast_upgrade` - (Optional) Specify whether to enable fast upgrade when upgrade instance spec, available value: `1` - enabled, `0` - disabled.
* `first_slave_zone` - (Optional, ForceNew) Zone information about first slave instance.
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/mysql_readonly_instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ The following arguments are supported:
* `auto_renew_flag` - (Optional) Auto renew flag. NOTES: Only supported prepaid instance.
* `charge_type` - (Optional, ForceNew) Pay type of instance. Valid values:`PREPAID`, `POSTPAID`. Default is `POSTPAID`.
* `cpu` - (Optional) CPU cores.
* `device_type` - (Optional) Specify device type, available values: `UNIVERSAL` (default), `EXCLUSIVE`, `BASIC`.
* `fast_upgrade` - (Optional) Specify whether to enable fast upgrade when upgrade instance spec, available value: `1` - enabled, `0` - disabled.
* `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. Valid value ranges: [1024~65535]. The default value is `3306`.
Expand Down