From c9259f22656e3d3317f0fe64b310594fe388989a Mon Sep 17 00:00:00 2001 From: zhukun <2019229048@tju.edu.cn> Date: Thu, 2 Nov 2023 17:04:57 +0800 Subject: [PATCH] dms_branch --- docs/data-sources/dms_maintainwindow.md | 34 + ..._flexibleengine_dms_maintainwindow_test.go | 35 + ...exibleengine_dms_rabbitmq_instance_test.go | 767 ++++++++++++++++++ flexibleengine/provider.go | 1 + 4 files changed, 837 insertions(+) create mode 100644 docs/data-sources/dms_maintainwindow.md create mode 100644 flexibleengine/acceptance/data_source_flexibleengine_dms_maintainwindow_test.go create mode 100644 flexibleengine/acceptance/resource_flexibleengine_dms_rabbitmq_instance_test.go diff --git a/docs/data-sources/dms_maintainwindow.md b/docs/data-sources/dms_maintainwindow.md new file mode 100644 index 00000000..2d37cbe9 --- /dev/null +++ b/docs/data-sources/dms_maintainwindow.md @@ -0,0 +1,34 @@ +--- +subcategory: "Distributed Message Service (DMS)" +--- + +# flexibleengine_dms_maintainwindow + +Use this data source to get the ID of an available FlexibleEngine dms maintainwindow. + +## Example Usage + +```hcl +data "flexibleengine_dms_maintainwindow" "maintainwindow1" { + seq = 1 +} +``` + +## Argument Reference + +* `region` - (Optional, String) The region in which to obtain the dms maintainwindows. If omitted, the provider-level + region will be used. + +* `seq` - (Optional, Int) Indicates the sequential number of a maintenance time window. + +* `begin` - (Optional, String) Indicates the time at which a maintenance time window starts. + +* `end` - (Optional, String) Indicates the time at which a maintenance time window ends. + +* `default` - (Optional, Bool) Indicates whether a maintenance time window is set to the default time segment. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - Specifies a data source ID in UUID format. diff --git a/flexibleengine/acceptance/data_source_flexibleengine_dms_maintainwindow_test.go b/flexibleengine/acceptance/data_source_flexibleengine_dms_maintainwindow_test.go new file mode 100644 index 00000000..bd5e37d9 --- /dev/null +++ b/flexibleengine/acceptance/data_source_flexibleengine_dms_maintainwindow_test.go @@ -0,0 +1,35 @@ +package acceptance + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" +) + +func TestAccDmsMaintainWindowDataSource_basic(t *testing.T) { + dataSourceName := "data.flexibleengine_dms_maintainwindow.maintainwindow1" + dc := acceptance.InitDataSourceCheck(dataSourceName) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccDmsMaintainWindowDataSource_basic, + Check: resource.ComposeTestCheckFunc( + dc.CheckResourceExists(), + resource.TestCheckResourceAttr(dataSourceName, "seq", "1"), + resource.TestCheckResourceAttr(dataSourceName, "begin", "22:00:00"), + ), + }, + }, + }) +} + +var testAccDmsMaintainWindowDataSource_basic = ` +data "flexibleengine_dms_maintainwindow" "maintainwindow1" { + seq = 1 +} +` diff --git a/flexibleengine/acceptance/resource_flexibleengine_dms_rabbitmq_instance_test.go b/flexibleengine/acceptance/resource_flexibleengine_dms_rabbitmq_instance_test.go new file mode 100644 index 00000000..de7146d0 --- /dev/null +++ b/flexibleengine/acceptance/resource_flexibleengine_dms_rabbitmq_instance_test.go @@ -0,0 +1,767 @@ +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + "github.com/chnsz/golangsdk/openstack/dms/v2/rabbitmq/instances" + + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" +) + +func getDmsRabbitMqInstanceFunc(c *config.Config, state *terraform.ResourceState) (interface{}, error) { + client, err := c.DmsV2Client(OS_REGION_NAME) + if err != nil { + return nil, fmt.Errorf("error creating FlexibleEngine DMS client(V2): %s", err) + } + return instances.Get(client, state.Primary.ID).Extract() +} + +func getKafkaInstanceFunc(c *config.Config, state *terraform.ResourceState) (interface{}, error) { + client, err := c.DmsV2Client(acceptance.HW_REGION_NAME) + if err != nil { + return nil, fmt.Errorf("error creating HuaweiCloud DMS client(V2): %s", err) + } + return instances.Get(client, state.Primary.ID).Extract() +} + +func TestAccDmsRabbitmqInstances_basic(t *testing.T) { + var instance instances.Instance + rName := acceptance.RandomAccResourceNameWithDash() + updateName := acceptance.RandomAccResourceNameWithDash() + resourceName := "flexibleengine_dms_rabbitmq_instance.test" + rc := acceptance.InitResourceCheck( + resourceName, + &instance, + getDmsRabbitMqInstanceFunc, + ) + + // DMS instances use the tenant-level shared lock, the instances cannot be created or modified in parallel. + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccDmsRabbitmqInstance_basic(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "engine", "rabbitmq"), + resource.TestCheckResourceAttr(resourceName, "tags.key", "value"), + resource.TestCheckResourceAttr(resourceName, "tags.owner", "terraform"), + ), + }, + { + Config: testAccDmsRabbitmqInstance_update(rName, updateName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", updateName), + acceptance.TestCheckResourceAttrWithVariable(resourceName, "product_id", "${data.huaweicloud_dms_product.test2.id}"), + resource.TestCheckResourceAttr(resourceName, "description", "rabbitmq test update"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value"), + resource.TestCheckResourceAttr(resourceName, "tags.owner", "terraform_update"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", "used_storage_space", + }, + }, + }, + }) +} + +func TestAccDmsRabbitmqInstances_newFormat_cluster(t *testing.T) { + var instance instances.Instance + rName := acceptance.RandomAccResourceNameWithDash() + updateName := acceptance.RandomAccResourceNameWithDash() + resourceName := "flexibleengine_dms_rabbitmq_instance.test" + rc := acceptance.InitResourceCheck( + resourceName, + &instance, + getDmsRabbitMqInstanceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccDmsRabbitmqInstance_newFormat_cluster(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "description", "rabbitmq test"), + resource.TestCheckResourceAttr(resourceName, "tags.key", "value"), + resource.TestCheckResourceAttr(resourceName, "tags.owner", "terraform"), + ), + }, + { + Config: testAccDmsRabbitmqInstance_newFormat_cluster_update(rName, updateName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", updateName), + resource.TestCheckResourceAttr(resourceName, "description", "rabbitmq test update"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value"), + resource.TestCheckResourceAttr(resourceName, "tags.owner", "terraform_update"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", "used_storage_space", + }, + }, + }, + }) +} + +func TestAccDmsRabbitmqInstances_newFormat_single(t *testing.T) { + var instance instances.Instance + rName := acceptance.RandomAccResourceNameWithDash() + updateName := acceptance.RandomAccResourceNameWithDash() + resourceName := "flexibleengine_dms_rabbitmq_instance.test" + rc := acceptance.InitResourceCheck( + resourceName, + &instance, + getDmsRabbitMqInstanceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccDmsRabbitmqInstance_newFormat_single(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "description", "rabbitmq test"), + resource.TestCheckResourceAttr(resourceName, "tags.key", "value"), + resource.TestCheckResourceAttr(resourceName, "tags.owner", "terraform"), + ), + }, + { + Config: testAccDmsRabbitmqInstance_newFormat_single_update(rName, updateName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", updateName), + resource.TestCheckResourceAttr(resourceName, "description", "rabbitmq test update"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value"), + resource.TestCheckResourceAttr(resourceName, "tags.owner", "terraform_update"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", "used_storage_space", + }, + }, + }, + }) +} + +func TestAccDmsRabbitmqInstances_prePaid(t *testing.T) { + var instance instances.Instance + rName := acceptance.RandomAccResourceNameWithDash() + updateName := rName + "update" + resourceName := "flexibleengine_dms_rabbitmq_instance.test" + + rc := acceptance.InitResourceCheck( + resourceName, + &instance, + getKafkaInstanceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccDmsRabbitmqInstance_prePaid(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "description", "rabbitmq test"), + resource.TestCheckResourceAttr(resourceName, "tags.key", "value"), + resource.TestCheckResourceAttr(resourceName, "tags.owner", "terraform"), + resource.TestCheckResourceAttr(resourceName, "charging_mode", "prePaid"), + resource.TestCheckResourceAttr(resourceName, "broker_num", "3"), + ), + }, + { + Config: testAccDmsRabbitmqInstance_prePaid_update(rName, updateName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", updateName), + resource.TestCheckResourceAttr(resourceName, "description", "rabbitmq test update"), + resource.TestCheckResourceAttr(resourceName, "tags.key1", "value"), + resource.TestCheckResourceAttr(resourceName, "tags.owner", "terraform_update"), + resource.TestCheckResourceAttr(resourceName, "charging_mode", "prePaid"), + resource.TestCheckResourceAttr(resourceName, "broker_num", "3"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", + "auto_renew", + "period", + "period_unit", + }, + }, + }, + }) +} + +func TestAccDmsRabbitmqInstances_withEpsId(t *testing.T) { + var instance instances.Instance + rName := acceptance.RandomAccResourceNameWithDash() + resourceName := "flexibleengine_dms_rabbitmq_instance.test" + rc := acceptance.InitResourceCheck( + resourceName, + &instance, + getDmsRabbitMqInstanceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.TestAccPreCheckEpsID(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccDmsRabbitmqInstance_withEpsId(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "engine", "rabbitmq"), + resource.TestCheckResourceAttr(resourceName, "tags.key", "value"), + resource.TestCheckResourceAttr(resourceName, "tags.owner", "terraform"), + resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", OS_ENTERPRISE_PROJECT_ID_TEST), + ), + }, + }, + }) +} + +func TestAccDmsRabbitmqInstances_compatible(t *testing.T) { + var instance instances.Instance + rName := acceptance.RandomAccResourceNameWithDash() + resourceName := "flexibleengine_dms_rabbitmq_instance.test" + rc := acceptance.InitResourceCheck( + resourceName, + &instance, + getDmsRabbitMqInstanceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccDmsRabbitmqInstance_compatible(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + resource.TestCheckResourceAttr(resourceName, "name", rName), + resource.TestCheckResourceAttr(resourceName, "engine", "rabbitmq"), + resource.TestCheckResourceAttr(resourceName, "tags.key", "value"), + resource.TestCheckResourceAttr(resourceName, "tags.owner", "terraform"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + "password", "used_storage_space", + }, + }, + }, + }) +} + +func TestAccDmsRabbitmqInstances_single(t *testing.T) { + var instance instances.Instance + rName := acceptance.RandomAccResourceNameWithDash() + resourceName := "flexibleengine_dms_rabbitmq_instance.test" + rc := acceptance.InitResourceCheck( + resourceName, + &instance, + getDmsRabbitMqInstanceFunc, + ) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + CheckDestroy: rc.CheckResourceDestroy(), + Steps: []resource.TestStep{ + { + Config: testAccDmsRabbitmqInstance_single(rName), + Check: resource.ComposeTestCheckFunc( + rc.CheckResourceExists(), + ), + }, + }, + }) +} + +func testAccDmsRabbitmqInstance_Base(rName string) string { + return fmt.Sprintf(` +%s + +data "flexibleengine_availability_zones" "test" {} + +data "flexibleengine_dms_product" "test1" { + engine = "rabbitmq" + version = "3.8.35" + bandwidth = "100MB" + node_num = 3 +} + +data "flexibleengine_dms_product" "test2" { + engine = "rabbitmq" + instance_type = "cluster" + version = "3.8.35" + node_num = 5 +} +`, testBaseNetwork(rName)) +} + +func testAccDmsRabbitmqInstance_basic(rName string) string { + return fmt.Sprintf(` +%s + +resource "flexibleengine_dms_rabbitmq_instance" "test" { + name = "%s" + description = "rabbitmq test" + + vpc_id = flexibleengine_vpc_v1.test.id + network_id = flexibleengine_vpc_subnet_v1.test.id + security_group_id = flexibleengine_networking_secgroup_v2.test.id + availability_zones = [ + data.flexibleengine_availability_zones.test.names[0] + ] + + product_id = data.flexibleengine_dms_product.test1.id + engine_version = data.flexibleengine_dms_product.test1.version + storage_spec_code = data.flexibleengine_dms_product.test1.storage_spec_code + + access_user = "user" + password = "Rabbitmqtest@123" + + tags = { + key = "value" + owner = "terraform" + } +} +`, testAccDmsRabbitmqInstance_Base(rName), rName) +} + +func testAccDmsRabbitmqInstance_update(rName, updateName string) string { + return fmt.Sprintf(` +%s + +resource "flexibleengine_dms_rabbitmq_instance" "test" { + name = "%s" + description = "rabbitmq test update" + + vpc_id = flexibleengine_vpc_v1.test.id + network_id = flexibleengine_vpc_subnet_v1.test.id + security_group_id = flexibleengine_networking_secgroup_v2.test.id + availability_zones = [ + data.flexibleengine_availability_zones.test.names[0] + ] + + product_id = data.flexibleengine_dms_product.test2.id + engine_version = data.flexibleengine_dms_product.test2.version + storage_spec_code = data.flexibleengine_dms_product.test2.storage_spec_code + + access_user = "user" + password = "Rabbitmqtest@123" + + tags = { + key1 = "value" + owner = "terraform_update" + } +} +`, testAccDmsRabbitmqInstance_Base(rName), updateName) +} + +func testAccDmsRabbitmqInstance_withEpsId(rName string) string { + return fmt.Sprintf(` +%s + +resource "flexibleengine_dms_rabbitmq_instance" "test" { + name = "%s" + description = "rabbitmq test" + enterprise_project_id = "%s" + + vpc_id = flexibleengine_vpc_v1.test.id + network_id = flexibleengine_vpc_subnet_v1.test.id + security_group_id = flexibleengine_networking_secgroup_v2.test.id + availability_zones = [ + data.flexibleengine_availability_zones.test.names[0], + data.flexibleengine_availability_zones.test.names[1] + ] + + product_id = data.flexibleengine_dms_product.test1.id + engine_version = data.flexibleengine_dms_product.test1.version + storage_spec_code = data.flexibleengine_dms_product.test1.storage_spec_code + + access_user = "user" + password = "Rabbitmqtest@123" + + tags = { + key = "value" + owner = "terraform" + } +} +`, testAccDmsRabbitmqInstance_Base(rName), rName, OS_ENTERPRISE_PROJECT_ID_TEST) +} + +// After the 1.31.1 version, arguments storage_space and available_zones are deprecated. +func testAccDmsRabbitmqInstance_compatible(rName string) string { + return fmt.Sprintf(` +%s + +data "huaweicloud_dms_az" "test" {} +resource "flexibleengine_dms_rabbitmq_instance" "test" { + name = "%s" + description = "rabbitmq test" + + vpc_id = flexibleengine_vpc_v1.test.id + network_id = flexibleengine_vpc_subnet_v1.test.id + security_group_id = flexibleengine_networking_secgroup_v2.test.id + available_zones = [data.huaweicloud_dms_az.test.id] + + product_id = data.flexibleengine_dms_product.test1.id + engine_version = data.flexibleengine_dms_product.test1.version + storage_space = data.flexibleengine_dms_product.test1.storage + storage_spec_code = data.flexibleengine_dms_product.test1.storage_spec_code + + + access_user = "user" + password = "Rabbitmqtest@123" + + tags = { + key = "value" + owner = "terraform" + } +} +`, testAccDmsRabbitmqInstance_Base(rName), rName) +} + +func testAccDmsRabbitmqInstance_single(rName string) string { + randPwd := fmt.Sprintf("%s!#%d", acctest.RandString(5), acctest.RandIntRange(0, 999)) + return fmt.Sprintf(` +%[1]s + +data "flexibleengine_dms_product" "single" { + engine = "rabbitmq" + instance_type = "single" + version = "3.8.35" + node_num = 1 +} + +resource "flexibleengine_dms_rabbitmq_instance" "test" { + availability_zones = [ + data.flexibleengine_availability_zones.test.names[0], + ] + + name = "%[2]s" + vpc_id = flexibleengine_vpc_v1.test.id + network_id = flexibleengine_vpc_subnet_v1.test.id + security_group_id = flexibleengine_networking_secgroup_v2.test.id + + product_id = data.flexibleengine_dms_product.single.id + engine_version = data.flexibleengine_dms_product.single.version + storage_spec_code = data.flexibleengine_dms_product.single.storage_spec_code + storage_space = data.flexibleengine_dms_product.single.storage + + access_user = "root" + password = "%[3]s" +} +`, testAccDmsRabbitmqInstance_Base(rName), rName, randPwd) +} + +func testAccDmsRabbitmqInstance_newFormat_cluster(rName string) string { + return fmt.Sprintf(` +%s + +data "flexibleengine_availability_zones" "test" {} + +data "huaweicloud_dms_rabbitmq_flavors" "test" { + type = "cluster" +} + +locals { + query_results = data.huaweicloud_dms_rabbitmq_flavors.test + flavor = data.huaweicloud_dms_rabbitmq_flavors.test.flavors[0] +} + +resource "flexibleengine_dms_rabbitmq_instance" "test" { + name = "%s" + description = "rabbitmq test" + + vpc_id = flexibleengine_vpc_v1.test.id + network_id = flexibleengine_vpc_subnet_v1.test.id + security_group_id = flexibleengine_networking_secgroup_v2.test.id + + availability_zones = [ + data.flexibleengine_availability_zones.test.names[0] + ] + + flavor_id = local.flavor.id + engine_version = element(local.query_results.versions, length(local.query_results.versions)-1) + storage_space = local.flavor.properties[0].min_broker * local.flavor.properties[0].min_storage_per_node + storage_spec_code = local.flavor.ios[0].storage_spec_code + broker_num = 3 + access_user = "user" + password = "Rabbitmqtest@123" + + tags = { + key = "value" + owner = "terraform" + } +}`, testBaseNetwork(rName), rName) +} + +func testAccDmsRabbitmqInstance_newFormat_cluster_update(rName, updateName string) string { + return fmt.Sprintf(` +%s + +data "flexibleengine_availability_zones" "test" {} + +data "huaweicloud_dms_rabbitmq_flavors" "test" { + type = "cluster" +} + +locals { + query_results = data.huaweicloud_dms_rabbitmq_flavors.test + flavor = data.huaweicloud_dms_rabbitmq_flavors.test.flavors[0] + newFlavor = data.huaweicloud_dms_rabbitmq_flavors.test.flavors[1] +} + +resource "flexibleengine_dms_rabbitmq_instance" "test" { + name = "%s" + description = "rabbitmq test update" + + vpc_id = flexibleengine_vpc_v1.test.id + network_id = flexibleengine_vpc_subnet_v1.test.id + security_group_id = flexibleengine_networking_secgroup_v2.test.id + + availability_zones = [ + data.flexibleengine_availability_zones.test.names[0] + ] + + flavor_id = local.newFlavor.id + engine_version = element(local.query_results.versions, length(local.query_results.versions)-1) + storage_space = 1000 + storage_spec_code = local.flavor.ios[0].storage_spec_code + broker_num = 5 + access_user = "user" + password = "Rabbitmqtest@123" + + tags = { + key1 = "value" + owner = "terraform_update" + } +}`, testBaseNetwork(rName), updateName) +} + +func testAccDmsRabbitmqInstance_newFormat_single(rName string) string { + return fmt.Sprintf(` +%s + +data "flexibleengine_availability_zones" "test" {} + +data "huaweicloud_dms_rabbitmq_flavors" "test" { + type = "single" +} + +locals { + query_results = data.huaweicloud_dms_rabbitmq_flavors.test + flavor = data.huaweicloud_dms_rabbitmq_flavors.test.flavors[0] +} + +resource "flexibleengine_dms_rabbitmq_instance" "test" { + name = "%s" + description = "rabbitmq test" + + vpc_id = flexibleengine_vpc_v1.test.id + network_id = flexibleengine_vpc_subnet_v1.test.id + security_group_id = flexibleengine_networking_secgroup_v2.test.id + + availability_zones = [ + data.flexibleengine_availability_zones.test.names[0] + ] + + flavor_id = local.flavor.id + engine_version = element(local.query_results.versions, length(local.query_results.versions)-1) + storage_space = local.flavor.properties[0].min_broker * local.flavor.properties[0].min_storage_per_node + storage_spec_code = local.flavor.ios[0].storage_spec_code + access_user = "user" + password = "Rabbitmqtest@123" + + tags = { + key = "value" + owner = "terraform" + } +}`, testBaseNetwork(rName), rName) +} + +func testAccDmsRabbitmqInstance_newFormat_single_update(rName, updateName string) string { + return fmt.Sprintf(` +%s + +data "flexibleengine_availability_zones" "test" {} + +data "huaweicloud_dms_rabbitmq_flavors" "test" { + type = "single" +} + +locals { + query_results = data.huaweicloud_dms_rabbitmq_flavors.test + newFlavor = data.huaweicloud_dms_rabbitmq_flavors.test.flavors[1] +} + +resource "flexibleengine_dms_rabbitmq_instance" "test" { + name = "%s" + description = "rabbitmq test update" + + vpc_id = flexibleengine_vpc_v1.test.id + network_id = flexibleengine_vpc_subnet_v1.test.id + security_group_id = flexibleengine_networking_secgroup_v2.test.id + + availability_zones = [ + data.flexibleengine_availability_zones.test.names[0] + ] + + flavor_id = local.newFlavor.id + engine_version = element(local.query_results.versions, length(local.query_results.versions)-1) + storage_space = 600 + storage_spec_code = local.newFlavor.ios[0].storage_spec_code + access_user = "user" + password = "Rabbitmqtest@123" + + tags = { + key1 = "value" + owner = "terraform_update" + } +}`, testBaseNetwork(rName), updateName) +} + +func testAccDmsRabbitmqInstance_prePaid(rName string) string { + return fmt.Sprintf(` +%s + +data "flexibleengine_availability_zones" "test" {} + +data "huaweicloud_dms_rabbitmq_flavors" "test" { + type = "cluster" +} + +locals { + query_results = data.huaweicloud_dms_rabbitmq_flavors.test + flavor = data.huaweicloud_dms_rabbitmq_flavors.test.flavors[0] +} + +resource "flexibleengine_dms_rabbitmq_instance" "test" { + name = "%s" + description = "rabbitmq test" + + vpc_id = flexibleengine_vpc_v1.test.id + network_id = flexibleengine_vpc_subnet_v1.test.id + security_group_id = flexibleengine_networking_secgroup_v2.test.id + + availability_zones = [ + data.flexibleengine_availability_zones.test.names[0] + ] + + flavor_id = local.flavor.id + engine_version = element(local.query_results.versions, length(local.query_results.versions)-1) + storage_space = local.flavor.properties[0].min_broker * local.flavor.properties[0].min_storage_per_node + storage_spec_code = local.flavor.ios[0].storage_spec_code + broker_num = 3 + + access_user = "user" + password = "Rabbitmqtest@123" + + charging_mode = "prePaid" + period_unit = "month" + period = 1 + auto_renew = true + + tags = { + key = "value" + owner = "terraform" + } +}`, testBaseNetwork(rName), rName) +} + +func testAccDmsRabbitmqInstance_prePaid_update(rName, updateName string) string { + return fmt.Sprintf(` +%s + +data "flexibleengine_availability_zones" "test" {} + +data "huaweicloud_dms_rabbitmq_flavors" "test" { + type = "cluster" +} + +locals { + query_results = data.huaweicloud_dms_rabbitmq_flavors.test + flavor = data.huaweicloud_dms_rabbitmq_flavors.test.flavors[0] +} + +resource "flexibleengine_dms_rabbitmq_instance" "test" { + name = "%s" + description = "rabbitmq test update" + + vpc_id = flexibleengine_vpc_v1.test.id + network_id = flexibleengine_vpc_subnet_v1.test.id + security_group_id = flexibleengine_networking_secgroup_v2.test.id + + availability_zones = [ + data.flexibleengine_availability_zones.test.names[0] + ] + + flavor_id = local.flavor.id + engine_version = element(local.query_results.versions, length(local.query_results.versions)-1) + storage_space = local.flavor.properties[0].min_broker * local.flavor.properties[0].min_storage_per_node + storage_spec_code = local.flavor.ios[0].storage_spec_code + broker_num = 3 + + access_user = "user" + password = "Rabbitmqtest@123" + + charging_mode = "prePaid" + period_unit = "month" + period = 1 + auto_renew = true + + tags = { + key1 = "value" + owner = "terraform_update" + } +}`, testBaseNetwork(rName), updateName) +} diff --git a/flexibleengine/provider.go b/flexibleengine/provider.go index 6be2041f..6bdfdc30 100644 --- a/flexibleengine/provider.go +++ b/flexibleengine/provider.go @@ -296,6 +296,7 @@ func Provider() *schema.Provider { "flexibleengine_dms_kafka_instances": dms.DataSourceDmsKafkaInstances(), "flexibleengine_dms_rocketmq_broker": dms.DataSourceDmsRocketMQBroker(), "flexibleengine_dms_rocketmq_instances": dms.DataSourceDmsRocketMQInstances(), + "flexibleengine_dms_maintainwindow": dms.DataSourceDmsMaintainWindow(), "flexibleengine_dws_flavors": dws.DataSourceDwsFlavors(), "flexibleengine_elb_certificate": elb.DataSourceELBCertificateV3(),