-
Notifications
You must be signed in to change notification settings - Fork 163
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 resource supports schema space management
- Loading branch information
1 parent
98fb8ba
commit c8e6dfb
Showing
3 changed files
with
168 additions
and
0 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,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. |
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
109 changes: 109 additions & 0 deletions
109
huaweicloud/services/dws/resource_huaweicloud_dws_schema_space_management.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,109 @@ | ||
package dws | ||
|
||
import ( | ||
"context" | ||
"strings" | ||
|
||
"github.com/hashicorp/go-uuid" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"github.com/chnsz/golangsdk" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" | ||
) | ||
|
||
// @API APIG PUT /v2/{project_id}/clusters/{cluster_id}/databases/{database_name}/schemas | ||
func ResourceSchemaSpaceManagement() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceSchemaSpaceManagementCreate, | ||
ReadContext: resourceSchemaSpaceManagementRead, | ||
DeleteContext: resourceSchemaSpaceManagementDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"region": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, | ||
}, | ||
"cluster_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "Specifies the DWS cluster ID.", | ||
}, | ||
"database_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "Specifies the database name to which the schema space management belongs.", | ||
}, | ||
"schema_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "Specifies the name of the schema.", | ||
}, | ||
"space_limit": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "Specifies space limit of the schema.", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceSchemaSpaceManagementCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
var ( | ||
cfg = meta.(*config.Config) | ||
httpUrl = "v2/{project_id}/clusters/{cluster_id}/databases/{database_name}/schemas" | ||
clusterId = d.Get("cluster_id").(string) | ||
databaseName = d.Get("database_name").(string) | ||
) | ||
client, err := cfg.NewServiceClient("dws", cfg.GetRegion(d)) | ||
if err != nil { | ||
return diag.Errorf("error creating DWS Client: %s", err) | ||
} | ||
|
||
path := client.Endpoint + httpUrl | ||
path = strings.ReplaceAll(path, "{project_id}", client.ProjectID) | ||
path = strings.ReplaceAll(path, "{cluster_id}", clusterId) | ||
path = strings.ReplaceAll(path, "{database_name}", databaseName) | ||
createOpt := golangsdk.RequestOpts{ | ||
KeepResponseBody: true, | ||
JSONBody: map[string]interface{}{ | ||
"schema_name": d.Get("schema_name"), | ||
"perm_space": d.Get("space_limit"), | ||
}, | ||
} | ||
|
||
_, err = client.Request("PUT", path, &createOpt) | ||
if err != nil { | ||
return diag.Errorf("error modifying schema space limit for database (%s): %s", databaseName, err) | ||
} | ||
|
||
id, err := uuid.GenerateUUID() | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
d.SetId(id) | ||
|
||
return resourceSchemaSpaceManagementRead(ctx, d, meta) | ||
} | ||
|
||
func resourceSchemaSpaceManagementRead(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { | ||
return nil | ||
} | ||
|
||
func resourceSchemaSpaceManagementDelete(_ context.Context, _ *schema.ResourceData, _ interface{}) diag.Diagnostics { | ||
errorMsg := `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.` | ||
return diag.Diagnostics{ | ||
diag.Diagnostic{ | ||
Severity: diag.Warning, | ||
Summary: errorMsg, | ||
}, | ||
} | ||
} |