From da88f79feba58059bd4d38a34e6f40b1121fced5 Mon Sep 17 00:00:00 2001 From: "maoshuai.17" Date: Thu, 24 Aug 2023 15:17:14 +0800 Subject: [PATCH 1/6] feat: support acc test for rds allowlist --- ...rce_volcengine_rds_mysql_allowlist_test.go | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 volcengine/rds_mysql/allowlist/resource_volcengine_rds_mysql_allowlist_test.go diff --git a/volcengine/rds_mysql/allowlist/resource_volcengine_rds_mysql_allowlist_test.go b/volcengine/rds_mysql/allowlist/resource_volcengine_rds_mysql_allowlist_test.go new file mode 100644 index 00000000..2cb4b93f --- /dev/null +++ b/volcengine/rds_mysql/allowlist/resource_volcengine_rds_mysql_allowlist_test.go @@ -0,0 +1,120 @@ +package allowlist_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/allowlist" +) + +const testAccVolcengineRdsMysqlAllowlistCreateConfig = ` +resource "volcengine_rds_mysql_allowlist" "foo" { + allow_list_name = "acc-test-allowlist" + allow_list_desc = "acc-test" + allow_list_type = "IPv4" + allow_list = ["192.168.0.0/24", "192.168.1.0/24"] +} +` + +func TestAccVolcengineRdsMysqlAllowlistResource_Basic(t *testing.T) { + resourceName := "volcengine_rds_mysql_allowlist.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return allowlist.NewRdsMysqlAllowListService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlAllowlistCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list_name", "acc-test-allowlist"), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list_type", "IPv4"), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list_desc", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list.#", "2"), + volcengine.TestCheckTypeSetElemAttr(acc.ResourceId, "allow_list.*", "192.168.0.0/24"), + volcengine.TestCheckTypeSetElemAttr(acc.ResourceId, "allow_list.*", "192.168.1.0/24"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "allow_list_id"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +const testAccVolcengineRdsMysqlAllowlistUpdateConfig = ` +resource "volcengine_rds_mysql_allowlist" "foo" { + allow_list_name = "acc-test-allowlist-new" + allow_list_desc = "acc-test-new" + allow_list_type = "IPv4" + allow_list = ["192.168.0.0/24", "192.168.3.0/24", "192.168.4.0/24"] +} +` + +func TestAccVolcengineRdsMysqlAllowlistResource_Update(t *testing.T) { + resourceName := "volcengine_rds_mysql_allowlist.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return allowlist.NewRdsMysqlAllowListService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlAllowlistCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list_name", "acc-test-allowlist"), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list_type", "IPv4"), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list_desc", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list.#", "2"), + volcengine.TestCheckTypeSetElemAttr(acc.ResourceId, "allow_list.*", "192.168.0.0/24"), + volcengine.TestCheckTypeSetElemAttr(acc.ResourceId, "allow_list.*", "192.168.1.0/24"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "allow_list_id"), + ), + }, + { + Config: testAccVolcengineRdsMysqlAllowlistUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list_name", "acc-test-allowlist-new"), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list_type", "IPv4"), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list_desc", "acc-test-new"), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list.#", "3"), + volcengine.TestCheckTypeSetElemAttr(acc.ResourceId, "allow_list.*", "192.168.0.0/24"), + volcengine.TestCheckTypeSetElemAttr(acc.ResourceId, "allow_list.*", "192.168.3.0/24"), + volcengine.TestCheckTypeSetElemAttr(acc.ResourceId, "allow_list.*", "192.168.4.0/24"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "allow_list_id"), + ), + }, + { + Config: testAccVolcengineRdsMysqlAllowlistUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} From 1b2885ac4ee5a013298313c1d943280a1405df87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=93=B2=E9=93=AD?= Date: Fri, 25 Aug 2023 10:55:57 +0800 Subject: [PATCH 2/6] feat: add rds instance database node acc --- example/dataRdsMysqlDatabases/main.tf | 49 +++- example/dataRdsMysqlInstances/main.tf | 43 +++- example/rdsMysqlDatabase/main.tf | 46 +++- example/rdsMysqlInstance/main.tf | 31 ++- example/rdsMysqlInstanceReadonlyNode/main.tf | 44 +++- ...rce_volcengine_rds_mysql_databases_test.go | 86 +++++++ ...urce_volcengine_rds_mysql_database_test.go | 96 +++++++ ...rce_volcengine_rds_mysql_instances_test.go | 81 ++++++ ...urce_volcengine_rds_mysql_instance_test.go | 237 ++++++++++++++++++ ...e_rds_mysql_instance_readonly_node_test.go | 175 +++++++++++++ 10 files changed, 864 insertions(+), 24 deletions(-) create mode 100644 volcengine/rds_mysql/rds_mysql_database/data_source_volcengine_rds_mysql_databases_test.go create mode 100644 volcengine/rds_mysql/rds_mysql_database/resource_volcengine_rds_mysql_database_test.go create mode 100644 volcengine/rds_mysql/rds_mysql_instance/data_source_volcengine_rds_mysql_instances_test.go create mode 100644 volcengine/rds_mysql/rds_mysql_instance/resource_volcengine_rds_mysql_instance_test.go create mode 100644 volcengine/rds_mysql/rds_mysql_instance_readonly_node/resource_volcengine_rds_mysql_instance_readonly_node_test.go diff --git a/example/dataRdsMysqlDatabases/main.tf b/example/dataRdsMysqlDatabases/main.tf index c4d4c026..fdcbf305 100644 --- a/example/dataRdsMysqlDatabases/main.tf +++ b/example/dataRdsMysqlDatabases/main.tf @@ -1,4 +1,47 @@ -data "volcengine_rds_mysql_databases" "default"{ - instance_id="" - db_name="" +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test" + instance_id = volcengine_rds_mysql_instance.foo.id +} +data "volcengine_rds_mysql_databases" "foo"{ + db_name = "acc-test" + instance_id = volcengine_rds_mysql_instance.foo.id } \ No newline at end of file diff --git a/example/dataRdsMysqlInstances/main.tf b/example/dataRdsMysqlInstances/main.tf index 597b4cad..f3706785 100644 --- a/example/dataRdsMysqlInstances/main.tf +++ b/example/dataRdsMysqlInstances/main.tf @@ -1,3 +1,42 @@ -data "volcengine_rds_mysql_instances" "default" { - instance_id = "mysql-72da4258c2c7" +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +data "volcengine_rds_mysql_instances" "foo"{ + instance_id = volcengine_rds_mysql_instance.foo.id } \ No newline at end of file diff --git a/example/rdsMysqlDatabase/main.tf b/example/rdsMysqlDatabase/main.tf index 7d10d6ab..e002562e 100644 --- a/example/rdsMysqlDatabase/main.tf +++ b/example/rdsMysqlDatabase/main.tf @@ -1,5 +1,43 @@ -resource "volcengine_rds_mysql_database" "default"{ - instance_id="mysql-xxx" - db_name="xxx" - character_set_name="utf8" +data "volcengine_zones" "foo"{ } + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test" + instance_id = volcengine_rds_mysql_instance.foo.id +} \ No newline at end of file diff --git a/example/rdsMysqlInstance/main.tf b/example/rdsMysqlInstance/main.tf index 8765ccc0..bba49bff 100644 --- a/example/rdsMysqlInstance/main.tf +++ b/example/rdsMysqlInstance/main.tf @@ -1,19 +1,32 @@ +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + resource "volcengine_rds_mysql_instance" "foo" { db_engine_version = "MySQL_5_7" node_spec = "rds.mysql.1c2g" - primary_zone_id = "cn-guilin-a" - secondary_zone_id = "cn-guilin-b" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id storage_space = 80 - subnet_id = "subnet-2d72yi377stts58ozfdrlk9f6" - instance_name = "tf-test" + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" lower_case_table_names = "1" charge_info { charge_type = "PostPaid" } - allow_list_ids = ["acl-2dd8f8317e4d4159b21630d13ae2e6ec", "acl-2eaa2a053b2a4a58b988e38ae975e81c"] - parameters { parameter_name = "auto_increment_increment" parameter_value = "2" @@ -22,10 +35,4 @@ resource "volcengine_rds_mysql_instance" "foo" { parameter_name = "auto_increment_offset" parameter_value = "4" } -} - -resource "volcengine_rds_mysql_instance_readonly_node" "readonly" { - instance_id = volcengine_rds_mysql_instance.foo.id - node_spec = "rds.mysql.2c4g" - zone_id = "cn-guilin-a" } \ No newline at end of file diff --git a/example/rdsMysqlInstanceReadonlyNode/main.tf b/example/rdsMysqlInstanceReadonlyNode/main.tf index 9121f954..ca8bd847 100644 --- a/example/rdsMysqlInstanceReadonlyNode/main.tf +++ b/example/rdsMysqlInstanceReadonlyNode/main.tf @@ -1,5 +1,43 @@ -resource "volcengine_rds_mysql_instance_readonly_node" "foo" { - instance_id = "mysql-b3fca7f571d6" +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" node_spec = "rds.mysql.1c2g" - zone_id = "cn-guilin-b" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} +resource "volcengine_rds_mysql_instance_readonly_node" "foo" { + instance_id = volcengine_rds_mysql_instance.foo.id + node_spec = "rds.mysql.2c4g" + zone_id = data.volcengine_zones.foo.zones[0].id } \ No newline at end of file diff --git a/volcengine/rds_mysql/rds_mysql_database/data_source_volcengine_rds_mysql_databases_test.go b/volcengine/rds_mysql/rds_mysql_database/data_source_volcengine_rds_mysql_databases_test.go new file mode 100644 index 00000000..9a2c59c3 --- /dev/null +++ b/volcengine/rds_mysql/rds_mysql_database/data_source_volcengine_rds_mysql_databases_test.go @@ -0,0 +1,86 @@ +package rds_mysql_database_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/rds_mysql_database" +) + +const testAccVolcengineRdsMysqlDatabasesDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test" + instance_id = volcengine_rds_mysql_instance.foo.id +} +data "volcengine_rds_mysql_databases" "foo"{ + db_name = "acc-test" + instance_id = volcengine_rds_mysql_instance.foo.id +} +` + +func TestAccVolcengineRdsMysqlDatabasesDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_rds_mysql_databases.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return rds_mysql_database.NewRdsMysqlDatabaseService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlDatabasesDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "databases.#", "1"), + ), + }, + }, + }) +} diff --git a/volcengine/rds_mysql/rds_mysql_database/resource_volcengine_rds_mysql_database_test.go b/volcengine/rds_mysql/rds_mysql_database/resource_volcengine_rds_mysql_database_test.go new file mode 100644 index 00000000..8a0950c4 --- /dev/null +++ b/volcengine/rds_mysql/rds_mysql_database/resource_volcengine_rds_mysql_database_test.go @@ -0,0 +1,96 @@ +package rds_mysql_database_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/rds_mysql_database" +) + +const testAccVolcengineRdsMysqlDatabaseCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test" + instance_id = volcengine_rds_mysql_instance.foo.id +} +` + +func TestAccVolcengineRdsMysqlDatabaseResource_Basic(t *testing.T) { + resourceName := "volcengine_rds_mysql_database.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return rds_mysql_database.NewRdsMysqlDatabaseService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlDatabaseCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "character_set_name", ""), + resource.TestCheckResourceAttr(acc.ResourceId, "db_name", ""), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_id", ""), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccVolcengineRdsMysqlDatabaseCreateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, + }, + }, + }) +} diff --git a/volcengine/rds_mysql/rds_mysql_instance/data_source_volcengine_rds_mysql_instances_test.go b/volcengine/rds_mysql/rds_mysql_instance/data_source_volcengine_rds_mysql_instances_test.go new file mode 100644 index 00000000..828f4096 --- /dev/null +++ b/volcengine/rds_mysql/rds_mysql_instance/data_source_volcengine_rds_mysql_instances_test.go @@ -0,0 +1,81 @@ +package rds_mysql_instance_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/rds_mysql_instance" +) + +const testAccVolcengineRdsMysqlInstancesDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +data "volcengine_rds_mysql_instances" "foo"{ + instance_id = volcengine_rds_mysql_instance.foo.id +} +` + +func TestAccVolcengineRdsMysqlInstancesDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_rds_mysql_instances.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return rds_mysql_instance.NewRdsMysqlInstanceService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlInstancesDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "rds_mysql_instances.#", "1"), + ), + }, + }, + }) +} diff --git a/volcengine/rds_mysql/rds_mysql_instance/resource_volcengine_rds_mysql_instance_test.go b/volcengine/rds_mysql/rds_mysql_instance/resource_volcengine_rds_mysql_instance_test.go new file mode 100644 index 00000000..bc530319 --- /dev/null +++ b/volcengine/rds_mysql/rds_mysql_instance/resource_volcengine_rds_mysql_instance_test.go @@ -0,0 +1,237 @@ +package rds_mysql_instance_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/rds_mysql_instance" +) + +const testAccVolcengineRdsMysqlInstanceCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} +` + +const testAccVolcengineRdsMysqlInstanceUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_allowlist" "foo" { + allow_list_name = "acc-test-allowlist" + allow_list_desc = "acc-test" + allow_list_type = "IPv4" + allow_list = ["192.168.0.0/24", "192.168.1.0/24"] +} + +resource "volcengine_rds_mysql_allowlist" "foo1" { + allow_list_name = "acc-test-allowlist1" + allow_list_desc = "acc-test1" + allow_list_type = "IPv4" + allow_list = ["192.168.0.0/24", "192.168.1.0/24"] +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.2c4g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 100 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test1" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + allow_list_ids = [volcengine_rds_mysql_allowlist.foo.id, volcengine_rds_mysql_allowlist.foo1.id] + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "4" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "8" + } + parameters { + parameter_name = "innodb_thread_concurrency" + parameter_value = "0" + } +} +` + +func TestAccVolcengineRdsMysqlInstanceResource_Basic(t *testing.T) { + resourceName := "volcengine_rds_mysql_instance.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return rds_mysql_instance.NewRdsMysqlInstanceService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlInstanceCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list_ids.#", "0"), + resource.TestCheckResourceAttr(acc.ResourceId, "charge_info.#", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "charge_info.0.charge_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "db_engine_version", "MySQL_5_7"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_name", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "lower_case_table_names", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "node_spec", "rds.mysql.1c2g"), + resource.TestCheckResourceAttr(acc.ResourceId, "parameters.#", "2"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "parameters.*", map[string]string{ + "parameter_name": "auto_increment_increment", + "parameter_value": "2", + }), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "parameters.*", map[string]string{ + "parameter_name": "auto_increment_offset", + "parameter_value": "4", + }), + resource.TestCheckResourceAttr(acc.ResourceId, "storage_space", "80"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccVolcengineRdsMysqlInstanceResource_Update(t *testing.T) { + resourceName := "volcengine_rds_mysql_instance.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return rds_mysql_instance.NewRdsMysqlInstanceService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlInstanceCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list_ids.#", "0"), + resource.TestCheckResourceAttr(acc.ResourceId, "charge_info.#", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "charge_info.0.charge_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "db_engine_version", "MySQL_5_7"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_name", "acc-test"), + resource.TestCheckResourceAttr(acc.ResourceId, "lower_case_table_names", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "node_spec", "rds.mysql.1c2g"), + resource.TestCheckResourceAttr(acc.ResourceId, "parameters.#", "2"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "parameters.*", map[string]string{ + "parameter_name": "auto_increment_increment", + "parameter_value": "2", + }), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "parameters.*", map[string]string{ + "parameter_name": "auto_increment_offset", + "parameter_value": "4", + }), + resource.TestCheckResourceAttr(acc.ResourceId, "storage_space", "80"), + ), + }, + { + Config: testAccVolcengineRdsMysqlInstanceUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "allow_list_ids.#", "2"), + resource.TestCheckResourceAttr(acc.ResourceId, "charge_info.#", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "charge_info.0.charge_type", "PostPaid"), + resource.TestCheckResourceAttr(acc.ResourceId, "db_engine_version", "MySQL_5_7"), + resource.TestCheckResourceAttr(acc.ResourceId, "instance_name", "acc-test1"), + resource.TestCheckResourceAttr(acc.ResourceId, "lower_case_table_names", "1"), + resource.TestCheckResourceAttr(acc.ResourceId, "node_spec", "rds.mysql.2c4g"), + resource.TestCheckResourceAttr(acc.ResourceId, "parameters.#", "3"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "parameters.*", map[string]string{ + "parameter_name": "auto_increment_increment", + "parameter_value": "4", + }), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "parameters.*", map[string]string{ + "parameter_name": "auto_increment_offset", + "parameter_value": "8", + }), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "parameters.*", map[string]string{ + "parameter_name": "innodb_thread_concurrency", + "parameter_value": "0", + }), + resource.TestCheckResourceAttr(acc.ResourceId, "storage_space", "100"), + ), + }, + { + Config: testAccVolcengineRdsMysqlInstanceUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/rds_mysql/rds_mysql_instance_readonly_node/resource_volcengine_rds_mysql_instance_readonly_node_test.go b/volcengine/rds_mysql/rds_mysql_instance_readonly_node/resource_volcengine_rds_mysql_instance_readonly_node_test.go new file mode 100644 index 00000000..5d28ba14 --- /dev/null +++ b/volcengine/rds_mysql/rds_mysql_instance_readonly_node/resource_volcengine_rds_mysql_instance_readonly_node_test.go @@ -0,0 +1,175 @@ +package rds_mysql_instance_readonly_node_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/rds_mysql_instance_readonly_node" +) + +const testAccVolcengineRdsMysqlInstanceReadonlyNodeCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} +resource "volcengine_rds_mysql_instance_readonly_node" "foo" { + instance_id = volcengine_rds_mysql_instance.foo.id + node_spec = "rds.mysql.2c4g" + zone_id = data.volcengine_zones.foo.zones[0].id +} +` + +const testAccVolcengineRdsMysqlInstanceReadonlyNodeUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} +resource "volcengine_rds_mysql_instance_readonly_node" "foo" { + instance_id = volcengine_rds_mysql_instance.foo.id + node_spec = "rds.mysql.1c2g" + zone_id = data.volcengine_zones.foo.zones[0].id +} +` + +func TestAccVolcengineRdsMysqlInstanceReadonlyNodeResource_Basic(t *testing.T) { + resourceName := "volcengine_rds_mysql_instance_readonly_node.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return rds_mysql_instance_readonly_node.NewRdsMysqlInstanceReadonlyNodeService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlInstanceReadonlyNodeCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "node_spec", "rds.mysql.2c4g"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccVolcengineRdsMysqlInstanceReadonlyNodeResource_Update(t *testing.T) { + resourceName := "volcengine_rds_mysql_instance_readonly_node.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return rds_mysql_instance_readonly_node.NewRdsMysqlInstanceReadonlyNodeService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlInstanceReadonlyNodeCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "node_spec", "rds.mysql.2c4g"), + ), + }, + { + Config: testAccVolcengineRdsMysqlInstanceReadonlyNodeUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "node_spec", "rds.mysql.1c2g"), + ), + }, + { + Config: testAccVolcengineRdsMysqlInstanceReadonlyNodeUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} From cc55a963de0ca4f420ea4e536000a905055404ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=93=B2=E9=93=AD?= Date: Mon, 28 Aug 2023 19:29:49 +0800 Subject: [PATCH 3/6] fix: opt rds database acc --- .../resource_volcengine_rds_mysql_database_test.go | 13 ++++--------- .../resource_volcengine_rds_mysql_instance_test.go | 7 ++++--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/volcengine/rds_mysql/rds_mysql_database/resource_volcengine_rds_mysql_database_test.go b/volcengine/rds_mysql/rds_mysql_database/resource_volcengine_rds_mysql_database_test.go index 8a0950c4..c3b038b5 100644 --- a/volcengine/rds_mysql/rds_mysql_database/resource_volcengine_rds_mysql_database_test.go +++ b/volcengine/rds_mysql/rds_mysql_database/resource_volcengine_rds_mysql_database_test.go @@ -69,16 +69,16 @@ func TestAccVolcengineRdsMysqlDatabaseResource_Basic(t *testing.T) { PreCheck: func() { volcengine.AccTestPreCheck(t) }, - Providers: volcengine.GetTestAccProviders(), + Providers: volcengine.GetTestAccProviders(), + // CheckDestroy 此处可能存在问题,业务方接口查询已删除实例的数据库会报内部错误,预计于2023-09修复 CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), Steps: []resource.TestStep{ { Config: testAccVolcengineRdsMysqlDatabaseCreateConfig, Check: resource.ComposeTestCheckFunc( volcengine.AccTestCheckResourceExists(acc), - resource.TestCheckResourceAttr(acc.ResourceId, "character_set_name", ""), - resource.TestCheckResourceAttr(acc.ResourceId, "db_name", ""), - resource.TestCheckResourceAttr(acc.ResourceId, "instance_id", ""), + resource.TestCheckResourceAttr(acc.ResourceId, "character_set_name", "utf8mb4"), + resource.TestCheckResourceAttr(acc.ResourceId, "db_name", "acc-test"), ), }, { @@ -86,11 +86,6 @@ func TestAccVolcengineRdsMysqlDatabaseResource_Basic(t *testing.T) { ImportState: true, ImportStateVerify: true, }, - { - Config: testAccVolcengineRdsMysqlDatabaseCreateConfig, - PlanOnly: true, - ExpectNonEmptyPlan: false, - }, }, }) } diff --git a/volcengine/rds_mysql/rds_mysql_instance/resource_volcengine_rds_mysql_instance_test.go b/volcengine/rds_mysql/rds_mysql_instance/resource_volcengine_rds_mysql_instance_test.go index bc530319..2940d6dc 100644 --- a/volcengine/rds_mysql/rds_mysql_instance/resource_volcengine_rds_mysql_instance_test.go +++ b/volcengine/rds_mysql/rds_mysql_instance/resource_volcengine_rds_mysql_instance_test.go @@ -152,9 +152,10 @@ func TestAccVolcengineRdsMysqlInstanceResource_Basic(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"parameters"}, }, }, }) From 279ddb6c94768adccf3111d2b348cda28ff0f596 Mon Sep 17 00:00:00 2001 From: "maoshuai.17" Date: Mon, 4 Sep 2023 20:47:21 +0800 Subject: [PATCH 4/6] feat: support acc test for rds account --- example/dataRdsMysqlAccounts/main.tf | 60 ++++- example/dataRdsMysqlAllowlists/main.tf | 52 +++- example/rdsMysqlAccount/main.tf | 67 ++++-- example/rdsMysqlAllowlist/main.tf | 9 +- example/rdsMysqlAllowlistAssociate/main.tf | 48 +++- ...ce_volcengine_rds_mysql_allowlists_test.go | 90 +++++++ ...gine_rds_mysql_allowlist_associate_test.go | 95 ++++++++ ...urce_volcengine_rds_mysql_accounts_test.go | 97 ++++++++ ...ource_volcengine_rds_mysql_account_test.go | 225 ++++++++++++++++++ .../resource_volcengine_rds_mysql_instance.go | 1 + 10 files changed, 717 insertions(+), 27 deletions(-) create mode 100644 volcengine/rds_mysql/allowlist/data_source_volcengine_rds_mysql_allowlists_test.go create mode 100644 volcengine/rds_mysql/allowlist_associate/resource_volcengine_rds_mysql_allowlist_associate_test.go create mode 100644 volcengine/rds_mysql/rds_mysql_account/data_source_volcengine_rds_mysql_accounts_test.go create mode 100644 volcengine/rds_mysql/rds_mysql_account/resource_volcengine_rds_mysql_account_test.go diff --git a/example/dataRdsMysqlAccounts/main.tf b/example/dataRdsMysqlAccounts/main.tf index f82b2e39..670ee609 100644 --- a/example/dataRdsMysqlAccounts/main.tf +++ b/example/dataRdsMysqlAccounts/main.tf @@ -1,4 +1,58 @@ -data "volcengine_rds_mysql_accounts" "default"{ - instance_id="mysql-47d6bc58762b" - account_name="" +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test-db" + instance_id = volcengine_rds_mysql_instance.foo.id +} + +resource "volcengine_rds_mysql_account" "foo" { + account_name = "acc-test-account" + account_password = "93f0cb0614Aab12" + account_type = "Normal" + instance_id = volcengine_rds_mysql_instance.foo.id + account_privileges { + db_name = volcengine_rds_mysql_database.foo.db_name + account_privilege = "Custom" + account_privilege_detail = "SELECT,INSERT" + } +} + +data "volcengine_rds_mysql_accounts" "foo"{ + instance_id = volcengine_rds_mysql_instance.foo.id + account_name = volcengine_rds_mysql_account.foo.account_name } \ No newline at end of file diff --git a/example/dataRdsMysqlAllowlists/main.tf b/example/dataRdsMysqlAllowlists/main.tf index c8e8a3ca..e1a7fd8e 100644 --- a/example/dataRdsMysqlAllowlists/main.tf +++ b/example/dataRdsMysqlAllowlists/main.tf @@ -1,3 +1,51 @@ -data "volcengine_rds_mysql_allowlists" "default" { - region_id = "cn-guilin-boe" +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_allowlist" "foo" { + allow_list_name = "acc-test-allowlist-${count.index}" + allow_list_desc = "acc-test" + allow_list_type = "IPv4" + allow_list = ["192.168.0.0/24", "192.168.1.0/24"] + count = 3 +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } + + allow_list_ids = volcengine_rds_mysql_allowlist.foo[*].id +} + +data "volcengine_rds_mysql_allowlists" "foo"{ + instance_id = volcengine_rds_mysql_instance.foo.id + region_id = "cn-beijing" } \ No newline at end of file diff --git a/example/rdsMysqlAccount/main.tf b/example/rdsMysqlAccount/main.tf index 40d13eb7..97e7a6e8 100644 --- a/example/rdsMysqlAccount/main.tf +++ b/example/rdsMysqlAccount/main.tf @@ -1,16 +1,53 @@ -resource "volcengine_rds_mysql_account" "default"{ - instance_id="mysql-e9293705eed6" - account_name="test" - account_password="xdjsuiahHUH@" - account_type="Normal" -# account_privileges{ -# db_name="tf-test-dbdddddd" -# account_privilege="ReadOnly" -# account_privilege_detail="SELECT,UPDATE,INSERT" -# } -# account_privileges{ -# db_name="test-xx" -# account_privilege="ReadOnly" -# account_privilege_detail="SELECT,UPDATE,INSERT" -# } +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test-db" + instance_id = volcengine_rds_mysql_instance.foo.id +} + +resource "volcengine_rds_mysql_account" "foo" { + account_name = "acc-test-account" + account_password = "93f0cb0614Aab12" + account_type = "Normal" + instance_id = volcengine_rds_mysql_instance.foo.id + account_privileges { + db_name = volcengine_rds_mysql_database.foo.db_name + account_privilege = "Custom" + account_privilege_detail = "SELECT,INSERT" + } } \ No newline at end of file diff --git a/example/rdsMysqlAllowlist/main.tf b/example/rdsMysqlAllowlist/main.tf index 6b0b0b1b..7bf0a0fb 100644 --- a/example/rdsMysqlAllowlist/main.tf +++ b/example/rdsMysqlAllowlist/main.tf @@ -1,7 +1,6 @@ resource "volcengine_rds_mysql_allowlist" "foo" { - allow_list_name = "tf-test-opt" - allow_list_desc = "terraform test zzm" - allow_list = [ - "127.0.0.1" - ] + allow_list_name = "acc-test-allowlist" + allow_list_desc = "acc-test" + allow_list_type = "IPv4" + allow_list = ["192.168.0.0/24", "192.168.1.0/24"] } \ No newline at end of file diff --git a/example/rdsMysqlAllowlistAssociate/main.tf b/example/rdsMysqlAllowlistAssociate/main.tf index 2e1e287e..e3d5ecc4 100644 --- a/example/rdsMysqlAllowlistAssociate/main.tf +++ b/example/rdsMysqlAllowlistAssociate/main.tf @@ -1,4 +1,48 @@ +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_allowlist" "foo" { + allow_list_name = "acc-test-allowlist" + allow_list_desc = "acc-test" + allow_list_type = "IPv4" + allow_list = ["192.168.0.0/24", "192.168.1.0/24"] +} + resource "volcengine_rds_mysql_allowlist_associate" "foo" { - instance_id = "mysql-1b2c7b2d7583" - allow_list_id = "acl-15451212dcfa473baeda24be4baa02fe" + allow_list_id = volcengine_rds_mysql_allowlist.foo.id + instance_id = volcengine_rds_mysql_instance.foo.id } \ No newline at end of file diff --git a/volcengine/rds_mysql/allowlist/data_source_volcengine_rds_mysql_allowlists_test.go b/volcengine/rds_mysql/allowlist/data_source_volcengine_rds_mysql_allowlists_test.go new file mode 100644 index 00000000..8910631d --- /dev/null +++ b/volcengine/rds_mysql/allowlist/data_source_volcengine_rds_mysql_allowlists_test.go @@ -0,0 +1,90 @@ +package allowlist_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/allowlist" +) + +const testAccVolcengineRdsMysqlAllowlistsDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "${data.volcengine_zones.foo.zones[0].id}" + vpc_id = "${volcengine_vpc.foo.id}" +} + +resource "volcengine_rds_mysql_allowlist" "foo" { + allow_list_name = "acc-test-allowlist-${count.index}" + allow_list_desc = "acc-test" + allow_list_type = "IPv4" + allow_list = ["192.168.0.0/24", "192.168.1.0/24"] + count = 3 +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = "${data.volcengine_zones.foo.zones[0].id}" + secondary_zone_id = "${data.volcengine_zones.foo.zones[0].id}" + storage_space = 80 + subnet_id = "${volcengine_subnet.foo.id}" + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } + + allow_list_ids = volcengine_rds_mysql_allowlist.foo[*].id +} + +data "volcengine_rds_mysql_allowlists" "foo"{ + instance_id = "${volcengine_rds_mysql_instance.foo.id}" + region_id = "cn-beijing" +} +` + +func TestAccVolcengineRdsMysqlAllowlistsDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_rds_mysql_allowlists.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return allowlist.NewRdsMysqlAllowListService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlAllowlistsDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "allow_lists.#", "3"), + ), + }, + }, + }) +} diff --git a/volcengine/rds_mysql/allowlist_associate/resource_volcengine_rds_mysql_allowlist_associate_test.go b/volcengine/rds_mysql/allowlist_associate/resource_volcengine_rds_mysql_allowlist_associate_test.go new file mode 100644 index 00000000..fa924914 --- /dev/null +++ b/volcengine/rds_mysql/allowlist_associate/resource_volcengine_rds_mysql_allowlist_associate_test.go @@ -0,0 +1,95 @@ +package allowlist_associate_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/allowlist_associate" +) + +const testAccVolcengineRdsMysqlAllowlistAssociateCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "${data.volcengine_zones.foo.zones[0].id}" + vpc_id = "${volcengine_vpc.foo.id}" +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = "${data.volcengine_zones.foo.zones[0].id}" + secondary_zone_id = "${data.volcengine_zones.foo.zones[0].id}" + storage_space = 80 + subnet_id = "${volcengine_subnet.foo.id}" + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_allowlist" "foo" { + allow_list_name = "acc-test-allowlist" + allow_list_desc = "acc-test" + allow_list_type = "IPv4" + allow_list = ["192.168.0.0/24", "192.168.1.0/24"] +} + +resource "volcengine_rds_mysql_allowlist_associate" "foo" { + allow_list_id = "${volcengine_rds_mysql_allowlist.foo.id}" + instance_id = "${volcengine_rds_mysql_instance.foo.id}" +} +` + +func TestAccVolcengineRdsMysqlAllowlistAssociateResource_Basic(t *testing.T) { + resourceName := "volcengine_rds_mysql_allowlist_associate.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return allowlist_associate.NewRdsMysqlAllowListAssociateService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlAllowlistAssociateCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttrSet(acc.ResourceId, "allow_list_id"), + resource.TestCheckResourceAttrSet(acc.ResourceId, "instance_id"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} diff --git a/volcengine/rds_mysql/rds_mysql_account/data_source_volcengine_rds_mysql_accounts_test.go b/volcengine/rds_mysql/rds_mysql_account/data_source_volcengine_rds_mysql_accounts_test.go new file mode 100644 index 00000000..565e0678 --- /dev/null +++ b/volcengine/rds_mysql/rds_mysql_account/data_source_volcengine_rds_mysql_accounts_test.go @@ -0,0 +1,97 @@ +package rds_mysql_account_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/rds_mysql_account" +) + +const testAccVolcengineRdsMysqlAccountsDatasourceConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "${data.volcengine_zones.foo.zones[0].id}" + vpc_id = "${volcengine_vpc.foo.id}" +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = "${data.volcengine_zones.foo.zones[0].id}" + secondary_zone_id = "${data.volcengine_zones.foo.zones[0].id}" + storage_space = 80 + subnet_id = "${volcengine_subnet.foo.id}" + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test-db" + instance_id = "${volcengine_rds_mysql_instance.foo.id}" +} + +resource "volcengine_rds_mysql_account" "foo" { + account_name = "acc-test-account" + account_password = "93f0cb0614Aab12" + account_type = "Normal" + instance_id = "${volcengine_rds_mysql_instance.foo.id}" + account_privileges { + db_name = "${volcengine_rds_mysql_database.foo.db_name}" + account_privilege = "Custom" + account_privilege_detail = "SELECT,INSERT" + } +} + +data "volcengine_rds_mysql_accounts" "foo"{ + instance_id = "${volcengine_rds_mysql_instance.foo.id}" + account_name = "${volcengine_rds_mysql_account.foo.account_name}" +} +` + +func TestAccVolcengineRdsMysqlAccountsDatasource_Basic(t *testing.T) { + resourceName := "data.volcengine_rds_mysql_accounts.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return rds_mysql_account.NewRdsMysqlAccountService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlAccountsDatasourceConfig, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(acc.ResourceId, "accounts.#", "1"), + ), + }, + }, + }) +} diff --git a/volcengine/rds_mysql/rds_mysql_account/resource_volcengine_rds_mysql_account_test.go b/volcengine/rds_mysql/rds_mysql_account/resource_volcengine_rds_mysql_account_test.go new file mode 100644 index 00000000..01b89186 --- /dev/null +++ b/volcengine/rds_mysql/rds_mysql_account/resource_volcengine_rds_mysql_account_test.go @@ -0,0 +1,225 @@ +package rds_mysql_account_test + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + ve "github.com/volcengine/terraform-provider-volcengine/common" + "github.com/volcengine/terraform-provider-volcengine/volcengine" + "github.com/volcengine/terraform-provider-volcengine/volcengine/rds_mysql/rds_mysql_account" +) + +const testAccVolcengineRdsMysqlAccountCreateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "${data.volcengine_zones.foo.zones[0].id}" + vpc_id = "${volcengine_vpc.foo.id}" +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = "${data.volcengine_zones.foo.zones[0].id}" + secondary_zone_id = "${data.volcengine_zones.foo.zones[0].id}" + storage_space = 80 + subnet_id = "${volcengine_subnet.foo.id}" + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test-db" + instance_id = "${volcengine_rds_mysql_instance.foo.id}" +} + +resource "volcengine_rds_mysql_account" "foo" { + account_name = "acc-test-account" + account_password = "93f0cb0614Aab12" + account_type = "Normal" + instance_id = "${volcengine_rds_mysql_instance.foo.id}" + account_privileges { + db_name = "${volcengine_rds_mysql_database.foo.db_name}" + account_privilege = "Custom" + account_privilege_detail = "SELECT,INSERT" + } +} +` + +func TestAccVolcengineRdsMysqlAccountResource_Basic(t *testing.T) { + resourceName := "volcengine_rds_mysql_account.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return rds_mysql_account.NewRdsMysqlAccountService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + // CheckDestroy 此处可能存在问题,业务方接口查询已删除实例的账号会报内部错误,预计于2023-09修复 + //CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlAccountCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "account_name", "acc-test-account"), + resource.TestCheckResourceAttr(acc.ResourceId, "account_password", "93f0cb0614Aab12"), + resource.TestCheckResourceAttr(acc.ResourceId, "account_type", "Normal"), + resource.TestCheckResourceAttr(acc.ResourceId, "account_privileges.#", "1"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "account_privileges.*", map[string]string{ + "db_name": "acc-test-db", + "account_privilege": "Custom", + "account_privilege_detail": "SELECT,INSERT", + }), + resource.TestCheckResourceAttrSet(acc.ResourceId, "instance_id"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"account_password"}, + }, + }, + }) +} + +const testAccVolcengineRdsMysqlAccountUpdateConfig = ` +data "volcengine_zones" "foo"{ +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = "${data.volcengine_zones.foo.zones[0].id}" + vpc_id = "${volcengine_vpc.foo.id}" +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = "${data.volcengine_zones.foo.zones[0].id}" + secondary_zone_id = "${data.volcengine_zones.foo.zones[0].id}" + storage_space = 80 + subnet_id = "${volcengine_subnet.foo.id}" + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test-db" + instance_id = "${volcengine_rds_mysql_instance.foo.id}" +} + +resource "volcengine_rds_mysql_account" "foo" { + account_name = "acc-test-account" + account_password = "93f0cb0614Aab12345" + account_type = "Normal" + instance_id = "${volcengine_rds_mysql_instance.foo.id}" + account_privileges { + db_name = "${volcengine_rds_mysql_database.foo.db_name}" + account_privilege = "Custom" + account_privilege_detail = "UPDATE,DELETE,SELECT" + } +} +` + +func TestAccVolcengineRdsMysqlAccountResource_Update(t *testing.T) { + resourceName := "volcengine_rds_mysql_account.foo" + + acc := &volcengine.AccTestResource{ + ResourceId: resourceName, + SvcInitFunc: func(client *ve.SdkClient) ve.ResourceService { + return rds_mysql_account.NewRdsMysqlAccountService(client) + }, + } + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + volcengine.AccTestPreCheck(t) + }, + Providers: volcengine.GetTestAccProviders(), + // CheckDestroy 此处可能存在问题,业务方接口查询已删除实例的账号会报内部错误,预计于2023-09修复 + //CheckDestroy: volcengine.AccTestCheckResourceRemove(acc), + Steps: []resource.TestStep{ + { + Config: testAccVolcengineRdsMysqlAccountCreateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "account_name", "acc-test-account"), + resource.TestCheckResourceAttr(acc.ResourceId, "account_password", "93f0cb0614Aab12"), + resource.TestCheckResourceAttr(acc.ResourceId, "account_type", "Normal"), + resource.TestCheckResourceAttr(acc.ResourceId, "account_privileges.#", "1"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "account_privileges.*", map[string]string{ + "db_name": "acc-test-db", + "account_privilege": "Custom", + "account_privilege_detail": "SELECT,INSERT", + }), + resource.TestCheckResourceAttrSet(acc.ResourceId, "instance_id"), + ), + }, + { + Config: testAccVolcengineRdsMysqlAccountUpdateConfig, + Check: resource.ComposeTestCheckFunc( + volcengine.AccTestCheckResourceExists(acc), + resource.TestCheckResourceAttr(acc.ResourceId, "account_name", "acc-test-account"), + resource.TestCheckResourceAttr(acc.ResourceId, "account_password", "93f0cb0614Aab12345"), + resource.TestCheckResourceAttr(acc.ResourceId, "account_type", "Normal"), + resource.TestCheckResourceAttr(acc.ResourceId, "account_privileges.#", "1"), + volcengine.TestCheckTypeSetElemNestedAttrs(acc.ResourceId, "account_privileges.*", map[string]string{ + "db_name": "acc-test-db", + "account_privilege": "Custom", + "account_privilege_detail": "UPDATE,DELETE,SELECT", + }), + resource.TestCheckResourceAttrSet(acc.ResourceId, "instance_id"), + ), + }, + { + Config: testAccVolcengineRdsMysqlAccountUpdateConfig, + PlanOnly: true, + ExpectNonEmptyPlan: false, // 修改之后,不应该再产生diff + }, + }, + }) +} diff --git a/volcengine/rds_mysql/rds_mysql_instance/resource_volcengine_rds_mysql_instance.go b/volcengine/rds_mysql/rds_mysql_instance/resource_volcengine_rds_mysql_instance.go index 33a198e2..cb27a807 100644 --- a/volcengine/rds_mysql/rds_mysql_instance/resource_volcengine_rds_mysql_instance.go +++ b/volcengine/rds_mysql/rds_mysql_instance/resource_volcengine_rds_mysql_instance.go @@ -138,6 +138,7 @@ func ResourceVolcengineRdsMysqlInstance() *schema.Resource { "allow_list_ids": { Type: schema.TypeSet, Optional: true, + Computed: true, Set: schema.HashString, Description: "Allow list Ids of the RDS instance.", Elem: &schema.Schema{ From c9f814936e3a7a8eae682b65fb39994b578b6700 Mon Sep 17 00:00:00 2001 From: "maoshuai.17" Date: Tue, 5 Sep 2023 11:08:49 +0800 Subject: [PATCH 5/6] feat: update docs and version --- .../docs/d/rds_mysql_accounts.html.markdown | 60 ++++++++++++++++- .../docs/d/rds_mysql_allowlists.html.markdown | 52 ++++++++++++++- .../docs/d/rds_mysql_databases.html.markdown | 49 +++++++++++++- .../docs/d/rds_mysql_instances.html.markdown | 43 +++++++++++- .../docs/r/rds_mysql_account.html.markdown | 65 +++++++++++++++---- .../docs/r/rds_mysql_allowlist.html.markdown | 9 ++- ...ds_mysql_allowlist_associate.html.markdown | 48 +++++++++++++- .../docs/r/rds_mysql_database.html.markdown | 46 +++++++++++-- .../docs/r/rds_mysql_instance.html.markdown | 31 +++++---- ...mysql_instance_readonly_node.html.markdown | 44 ++++++++++++- 10 files changed, 397 insertions(+), 50 deletions(-) diff --git a/website/docs/d/rds_mysql_accounts.html.markdown b/website/docs/d/rds_mysql_accounts.html.markdown index b7bd8398..c6a7635d 100644 --- a/website/docs/d/rds_mysql_accounts.html.markdown +++ b/website/docs/d/rds_mysql_accounts.html.markdown @@ -10,9 +10,63 @@ description: |- Use this data source to query detailed information of rds mysql accounts ## Example Usage ```hcl -data "volcengine_rds_mysql_accounts" "default" { - instance_id = "mysql-47d6bc58762b" - account_name = "" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test-db" + instance_id = volcengine_rds_mysql_instance.foo.id +} + +resource "volcengine_rds_mysql_account" "foo" { + account_name = "acc-test-account" + account_password = "93f0cb0614Aab12" + account_type = "Normal" + instance_id = volcengine_rds_mysql_instance.foo.id + account_privileges { + db_name = volcengine_rds_mysql_database.foo.db_name + account_privilege = "Custom" + account_privilege_detail = "SELECT,INSERT" + } +} + +data "volcengine_rds_mysql_accounts" "foo" { + instance_id = volcengine_rds_mysql_instance.foo.id + account_name = volcengine_rds_mysql_account.foo.account_name } ``` ## Argument Reference diff --git a/website/docs/d/rds_mysql_allowlists.html.markdown b/website/docs/d/rds_mysql_allowlists.html.markdown index ba300f08..938a6398 100644 --- a/website/docs/d/rds_mysql_allowlists.html.markdown +++ b/website/docs/d/rds_mysql_allowlists.html.markdown @@ -10,8 +10,56 @@ description: |- Use this data source to query detailed information of rds mysql allowlists ## Example Usage ```hcl -data "volcengine_rds_mysql_allowlists" "default" { - region_id = "cn-guilin-boe" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_allowlist" "foo" { + allow_list_name = "acc-test-allowlist-${count.index}" + allow_list_desc = "acc-test" + allow_list_type = "IPv4" + allow_list = ["192.168.0.0/24", "192.168.1.0/24"] + count = 3 +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } + + allow_list_ids = volcengine_rds_mysql_allowlist.foo[*].id +} + +data "volcengine_rds_mysql_allowlists" "foo" { + instance_id = volcengine_rds_mysql_instance.foo.id + region_id = "cn-beijing" } ``` ## Argument Reference diff --git a/website/docs/d/rds_mysql_databases.html.markdown b/website/docs/d/rds_mysql_databases.html.markdown index 64b1ffa4..dc1d0d0f 100644 --- a/website/docs/d/rds_mysql_databases.html.markdown +++ b/website/docs/d/rds_mysql_databases.html.markdown @@ -10,9 +10,52 @@ description: |- Use this data source to query detailed information of rds mysql databases ## Example Usage ```hcl -data "volcengine_rds_mysql_databases" "default" { - instance_id = "" - db_name = "" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test" + instance_id = volcengine_rds_mysql_instance.foo.id +} +data "volcengine_rds_mysql_databases" "foo" { + db_name = "acc-test" + instance_id = volcengine_rds_mysql_instance.foo.id } ``` ## Argument Reference diff --git a/website/docs/d/rds_mysql_instances.html.markdown b/website/docs/d/rds_mysql_instances.html.markdown index 12b92fb8..4ab0428e 100644 --- a/website/docs/d/rds_mysql_instances.html.markdown +++ b/website/docs/d/rds_mysql_instances.html.markdown @@ -10,8 +10,47 @@ description: |- Use this data source to query detailed information of rds mysql instances ## Example Usage ```hcl -data "volcengine_rds_mysql_instances" "default" { - instance_id = "mysql-72da4258c2c7" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +data "volcengine_rds_mysql_instances" "foo" { + instance_id = volcengine_rds_mysql_instance.foo.id } ``` ## Argument Reference diff --git a/website/docs/r/rds_mysql_account.html.markdown b/website/docs/r/rds_mysql_account.html.markdown index 573ea846..e251320e 100644 --- a/website/docs/r/rds_mysql_account.html.markdown +++ b/website/docs/r/rds_mysql_account.html.markdown @@ -10,21 +10,58 @@ description: |- Provides a resource to manage rds mysql account ## Example Usage ```hcl -resource "volcengine_rds_mysql_account" "default" { - instance_id = "mysql-e9293705eed6" - account_name = "test" - account_password = "xdjsuiahHUH@" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test-db" + instance_id = volcengine_rds_mysql_instance.foo.id +} + +resource "volcengine_rds_mysql_account" "foo" { + account_name = "acc-test-account" + account_password = "93f0cb0614Aab12" account_type = "Normal" - # account_privileges{ - # db_name="tf-test-dbdddddd" - # account_privilege="ReadOnly" - # account_privilege_detail="SELECT,UPDATE,INSERT" - # } - # account_privileges{ - # db_name="test-xx" - # account_privilege="ReadOnly" - # account_privilege_detail="SELECT,UPDATE,INSERT" - # } + instance_id = volcengine_rds_mysql_instance.foo.id + account_privileges { + db_name = volcengine_rds_mysql_database.foo.db_name + account_privilege = "Custom" + account_privilege_detail = "SELECT,INSERT" + } } ``` ## Argument Reference diff --git a/website/docs/r/rds_mysql_allowlist.html.markdown b/website/docs/r/rds_mysql_allowlist.html.markdown index 81221379..5ee9cd5c 100644 --- a/website/docs/r/rds_mysql_allowlist.html.markdown +++ b/website/docs/r/rds_mysql_allowlist.html.markdown @@ -11,11 +11,10 @@ Provides a resource to manage rds mysql allowlist ## Example Usage ```hcl resource "volcengine_rds_mysql_allowlist" "foo" { - allow_list_name = "tf-test-opt" - allow_list_desc = "terraform test zzm" - allow_list = [ - "127.0.0.1" - ] + allow_list_name = "acc-test-allowlist" + allow_list_desc = "acc-test" + allow_list_type = "IPv4" + allow_list = ["192.168.0.0/24", "192.168.1.0/24"] } ``` ## Argument Reference diff --git a/website/docs/r/rds_mysql_allowlist_associate.html.markdown b/website/docs/r/rds_mysql_allowlist_associate.html.markdown index 7a3b848e..04f60f97 100644 --- a/website/docs/r/rds_mysql_allowlist_associate.html.markdown +++ b/website/docs/r/rds_mysql_allowlist_associate.html.markdown @@ -10,9 +10,53 @@ description: |- Provides a resource to manage rds mysql allowlist associate ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-vpc" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-test-subnet" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + instance_name = "acc-test-rds-mysql" + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + lower_case_table_names = "1" + charge_info { + charge_type = "PostPaid" + } + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_allowlist" "foo" { + allow_list_name = "acc-test-allowlist" + allow_list_desc = "acc-test" + allow_list_type = "IPv4" + allow_list = ["192.168.0.0/24", "192.168.1.0/24"] +} + resource "volcengine_rds_mysql_allowlist_associate" "foo" { - instance_id = "mysql-1b2c7b2d7583" - allow_list_id = "acl-15451212dcfa473baeda24be4baa02fe" + allow_list_id = volcengine_rds_mysql_allowlist.foo.id + instance_id = volcengine_rds_mysql_instance.foo.id } ``` ## Argument Reference diff --git a/website/docs/r/rds_mysql_database.html.markdown b/website/docs/r/rds_mysql_database.html.markdown index b84dbd72..996ecbc3 100644 --- a/website/docs/r/rds_mysql_database.html.markdown +++ b/website/docs/r/rds_mysql_database.html.markdown @@ -10,10 +10,48 @@ description: |- Provides a resource to manage rds mysql database ## Example Usage ```hcl -resource "volcengine_rds_mysql_database" "default" { - instance_id = "mysql-xxx" - db_name = "xxx" - character_set_name = "utf8" +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} + +resource "volcengine_rds_mysql_database" "foo" { + db_name = "acc-test" + instance_id = volcengine_rds_mysql_instance.foo.id } ``` ## Argument Reference diff --git a/website/docs/r/rds_mysql_instance.html.markdown b/website/docs/r/rds_mysql_instance.html.markdown index 7ae43550..5133ee25 100644 --- a/website/docs/r/rds_mysql_instance.html.markdown +++ b/website/docs/r/rds_mysql_instance.html.markdown @@ -10,22 +10,35 @@ description: |- Provides a resource to manage rds mysql instance ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + resource "volcengine_rds_mysql_instance" "foo" { db_engine_version = "MySQL_5_7" node_spec = "rds.mysql.1c2g" - primary_zone_id = "cn-guilin-a" - secondary_zone_id = "cn-guilin-b" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id storage_space = 80 - subnet_id = "subnet-2d72yi377stts58ozfdrlk9f6" - instance_name = "tf-test" + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" lower_case_table_names = "1" charge_info { charge_type = "PostPaid" } - allow_list_ids = ["acl-2dd8f8317e4d4159b21630d13ae2e6ec", "acl-2eaa2a053b2a4a58b988e38ae975e81c"] - parameters { parameter_name = "auto_increment_increment" parameter_value = "2" @@ -35,12 +48,6 @@ resource "volcengine_rds_mysql_instance" "foo" { parameter_value = "4" } } - -resource "volcengine_rds_mysql_instance_readonly_node" "readonly" { - instance_id = volcengine_rds_mysql_instance.foo.id - node_spec = "rds.mysql.2c4g" - zone_id = "cn-guilin-a" -} ``` ## Argument Reference The following arguments are supported: diff --git a/website/docs/r/rds_mysql_instance_readonly_node.html.markdown b/website/docs/r/rds_mysql_instance_readonly_node.html.markdown index 844e95be..69bc1830 100644 --- a/website/docs/r/rds_mysql_instance_readonly_node.html.markdown +++ b/website/docs/r/rds_mysql_instance_readonly_node.html.markdown @@ -10,10 +10,48 @@ description: |- Provides a resource to manage rds mysql instance readonly node ## Example Usage ```hcl +data "volcengine_zones" "foo" { +} + +resource "volcengine_vpc" "foo" { + vpc_name = "acc-test-project1" + cidr_block = "172.16.0.0/16" +} + +resource "volcengine_subnet" "foo" { + subnet_name = "acc-subnet-test-2" + cidr_block = "172.16.0.0/24" + zone_id = data.volcengine_zones.foo.zones[0].id + vpc_id = volcengine_vpc.foo.id +} + +resource "volcengine_rds_mysql_instance" "foo" { + db_engine_version = "MySQL_5_7" + node_spec = "rds.mysql.1c2g" + primary_zone_id = data.volcengine_zones.foo.zones[0].id + secondary_zone_id = data.volcengine_zones.foo.zones[0].id + storage_space = 80 + subnet_id = volcengine_subnet.foo.id + instance_name = "acc-test" + lower_case_table_names = "1" + + charge_info { + charge_type = "PostPaid" + } + + parameters { + parameter_name = "auto_increment_increment" + parameter_value = "2" + } + parameters { + parameter_name = "auto_increment_offset" + parameter_value = "4" + } +} resource "volcengine_rds_mysql_instance_readonly_node" "foo" { - instance_id = "mysql-b3fca7f571d6" - node_spec = "rds.mysql.1c2g" - zone_id = "cn-guilin-b" + instance_id = volcengine_rds_mysql_instance.foo.id + node_spec = "rds.mysql.2c4g" + zone_id = data.volcengine_zones.foo.zones[0].id } ``` ## Argument Reference From 6d28b7950120890406aebbdcb545203801345dca Mon Sep 17 00:00:00 2001 From: "maoshuai.17" Date: Wed, 6 Sep 2023 11:17:15 +0800 Subject: [PATCH 6/6] feat: add ecs_invocation_results --- common/common_volcengine_version.go | 2 +- ...ource_volcengine_ecs_invocation_results.go | 2 +- volcengine/provider.go | 18 ++++---- .../d/ecs_invocation_results.html.markdown | 44 +++++++++++++++++++ website/volcengine.erb | 3 ++ 5 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 website/docs/d/ecs_invocation_results.html.markdown diff --git a/common/common_volcengine_version.go b/common/common_volcengine_version.go index 1f4be772..60a1961f 100644 --- a/common/common_volcengine_version.go +++ b/common/common_volcengine_version.go @@ -2,5 +2,5 @@ package common const ( TerraformProviderName = "terraform-provider-volcengine" - TerraformProviderVersion = "0.0.106" + TerraformProviderVersion = "0.0.107" ) diff --git a/volcengine/ecs/ecs_invocation_result/data_source_volcengine_ecs_invocation_results.go b/volcengine/ecs/ecs_invocation_result/data_source_volcengine_ecs_invocation_results.go index 702b1d62..b43e7d1f 100644 --- a/volcengine/ecs/ecs_invocation_result/data_source_volcengine_ecs_invocation_results.go +++ b/volcengine/ecs/ecs_invocation_result/data_source_volcengine_ecs_invocation_results.go @@ -91,7 +91,7 @@ func DataSourceVolcengineEcsInvocationResults() *schema.Resource { "output": { Type: schema.TypeString, Computed: true, - Description: "The base64 encoded output message of the ecs invocation. ", + Description: "The base64 encoded output message of the ecs invocation.", }, "exit_code": { Type: schema.TypeInt, diff --git a/volcengine/provider.go b/volcengine/provider.go index 9489cb26..39629506 100644 --- a/volcengine/provider.go +++ b/volcengine/provider.go @@ -85,6 +85,7 @@ import ( "github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_instance" "github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_instance_state" "github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_invocation" + "github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_invocation_result" "github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_key_pair" "github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_key_pair_associate" "github.com/volcengine/terraform-provider-volcengine/volcengine/ecs/ecs_launch_template" @@ -262,14 +263,15 @@ func Provider() terraform.ResourceProvider { "volcengine_volumes": volume.DataSourceVolcengineVolumes(), // ================ ECS ================ - "volcengine_ecs_instances": ecs_instance.DataSourceVolcengineEcsInstances(), - "volcengine_images": image.DataSourceVolcengineImages(), - "volcengine_zones": zone.DataSourceVolcengineZones(), - "volcengine_ecs_deployment_sets": ecs_deployment_set.DataSourceVolcengineEcsDeploymentSets(), - "volcengine_ecs_key_pairs": ecs_key_pair.DataSourceVolcengineEcsKeyPairs(), - "volcengine_ecs_launch_templates": ecs_launch_template.DataSourceVolcengineEcsLaunchTemplates(), - "volcengine_ecs_commands": ecs_command.DataSourceVolcengineEcsCommands(), - "volcengine_ecs_invocations": ecs_invocation.DataSourceVolcengineEcsInvocations(), + "volcengine_ecs_instances": ecs_instance.DataSourceVolcengineEcsInstances(), + "volcengine_images": image.DataSourceVolcengineImages(), + "volcengine_zones": zone.DataSourceVolcengineZones(), + "volcengine_ecs_deployment_sets": ecs_deployment_set.DataSourceVolcengineEcsDeploymentSets(), + "volcengine_ecs_key_pairs": ecs_key_pair.DataSourceVolcengineEcsKeyPairs(), + "volcengine_ecs_launch_templates": ecs_launch_template.DataSourceVolcengineEcsLaunchTemplates(), + "volcengine_ecs_commands": ecs_command.DataSourceVolcengineEcsCommands(), + "volcengine_ecs_invocations": ecs_invocation.DataSourceVolcengineEcsInvocations(), + "volcengine_ecs_invocation_results": ecs_invocation_result.DataSourceVolcengineEcsInvocationResults(), // ================ NAT ================ "volcengine_snat_entries": snat_entry.DataSourceVolcengineSnatEntries(), diff --git a/website/docs/d/ecs_invocation_results.html.markdown b/website/docs/d/ecs_invocation_results.html.markdown new file mode 100644 index 00000000..ef9c2c80 --- /dev/null +++ b/website/docs/d/ecs_invocation_results.html.markdown @@ -0,0 +1,44 @@ +--- +subcategory: "ECS" +layout: "volcengine" +page_title: "Volcengine: volcengine_ecs_invocation_results" +sidebar_current: "docs-volcengine-datasource-ecs_invocation_results" +description: |- + Use this data source to query detailed information of ecs invocation results +--- +# volcengine_ecs_invocation_results +Use this data source to query detailed information of ecs invocation results +## Example Usage +```hcl +data "volcengine_ecs_invocation_results" "default" { + invocation_id = "ivk-ych9y4vujvl8j01c****" + invocation_result_status = ["Success"] +} +``` +## Argument Reference +The following arguments are supported: +* `invocation_id` - (Required) The id of ecs invocation. +* `command_id` - (Optional) The id of ecs command. +* `instance_id` - (Optional) The id of ecs instance. +* `invocation_result_status` - (Optional) The list of status of ecs invocation in a single instance. Valid values: `Pending`, `Running`, `Success`, `Failed`, `Timeout`. +* `output_file` - (Optional) File name where to save data source results. + +## Attributes Reference +In addition to all arguments above, the following attributes are exported: +* `invocation_results` - The collection of query. + * `command_id` - The id of the ecs command. + * `end_time` - The end time of the ecs invocation in the instance. + * `error_code` - The error code of the ecs invocation. + * `error_message` - The error message of the ecs invocation. + * `exit_code` - The exit code of the ecs command. + * `id` - The id of the ecs invocation result. + * `instance_id` - The id of the ecs instance. + * `invocation_id` - The id of the ecs invocation. + * `invocation_result_id` - The id of the ecs invocation result. + * `invocation_result_status` - The status of ecs invocation in a single instance. + * `output` - The base64 encoded output message of the ecs invocation. + * `start_time` - The start time of the ecs invocation in the instance. + * `username` - The username of the ecs command. +* `total_count` - The total count of query. + + diff --git a/website/volcengine.erb b/website/volcengine.erb index 6b5a7e14..96398b9a 100644 --- a/website/volcengine.erb +++ b/website/volcengine.erb @@ -352,6 +352,9 @@
  • ecs_invocations
  • +
  • + ecs_invocation_results +
  • ecs_key_pairs