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
16 changes: 16 additions & 0 deletions tencentcloud/basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ data "tencentcloud_instance_types" "default" {
}
`

const (
defaultMySQLName = "preset_mysql"
)

// ref with `local.mysql_id`
const CommonPresetMysql = `
data "tencentcloud_mysql_instance" "mysql" {
instance_name = "` + defaultMySQLName + `"
}

locals {
mysql_id = data.tencentcloud_mysql_instance.mysql.instance_list.0.mysql_id
}
`

const instanceCommonTestCase = defaultInstanceVariable + `
resource "tencentcloud_instance" "default" {
instance_name = var.instance_name
Expand Down Expand Up @@ -158,6 +173,7 @@ resource "tencentcloud_mysql_instance" "default" {
engine_version = "5.7"
root_password = "0153Y474"
availability_zone = var.availability_zone
force_delete = true
}
`

Expand Down
4 changes: 2 additions & 2 deletions tencentcloud/data_source_tc_mysql_backup_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ func TestAccDataSourceMysqlBackupList_basic(t *testing.T) {
}

func testAccDataSourceMysqlBackupListConfig() string {
return mysqlInstanceCommonTestCase + `
return CommonPresetMysql + `
data "tencentcloud_mysql_backup_list" "test" {
mysql_id = tencentcloud_mysql_instance.default.id
mysql_id = local.mysql_id
}`
}
16 changes: 7 additions & 9 deletions tencentcloud/data_source_tc_mysql_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ func TestAccTencentCloudMysqlInstanceDataSource(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccTencentCloudMysqlInstanceDataSourceConfig(mysqlInstanceCommonTestCase),
Config: testAccTencentCloudMysqlInstanceDataSourceConfig(),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("data.tencentcloud_mysql_instance.mysql", "instance_list.#", "1"),
resource.TestCheckResourceAttr("data.tencentcloud_mysql_instance.mysql", "instance_list.0.instance_name", "tf-ci-test"),
resource.TestCheckResourceAttr("data.tencentcloud_mysql_instance.mysql", "instance_list.0.instance_name", defaultMySQLName),
resource.TestCheckResourceAttr("data.tencentcloud_mysql_instance.mysql", "instance_list.0.pay_type", "1"),
resource.TestCheckResourceAttr("data.tencentcloud_mysql_instance.mysql", "instance_list.0.memory_size", "1000"),
resource.TestCheckResourceAttr("data.tencentcloud_mysql_instance.mysql", "instance_list.0.volume_size", "25"),
resource.TestCheckResourceAttr("data.tencentcloud_mysql_instance.mysql", "instance_list.0.memory_size", "4000"),
resource.TestCheckResourceAttr("data.tencentcloud_mysql_instance.mysql", "instance_list.0.volume_size", "200"),
resource.TestCheckResourceAttr("data.tencentcloud_mysql_instance.mysql", "instance_list.0.engine_version", "5.7"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_instance.mysql", "instance_list.0.vpc_id"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_instance.mysql", "instance_list.0.subnet_id"),
Expand All @@ -31,12 +31,10 @@ func TestAccTencentCloudMysqlInstanceDataSource(t *testing.T) {
})
}

func testAccTencentCloudMysqlInstanceDataSourceConfig(commonTestCase string) string {
func testAccTencentCloudMysqlInstanceDataSourceConfig() string {
return fmt.Sprintf(`
%s
data "tencentcloud_mysql_instance" "mysql" {
mysql_id = tencentcloud_mysql_instance.default.id
instance_name = tencentcloud_mysql_instance.default.instance_name
instance_name = "%s"
}
`, commonTestCase)
`, defaultMySQLName)
}
4 changes: 2 additions & 2 deletions tencentcloud/data_source_tc_mysql_parameter_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestAccTencentCloudMysqlParameterListDataSource(t *testing.T) {
),
},
{
Config: testAccMysqlParameterListDataSourceConfig(mysqlInstanceCommonTestCase),
Config: testAccMysqlParameterListDataSourceConfig(CommonPresetMysql),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_parameter_list.mysql", "parameter_list.#"),
resource.TestCheckResourceAttrSet("data.tencentcloud_mysql_parameter_list.mysql", "parameter_list.0.parameter_name"),
Expand All @@ -49,7 +49,7 @@ func testAccMysqlParameterListDataSourceConfig(commonTestCase string) string {
return fmt.Sprintf(`
%s
data "tencentcloud_mysql_parameter_list" "mysql" {
mysql_id = tencentcloud_mysql_instance.default.id
mysql_id = local.mysql_id
}
`, commonTestCase)
}
24 changes: 12 additions & 12 deletions tencentcloud/resource_tc_mysql_account_privilege_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAccTencentCloudMysqlAccountPrivilege(t *testing.T) {
CheckDestroy: testAccMysqlAccountPrivilegeDestroy,
Steps: []resource.TestStep{
{
Config: testAccMysqlAccountPrivilege(mysqlInstanceCommonTestCase),
Config: testAccMysqlAccountPrivilege(),
Check: resource.ComposeAggregateTestCheckFunc(
testAccMysqlAccountPrivilegeExists("tencentcloud_mysql_account_privilege.mysql_account_privilege"),
resource.TestCheckResourceAttrSet("tencentcloud_mysql_account_privilege.mysql_account_privilege", "mysql_id"),
Expand All @@ -36,7 +36,7 @@ func TestAccTencentCloudMysqlAccountPrivilege(t *testing.T) {
),
},
{
Config: testAccMysqlAccountPrivilegeUpdate(mysqlInstanceCommonTestCase),
Config: testAccMysqlAccountPrivilegeUpdate(),
Check: resource.ComposeAggregateTestCheckFunc(
testAccMysqlAccountPrivilegeExists("tencentcloud_mysql_account_privilege.mysql_account_privilege"),
resource.TestCheckResourceAttrSet("tencentcloud_mysql_account_privilege.mysql_account_privilege", "mysql_id"),
Expand Down Expand Up @@ -177,41 +177,41 @@ func testAccMysqlAccountPrivilegeDestroy(s *terraform.State) error {
return nil
}

func testAccMysqlAccountPrivilege(commonTestCase string) string {
func testAccMysqlAccountPrivilege() string {
return fmt.Sprintf(`
%s
resource "tencentcloud_mysql_account" "mysql_account" {
mysql_id = tencentcloud_mysql_instance.default.id
name = "test"
mysql_id = local.mysql_id
name = "previlege_test"
host = "119.168.110.%%"
password = "test1234"
description = "test from terraform"
}
resource "tencentcloud_mysql_account_privilege" "mysql_account_privilege" {
mysql_id = tencentcloud_mysql_instance.default.id
mysql_id = local.mysql_id
account_name = tencentcloud_mysql_account.mysql_account.name
account_host = tencentcloud_mysql_account.mysql_account.host
privileges = ["SELECT", "INSERT", "UPDATE", "DELETE"]
database_names = ["test"]
}`, commonTestCase)
}`, CommonPresetMysql)
}

func testAccMysqlAccountPrivilegeUpdate(commonTestCase string) string {
func testAccMysqlAccountPrivilegeUpdate() string {
return fmt.Sprintf(`
%s
resource "tencentcloud_mysql_account" "mysql_account" {
mysql_id = tencentcloud_mysql_instance.default.id
name = "test"
mysql_id = local.mysql_id
name = "previlege_test"
host = "119.168.110.%%"
password = "test1234"
description = "test from terraform"
}
resource "tencentcloud_mysql_account_privilege" "mysql_account_privilege" {
mysql_id = tencentcloud_mysql_instance.default.id
mysql_id = local.mysql_id
account_name = tencentcloud_mysql_account.mysql_account.name
account_host = tencentcloud_mysql_account.mysql_account.host
privileges = ["TRIGGER"]
database_names = ["test"]
}`, commonTestCase)
}`, CommonPresetMysql)

}
9 changes: 5 additions & 4 deletions tencentcloud/resource_tc_mysql_account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAccTencentCloudMysqlAccountResource(t *testing.T) {
CheckDestroy: testAccCheckMysqlAccountDestroy,
Steps: []resource.TestStep{
{
Config: testAccMysqlAccount(mysqlInstanceCommonTestCase),
Config: testAccMysqlAccount(),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckMysqlAccountExists("tencentcloud_mysql_account.mysql_account"),
resource.TestCheckResourceAttrSet("tencentcloud_mysql_account.mysql_account", "mysql_id"),
Expand Down Expand Up @@ -123,15 +123,16 @@ func testAccCheckMysqlAccountDestroy(s *terraform.State) error {
return nil
}

func testAccMysqlAccount(commonTestCase string) string {
func testAccMysqlAccount() string {
return fmt.Sprintf(`
%s

resource "tencentcloud_mysql_account" "mysql_account" {
mysql_id = tencentcloud_mysql_instance.default.id
mysql_id = local.mysql_id
name = "test"
host = "192.168.0.%%"
password = "test1234"
description = "test from terraform"
}
`, commonTestCase)
`, CommonPresetMysql)
}
16 changes: 8 additions & 8 deletions tencentcloud/resource_tc_mysql_backup_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestAccTencentCloudMysqlBackupPolicy(t *testing.T) {
CheckDestroy: testAccTencentCloudMysqlBackupPolicyDestroy,
Steps: []resource.TestStep{
{
Config: testAccMysqlBackupPolicy(mysqlInstanceCommonTestCase),
Config: testAccMysqlBackupPolicy(),
Check: resource.ComposeAggregateTestCheckFunc(
testAccTencentCloudMysqlBackupPolicyExists("tencentcloud_mysql_backup_policy.mysql_backup_policy"),
resource.TestCheckResourceAttrSet("tencentcloud_mysql_backup_policy.mysql_backup_policy", "mysql_id"),
Expand All @@ -29,7 +29,7 @@ func TestAccTencentCloudMysqlBackupPolicy(t *testing.T) {
),
},
{
Config: testAccMysqlBackupPolicyUpdate(mysqlInstanceCommonTestCase),
Config: testAccMysqlBackupPolicyUpdate(),
Check: resource.ComposeAggregateTestCheckFunc(
testAccTencentCloudMysqlBackupPolicyExists("tencentcloud_mysql_backup_policy.mysql_backup_policy"),
resource.TestCheckResourceAttrSet("tencentcloud_mysql_backup_policy.mysql_backup_policy", "mysql_id"),
Expand Down Expand Up @@ -105,22 +105,22 @@ func testAccTencentCloudMysqlBackupPolicyDestroy(s *terraform.State) error {
return nil
}

func testAccMysqlBackupPolicy(commonTestCase string) string {
func testAccMysqlBackupPolicy() string {
return fmt.Sprintf(`
%s
resource "tencentcloud_mysql_backup_policy" "mysql_backup_policy" {
mysql_id = tencentcloud_mysql_instance.default.id
mysql_id = local.mysql_id
retention_period = 56
backup_time = "10:00-14:00"
}`, commonTestCase)
}`, CommonPresetMysql)
}

func testAccMysqlBackupPolicyUpdate(commonTestCase string) string {
func testAccMysqlBackupPolicyUpdate() string {
return fmt.Sprintf(`
%s
resource "tencentcloud_mysql_backup_policy" "mysql_backup_policy" {
mysql_id = tencentcloud_mysql_instance.default.id
mysql_id = local.mysql_id
retention_period = 80
backup_time = "06:00-10:00"
}`, commonTestCase)
}`, CommonPresetMysql)
}
65 changes: 0 additions & 65 deletions tencentcloud/resource_tc_mysql_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,38 +227,6 @@ func TestAccTencentCloudMysqlMasterInstance_basic_and_update(t *testing.T) {
})
}

func TestAccTencentCloudMysqlPrepaid(t *testing.T) {
t.Parallel()
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckMysqlMasterInstanceDestroy,
Steps: []resource.TestStep{
{
Config: testAccMysqlMasterInstance_prepaid(),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckMysqlMasterInstanceExists("tencentcloud_mysql_instance.prepaid"),
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.prepaid", "instance_name", "testAccMysqlPrepaid"),
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.prepaid", "slave_deploy_mode", "0"),
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.prepaid", "slave_sync_mode", "0"),
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.prepaid", "availability_zone", TestAccTencentCloudMysqlMasterInstance_availability_zone),
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.prepaid", "first_slave_zone", TestAccTencentCloudMysqlMasterInstance_availability_zone),
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.prepaid", "auto_renew_flag", "0"),
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.prepaid", "charge_type", "PREPAID"),
),
},
// update auto_renew_flag
{
Config: testAccMysqlMasterInstance_prepaidupdate(),
Check: resource.ComposeAggregateTestCheckFunc(
testAccCheckMysqlMasterInstanceExists("tencentcloud_mysql_instance.prepaid"),
resource.TestCheckResourceAttr("tencentcloud_mysql_instance.prepaid", "auto_renew_flag", "1"),
),
},
},
})
}

func testAccCheckMysqlMasterInstanceDestroy(s *terraform.State) error {
logId := getLogId(contextNil)
ctx := context.WithValue(context.TODO(), logIdKey, logId)
Expand Down Expand Up @@ -323,39 +291,6 @@ resource "tencentcloud_mysql_instance" "mysql_master" {
}`
}

func testAccMysqlMasterInstance_prepaid() string {
return `
resource "tencentcloud_mysql_instance" "prepaid" {
charge_type = "PREPAID"
mem_size = 1000
volume_size = 50
instance_name = "testAccMysqlPrepaid"
engine_version = "5.7"
root_password = "test1234"
intranet_port = 3360
availability_zone = "ap-guangzhou-3"
first_slave_zone = "ap-guangzhou-3"
force_delete = false
}`
}

func testAccMysqlMasterInstance_prepaidupdate() string {
return `
resource "tencentcloud_mysql_instance" "prepaid" {
charge_type = "PREPAID"
mem_size = 1000
volume_size = 50
auto_renew_flag = 1
instance_name = "testAccMysqlPrepaid"
engine_version = "5.7"
root_password = "test1234"
intranet_port = 3360
availability_zone = "ap-guangzhou-3"
first_slave_zone = "ap-guangzhou-3"
force_delete = false
}`
}

func testAccMysqlMasterInstance_fullslave() string {
return `
resource "tencentcloud_mysql_instance" "mysql_master" {
Expand Down
Loading