From 47bf40b8df6c3f9d7fb0986d39b46049db295e16 Mon Sep 17 00:00:00 2001 From: dengyali0125 Date: Mon, 15 Jan 2024 10:51:16 +0800 Subject: [PATCH] feat(SDRS): Synchronized SDRS dataSources, unit test and document. --- docs/data-sources/sdrs_domain_v1.md | 16 ++++--- ...urce_flexibleengine_sdrs_domain_v1_test.go | 42 +++++++++++++++++++ flexibleengine/provider.go | 3 +- 3 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 flexibleengine/acceptance/data_source_flexibleengine_sdrs_domain_v1_test.go diff --git a/docs/data-sources/sdrs_domain_v1.md b/docs/data-sources/sdrs_domain_v1.md index 6630c8bc8..8848aeb6e 100644 --- a/docs/data-sources/sdrs_domain_v1.md +++ b/docs/data-sources/sdrs_domain_v1.md @@ -4,7 +4,7 @@ subcategory: "Storage Disaster Recovery Service (SDRS)" # flexibleengine_sdrs_domain_v1 -Use this data source to get the ID of an available FlexibleEngine SDRS domain. +Use this data source to get an available SDRS domain. ## Example Usage @@ -18,11 +18,17 @@ data "flexibleengine_sdrs_domain_v1" "dom_1" { ## Argument Reference -* `name` - (Optional, String) Specifies the name of an active-active domain. Currently only support SDRS_HypeDomain01. +The following arguments are supported: + +* `region` - (Optional, String) Specifies the region in which to query the data source. + If omitted, the provider-level region will be used. + +* `name` - (Optional, String) Specifies the name of an available SDRS domain. ## Attribute Reference -`id` is set to the ID of the active-active domain. In addition, the following attributes -are exported: +In addition to all arguments above, the following attributes are exported: + +* `id` - The resource ID. -* `description` - Specifies the description of an active-active domain. +* `description` - Indicates the description of the SDRS domain. diff --git a/flexibleengine/acceptance/data_source_flexibleengine_sdrs_domain_v1_test.go b/flexibleengine/acceptance/data_source_flexibleengine_sdrs_domain_v1_test.go new file mode 100644 index 000000000..a6ecea48e --- /dev/null +++ b/flexibleengine/acceptance/data_source_flexibleengine_sdrs_domain_v1_test.go @@ -0,0 +1,42 @@ +package acceptance + +import ( + "regexp" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" +) + +func TestAccSDRSDomainDataSource_basic(t *testing.T) { + rName := "data.flexibleengine_sdrs_domain_v1.test" + dc := acceptance.InitDataSourceCheck(rName) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ProviderFactories: TestAccProviderFactories, + Steps: []resource.TestStep{ + { + Config: testAccCheckSDRSDomainDataSource_basic, + Check: resource.ComposeTestCheckFunc( + dc.CheckResourceExists(), + resource.TestCheckResourceAttrSet(rName, "name"), + resource.TestCheckResourceAttrSet(rName, "description"), + ), + }, + { + Config: testAccCheckSDRSDomainDataSource_checkError, + ExpectError: regexp.MustCompile(`your query returned no results. Please change your search criteria and try again`), + }, + }, + }) +} + +const testAccCheckSDRSDomainDataSource_basic = ` +data "flexibleengine_sdrs_domain_v1" "test" {} +` + +const testAccCheckSDRSDomainDataSource_checkError = ` +data "flexibleengine_sdrs_domain_v1" "test" { + name = "error_check" +}` \ No newline at end of file diff --git a/flexibleengine/provider.go b/flexibleengine/provider.go index 5a861c878..c92c9aead 100644 --- a/flexibleengine/provider.go +++ b/flexibleengine/provider.go @@ -9,6 +9,7 @@ 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/services/sdrs" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud" "github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" @@ -292,7 +293,7 @@ func Provider() *schema.Provider { "flexibleengine_lb_certificate_v2": dataSourceCertificateV2(), "flexibleengine_lb_loadbalancer_v2": dataSourceELBV2Loadbalancer(), - "flexibleengine_sdrs_domain_v1": dataSourceSdrsDomainV1(), + "flexibleengine_sdrs_domain_v1": sdrs.DataSourceSDRSDomain(), "flexibleengine_identity_project_v3": dataSourceIdentityProjectV3(), "flexibleengine_identity_role_v3": dataSourceIdentityRoleV3(),