-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dws): add new datasource to query schemas
- Loading branch information
1 parent
d2e977d
commit 62be019
Showing
4 changed files
with
387 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
subcategory: "GaussDB(DWS)" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_dws_schema_space_managements" | ||
description: |- | ||
Use this data source to get the list of schema space management information of the DWS Cluster within HuaweiCloud. | ||
--- | ||
|
||
# huaweicloud_dws_schema_space_managements | ||
|
||
Use this data source to get the list of schema space management information of the DWS Cluster within HuaweiCloud. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable "dws_cluster_id" {} | ||
variable "database_name" {} | ||
data "huaweicloud_dws_schema_space_managements" "test" { | ||
cluster_id = var.dws_cluster_id | ||
database_name = var.database_name | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String) Specifies the region in which to query the resource. | ||
If omitted, the provider-level region will be used. | ||
|
||
* `cluster_id` - (Required, String) Specifies the DWS cluster ID. | ||
|
||
* `database_name` - (Required, String) Specifies the database name to which the schema space management belongs. | ||
|
||
* `schema_name` - (Optional, String) Specifies the name of the schema. Fuzzy search is supported. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `schemas` - All schema space management that match the filter parameters. | ||
|
||
The [schemas](#schemas_struct) structure is documented below. | ||
|
||
<a name="schemas_struct"></a> | ||
The `schemas` block supports: | ||
|
||
* `database_name` - The database name corresponding to the schema. | ||
|
||
* `schema_name` - The name of the schema. | ||
|
||
* `used` - The number of schema spaces used, in bytes. | ||
|
||
* `space_limit` - The number of available spaces, in bytes. | ||
|
||
* `skew_percent` - The skew rate of the schema. | ||
|
||
* `min_value` - The number of used spaces by the DN with the minimum usage, in bytes. | ||
|
||
* `max_value` - The number of used spaces by the DN with the maximum usage, in bytes. | ||
|
||
* `dn_num` - The number of DNs. | ||
|
||
* `min_dn` - The DN that uses the least space. | ||
|
||
* `max_dn` - The DN that uses the most space. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
...loud/services/acceptance/dws/data_source_huaweicloud_dws_schema_space_managements_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package dws | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/go-uuid" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
) | ||
|
||
func TestAccDataSourceSchemaSpaceManagements_basic(t *testing.T) { | ||
var ( | ||
notFoundDatabase = "data.huaweicloud_dws_schema_space_managements.test" | ||
dcNotFoundDatabase = acceptance.InitDataSourceCheck(notFoundDatabase) | ||
dataSource = "data.huaweicloud_dws_schema_space_managements.test" | ||
dc = acceptance.InitDataSourceCheck(dataSource) | ||
bySchemaName = "data.huaweicloud_dws_schema_space_managements.filter_by_schema_name" | ||
dcBySchemaName = acceptance.InitDataSourceCheck(bySchemaName) | ||
) | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
acceptance.TestAccPreCheckDwsClusterId(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceSchemaSpaceManagements_clusterIdNotExist(), | ||
ExpectError: regexp.MustCompile("Cluster does not exist or has been deleted"), | ||
}, | ||
{ | ||
Config: testDataSourceSchemaSpaceManagements_basic(), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
dcNotFoundDatabase.CheckResourceExists(), | ||
resource.TestCheckOutput("not_found_database", "true"), | ||
resource.TestMatchResourceAttr(dataSource, "schemas.#", regexp.MustCompile(`^[1-9]([0-9]*)?$`)), | ||
resource.TestCheckOutput("assert_space_limit", "true"), | ||
dcBySchemaName.CheckResourceExists(), | ||
resource.TestCheckResourceAttr(bySchemaName, "schemas.0.database_name", "gaussdb"), | ||
resource.TestCheckResourceAttrSet(bySchemaName, "schemas.0.schema_name"), | ||
resource.TestCheckResourceAttrSet(bySchemaName, "schemas.0.used"), | ||
resource.TestCheckResourceAttrSet(bySchemaName, "schemas.0.space_limit"), | ||
resource.TestCheckResourceAttrSet(bySchemaName, "schemas.0.skew_percent"), | ||
resource.TestCheckResourceAttrSet(bySchemaName, "schemas.0.dn_num"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceSchemaSpaceManagements_clusterIdNotExist() string { | ||
clusterId, _ := uuid.GenerateUUID() | ||
return fmt.Sprintf(` | ||
data "huaweicloud_dws_schema_space_managements" "test" { | ||
cluster_id = "%s" | ||
database_name = "gaussdb" | ||
} | ||
`, clusterId) | ||
} | ||
|
||
func testDataSourceSchemaSpaceManagements_basic() string { | ||
return fmt.Sprintf(` | ||
data "huaweicloud_dws_schema_space_managements" "not_found_database" { | ||
cluster_id = "%[1]s" | ||
database_name = "not_found_database" | ||
} | ||
output "not_found_database" { | ||
value = length(data.huaweicloud_dws_schema_space_managements.not_found_database.schemas) == 0 | ||
} | ||
data "huaweicloud_dws_schema_space_managements" "test" { | ||
depends_on = [ | ||
huaweicloud_dws_schema_space_management.test | ||
] | ||
cluster_id = "%[1]s" | ||
database_name = huaweicloud_dws_schema_space_management.test.database_name | ||
} | ||
# Modify space quota for scheduler to 2MB (2048 Byte). | ||
resource "huaweicloud_dws_schema_space_management" "test" { | ||
cluster_id = "%[1]s" | ||
database_name = "gaussdb" | ||
schema_name = "scheduler" | ||
space_limit = "2048" | ||
} | ||
# Filter by schema name. | ||
data "huaweicloud_dws_schema_space_managements" "filter_by_schema_name" { | ||
depends_on = [ | ||
huaweicloud_dws_schema_space_management.test | ||
] | ||
cluster_id = "%[1]s" | ||
database_name = huaweicloud_dws_schema_space_management.test.database_name | ||
schema_name = local.schema_name | ||
} | ||
locals { | ||
schema_name = huaweicloud_dws_schema_space_management.test.schema_name | ||
# Convert the obtained value from Byte to MB. | ||
space_limit = try([for v in data.huaweicloud_dws_schema_space_managements.filter_by_schema_name.schemas : ceil(v.space_limit / 1024 / 1024) | ||
if v.schema_name == local.schema_name][0], null) | ||
} | ||
output "assert_space_limit" { | ||
value = local.space_limit == 2 | ||
} | ||
`, acceptance.HW_DWS_CLUSTER_ID) | ||
} |
Oops, something went wrong.