Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dws): add new resource and datasource to manage schema space management #5546

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions docs/data-sources/dws_schema_space_managements.md
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 schemas 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.
58 changes: 58 additions & 0 deletions docs/resources/dws_schema_space_management.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
subcategory: "GaussDB(DWS)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_dws_schema_space_management"
description: |-
Use this resource to modify schema space limit under specified DWS cluster within HuaweiCloud.
---
# huaweicloud_dws_schema_space_management

Use this resource to modify schema space limit under specified DWS cluster within HuaweiCloud.

-> 1. This resource is supported only in `8.1.1` or later.
<br>2. The space quota limit only common users but not database administrators.
<br>3.This resource is only a one-time action resource for modifying schema space limit. Deleting this resource will
not clear the corresponding request record, but will only remove the resource information from the tfstate file.

## Example Usage

```hcl
variable "dws_cluster_id" {}
variable "database_name" {}
variable "schema_name" {}

resource "huaweicloud_dws_schema_space_management" "test" {
cluster_id = var.dws_cluster_id
database_name = var.database_name
schema_name = var.schema_name
space_limit = "1024"
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
If omitted, the provider-level region will be used.
Changing this creates a new resource.

* `cluster_id` - (Required, String, ForceNew) Specifies the DWS cluster ID.
Changing this creates a new resource.

* `database_name` - (Required, String, ForceNew) Specifies the database name to which the schema space management belongs.
Changing this creates a new resource.

* `schema_name` - (Required, String, ForceNew) Specifies the name of the schema.
Changing this creates a new resource.

* `space_limit` - (Required, String, ForceNew) Specifies space limit of the schema, in KB.
The valid value ranges from `-1` to `9,007,199,254,740,992`, `-1` and `0` means unlimited.

Changing this creates a new resource.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID.
2 changes: 2 additions & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@ func Provider() *schema.Provider {
"huaweicloud_dws_logical_clusters": dws.DataSourceDwsLogicalClusters(),
"huaweicloud_dws_om_account_configuration": dws.DataSourceOmAccountConfiguration(),
"huaweicloud_dws_quotas": dws.DataSourceDwsQuotas(),
"huaweicloud_dws_schema_space_managements": dws.DataSourceDwsSchemaSpaceManagements(),
"huaweicloud_dws_snapshot_policies": dws.DataSourceDwsSnapshotPolicies(),
"huaweicloud_dws_snapshots": dws.DataSourceDwsSnapshots(),
"huaweicloud_dws_workload_plans": dws.DataSourceDwsWorkloadPlans(),
Expand Down Expand Up @@ -1448,6 +1449,7 @@ func Provider() *schema.Provider {
"huaweicloud_dws_logical_cluster": dws.ResourceLogicalCluster(),
"huaweicloud_dws_om_account_action": dws.ResourceOmAccountAction(),
"huaweicloud_dws_public_domain_associate": dws.ResourcePublicDomainAssociate(),
"huaweicloud_dws_schema_space_management": dws.ResourceSchemaSpaceManagement(),
"huaweicloud_dws_snapshot_policy": dws.ResourceDwsSnapshotPolicy(),
"huaweicloud_dws_snapshot": dws.ResourceDwsSnapshot(),
"huaweicloud_dws_workload_configuration": dws.ResourceWorkLoadConfiguration(),
Expand Down
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)
}
Loading
Loading