From f0911ea1b45158263611c250fb90a8e1c8499f31 Mon Sep 17 00:00:00 2001 From: Zippo-Wang <852420284@qq.com> Date: Wed, 11 Oct 2023 16:56:09 +0800 Subject: [PATCH] feat(ECS): import ECS resource, unit test and document. ### resourceName: data_source_flexibleengine_compute_servergroups --- docs/data-sources/compute_servergroups.md | 46 +++++++++++++++++++ ...lexibleengine_compute_servergroups_test.go | 46 +++++++++++++++++++ flexibleengine/provider.go | 7 ++- 3 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 docs/data-sources/compute_servergroups.md create mode 100644 flexibleengine/acceptance/data_source_flexibleengine_compute_servergroups_test.go diff --git a/docs/data-sources/compute_servergroups.md b/docs/data-sources/compute_servergroups.md new file mode 100644 index 00000000..99d610f5 --- /dev/null +++ b/docs/data-sources/compute_servergroups.md @@ -0,0 +1,46 @@ +--- +subcategory: "Elastic Cloud Server (ECS)" +--- + +# flexibleengine_compute_servergroups + +Use this data source to get the list of the compute server groups. + +## Example Usage + +```hcl +variable "name" {} + +data "flexibleengine_compute_servergroups" "test" { + name = var.name +} +``` + +## Argument Reference + +The following arguments are supported: + +* `region` - (Optional, String) Specifies the region in which to obtain the server groups. + If omitted, the provider-level region will be used. + +* `name` - (Optional, String) Specifies the server group name. + +## Attribute Reference + +In addition to all arguments above, the following attributes are exported: + +* `id` - The data source ID. + +* `servergroups` - List of ECS server groups details. The [servergroups](#ecs_servergroups) object structure is + documented below. + + +The `servergroups` block supports: + +* `id` - The server group ID in UUID format. + +* `name` - The server group name. + +* `policies` - The set of policies for the server group. + +* `members` - An array of one or more instance ID attached to the server group. diff --git a/flexibleengine/acceptance/data_source_flexibleengine_compute_servergroups_test.go b/flexibleengine/acceptance/data_source_flexibleengine_compute_servergroups_test.go new file mode 100644 index 00000000..7dc11d4f --- /dev/null +++ b/flexibleengine/acceptance/data_source_flexibleengine_compute_servergroups_test.go @@ -0,0 +1,46 @@ +package acceptance + +import ( + "fmt" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" +) + +func TestAccComputeServerGroupsDataSource_basic(t *testing.T) { + rName := acceptance.RandomAccResourceNameWithDash() + dataSourceName := "data.flexibleengine_compute_servergroups.test" + dc := acceptance.InitDataSourceCheck(dataSourceName) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccComputeServerGroupsDataSource_basic(rName), + Check: resource.ComposeTestCheckFunc( + dc.CheckResourceExists(), + resource.TestCheckResourceAttr(dataSourceName, "name", rName), + resource.TestCheckResourceAttr(dataSourceName, "servergroups.#", "1"), + resource.TestCheckResourceAttrSet(dataSourceName, "servergroups.0.id"), + resource.TestCheckResourceAttrSet(dataSourceName, "servergroups.0.name"), + ), + }, + }, + }) +} + +func testAccComputeServerGroupsDataSource_basic(rName string) string { + return fmt.Sprintf(` +resource "flexibleengine_compute_servergroup_v2" "test" { + name = "%s" + policies = ["anti-affinity"] +} + +data "flexibleengine_compute_servergroups" "test" { + name = flexibleengine_compute_servergroup_v2.test.name +} +`, rName) +} diff --git a/flexibleengine/provider.go b/flexibleengine/provider.go index 989b7a00..c6b2a871 100644 --- a/flexibleengine/provider.go +++ b/flexibleengine/provider.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/mutexkv" @@ -26,6 +25,7 @@ import ( "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/dms" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/drs" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/dws" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/ecs" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/eip" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/elb" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/eps" @@ -285,6 +285,8 @@ func Provider() *schema.Provider { "flexibleengine_cbr_vaults": cbr.DataSourceCbrVaultsV3(), "flexibleengine_cbr_backup": cbr.DataSourceBackup(), "flexibleengine_cce_clusters": cce.DataSourceCCEClusters(), + + "flexibleengine_compute_servergroups": ecs.DataSourceComputeServerGroups(), "flexibleengine_ddm_engines": ddm.DataSourceDdmEngines(), "flexibleengine_ddm_flavors": ddm.DataSourceDdmFlavors(), @@ -297,7 +299,8 @@ func Provider() *schema.Provider { "flexibleengine_dms_rocketmq_broker": dms.DataSourceDmsRocketMQBroker(), "flexibleengine_dms_rocketmq_instances": dms.DataSourceDmsRocketMQInstances(), - "flexibleengine_dws_flavors": dws.DataSourceDwsFlavors(), + "flexibleengine_dws_flavors": dws.DataSourceDwsFlavors(), + "flexibleengine_elb_certificate": elb.DataSourceELBCertificateV3(), "flexibleengine_fgs_dependencies": fgs.DataSourceFunctionGraphDependencies(),