diff --git a/tencentcloud/resource_tc_mysql_instance.go b/tencentcloud/resource_tc_mysql_instance.go index d305113936..a102c311eb 100644 --- a/tencentcloud/resource_tc_mysql_instance.go +++ b/tencentcloud/resource_tc_mysql_instance.go @@ -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, @@ -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 } @@ -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 @@ -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 { @@ -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 @@ -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) @@ -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 @@ -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" +} diff --git a/tencentcloud/resource_tc_mysql_instance_test.go b/tencentcloud/resource_tc_mysql_instance_test.go index edc73faeef..c07a0dbddb 100644 --- a/tencentcloud/resource_tc_mysql_instance_test.go +++ b/tencentcloud/resource_tc_mysql_instance_test.go @@ -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) }, @@ -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" { @@ -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 @@ -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 }` } diff --git a/tencentcloud/resource_tc_mysql_readonly_instance.go b/tencentcloud/resource_tc_mysql_readonly_instance.go index 508a71011b..d2ac3a2b1e 100644 --- a/tencentcloud/resource_tc_mysql_readonly_instance.go +++ b/tencentcloud/resource_tc_mysql_readonly_instance.go @@ -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 diff --git a/tencentcloud/service_tencentcloud_mysql.go b/tencentcloud/service_tencentcloud_mysql.go index d282c5e54d..df4b56fc2a 100644 --- a/tencentcloud/service_tencentcloud_mysql.go +++ b/tencentcloud/service_tencentcloud_mysql.go @@ -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) @@ -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 { diff --git a/website/docs/r/mysql_instance.html.markdown b/website/docs/r/mysql_instance.html.markdown index 7bfb76eb80..16c44f9cbc 100644 --- a/website/docs/r/mysql_instance.html.markdown +++ b/website/docs/r/mysql_instance.html.markdown @@ -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. diff --git a/website/docs/r/mysql_readonly_instance.html.markdown b/website/docs/r/mysql_readonly_instance.html.markdown index 9371aa69e5..50727aa01c 100644 --- a/website/docs/r/mysql_readonly_instance.html.markdown +++ b/website/docs/r/mysql_readonly_instance.html.markdown @@ -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`.