Skip to content

Commit

Permalink
Add DWS Cluster resource (#84)
Browse files Browse the repository at this point in the history
kolsean authored Jul 26, 2021

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent cf09cde commit ab6d3f0
Showing 3 changed files with 285 additions and 1 deletion.
151 changes: 151 additions & 0 deletions docs/resources/dws_cluster.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
---
subcategory: "Data Warehouse Service (DWS)"
---

# sbercloud\_dws\_cluster

cluster management

## Example Usage

### Dws Cluster Example

```hcl
resource "sbercloud_networking_secgroup" "secgroup" {
name = "security_group_2"
description = "terraform security group"
}
resource "sbercloud_dws_cluster" "cluster" {
node_type = "dws.m3.xlarge"
number_of_node = 3
network_id = "{{ network_id }}"
vpc_id = "{{ vpc_id }}"
security_group_id = sbercloud_networking_secgroup.secgroup.id
availability_zone = "{{ availability_zone }}"
name = "terraform_dws_cluster_test"
user_name = "test_cluster_admin"
user_pwd = "cluster123@!"
timeouts {
create = "30m"
delete = "30m"
}
}
```

## Argument Reference

The following arguments are supported:

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

* `name` - (Required, String, ForceNew) Cluster name, which must be unique and contains 4 to 64
characters, which consist of letters, digits, hyphens(-), or
underscores(_) only and must start with a letter.

* `network_id` - (Required, String, ForceNew) Network ID, which is used for configuring cluster network

* `node_type` - (Required, String, ForceNew) Node type

* `number_of_node` - (Required, Int, ForceNew) Number of nodes in a cluster. The value ranges from 3 to 32

* `security_group_id` - (Required, String, ForceNew) ID of a security group. The ID is used for configuring cluster network

* `user_name` - (Required, String, ForceNew) Administrator username for logging in to a data warehouse cluster The
administrator username must: Consist of lowercase letters, digits,
or underscores. Start with a lowercase letter or an underscore.
Contain 1 to 63 characters. Cannot be a keyword of the DWS database.

* `vpc_id` - (Required, String, ForceNew) VPC ID, which is used for configuring cluster network

* `user_pwd` - (Required, String, ForceNew) Administrator password for logging in to a data warehouse cluster A
password must conform to the following rules: Contains 8 to 32
characters. Cannot be the same as the username or the username
written in reverse order. Contains three types of the following:
Lowercase letters Uppercase letters Digits Special characters
~!@#%^&*()-_=+|[{}];:,<.>/?

- - -

* `availability_zone` - (Optional, String, ForceNew) AZ in a cluster

* `port` - (Optional, Int) Service port of a cluster (8000 to 10000). The default value is 8000.

* `public_ip` - (Optional, List, ForceNew) A nested object resource Structure is documented below.

The `public_ip` block supports:

* `eip_id` - (Optional, String, ForceNew) EIP ID

* `public_bind_type` - (Optional, String, ForceNew) Binding type of an EIP. The value can be either of the following:
auto_assign not_use bind_existing The default value is
not_use.

## Attributes Reference

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

* `created` - Cluster creation time. The format is ISO8601:YYYY-MM-DDThh:mm:ssZ

* `endpoints` - View the private network connection information about the
cluster. Structure is documented below.

* `id` - Cluster ID

* `public_endpoints` - Public network connection information about the cluster. If the
value is not specified, the public network connection information is not used by default Structure is documented below.

* `recent_event` - The recent event number

* `status` - Cluster status, which can be one of the following: CREATING AVAILABLE UNAVAILABLE CREATION FAILED

* `sub_status` - Sub-status of clusters in the AVAILABLE state. The value can be one
of the following: NORMAL READONLY REDISTRIBUTING
REDISTRIBUTION-FAILURE UNBALANCED UNBALANCED | READONLY DEGRADED
DEGRADED | READONLY DEGRADED | UNBALANCED UNBALANCED |
REDISTRIBUTING UNBALANCED | REDISTRIBUTION-FAILURE READONLY |
REDISTRIBUTION-FAILURE UNBALANCED | READONLY |
REDISTRIBUTION-FAILURE DEGRADED | REDISTRIBUTION-FAILURE DEGRADED |
UNBALANCED | REDISTRIBUTION-FAILURE DEGRADED | UNBALANCED | READONLY
| REDISTRIBUTION-FAILURE DEGRADED | UNBALANCED | READONLY

* `task_status` - Cluster management task. The value can be one of the following:
RESTORING SNAPSHOTTING GROWING REBOOTING SETTING_CONFIGURATION
CONFIGURING_EXT_DATASOURCE DELETING_EXT_DATASOURCE REBOOT_FAILURE
RESIZE_FAILURE

* `updated` - Last modification time of a cluster. The format is
ISO8601:YYYY-MM-DDThh:mm:ssZ

* `version` - Data warehouse version

The `endpoints` block contains:

* `connect_info` - (Optional, String) Private network connection information

* `jdbc_url` - (Optional, String)
JDBC URL. The following is the default format:
jdbc:postgresql://< connect_info>/<YOUR_DATABASE_NAME>

The `public_endpoints` block contains:

* `jdbc_url` - (Optional, String)
JDBC URL. The following is the default format:
jdbc:postgresql://< public_connect_info>/<YOUR_DATABASE_NAME>

* `public_connect_info` - (Optional, String)
Public network connection information

## Timeouts
This resource provides the following timeouts configuration options:
- `create` - Default is 10 minute.
- `delete` - Default is 10 minute.

## Import

Cluster can be imported using the following format:

```
$ terraform import sbercloud_dws_cluster.default {{ resource id}}
```
3 changes: 2 additions & 1 deletion sbercloud/provider.go
Original file line number Diff line number Diff line change
@@ -162,10 +162,11 @@ func Provider() terraform.ResourceProvider {
"sbercloud_dcs_instance": huaweicloud.ResourceDcsInstanceV1(),
"sbercloud_dds_instance": huaweicloud.ResourceDdsInstanceV3(),
"sbercloud_dis_stream": huaweicloud.ResourceDisStreamV2(),
"sbercloud_dms_instance": ResourceDmsInstancesV1(),
"sbercloud_dli_queue": huaweicloud.ResourceDliQueueV1(),
"sbercloud_dms_instance": ResourceDmsInstancesV1(),
"sbercloud_dns_recordset": huaweicloud.ResourceDNSRecordSetV2(),
"sbercloud_dns_zone": huaweicloud.ResourceDNSZoneV2(),
"sbercloud_dws_cluster": huaweicloud.ResourceDwsCluster(),
"sbercloud_evs_snapshot": huaweicloud.ResourceEvsSnapshotV2(),
"sbercloud_evs_volume": huaweicloud.ResourceEvsStorageVolumeV3(),
"sbercloud_fgs_function": huaweicloud.ResourceFgsFunctionV2(),
132 changes: 132 additions & 0 deletions sbercloud/resource_sbercloud_dws_cluster_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package sbercloud

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
)

func TestAccDwsCluster_basic(t *testing.T) {
name := fmt.Sprintf("tf-acc-test-%s", acctest.RandString(5))
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDwsClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccDwsCluster_basic(name),
Check: resource.ComposeTestCheckFunc(
testAccCheckDwsClusterExists(),
),
},
},
})
}

func testAccDwsCluster_basic(name string) string {
return fmt.Sprintf(`
data "sbercloud_availability_zones" "test" {}
resource "sbercloud_vpc" "test" {
name = "%s"
cidr = "192.168.0.0/16"
}
resource "sbercloud_vpc_subnet" "test" {
name = "%s"
cidr = "192.168.0.0/24"
gateway_ip = "192.168.0.1"
primary_dns = "100.125.1.250"
secondary_dns = "100.125.21.250"
vpc_id = sbercloud_vpc.test.id
}
resource "sbercloud_networking_secgroup" "secgroup" {
name = "%s"
description = "terraform security group"
}
resource "sbercloud_dws_cluster" "cluster" {
node_type = "dws2.m6.4xlarge.8"
number_of_node = 3
network_id = sbercloud_vpc_subnet.test.id
vpc_id = sbercloud_vpc.test.id
security_group_id = sbercloud_networking_secgroup.secgroup.id
availability_zone = data.sbercloud_availability_zones.test.names[0]
name = "%s"
user_name = "test_cluster_admin"
user_pwd = "cluster123@!"
timeouts {
create = "30m"
delete = "30m"
}
}
`, name, name, name, name)
}

func testAccCheckDwsClusterDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*config.Config)
client, err := config.DwsV1Client(SBC_REGION_NAME)
if err != nil {
return fmt.Errorf("Error creating sdk client, err=%s", err)
}

for _, rs := range s.RootModule().Resources {
if rs.Type != "sbercloud_dws_cluster" {
continue
}

url, err := replaceVarsForTest(rs, "clusters/{id}")
if err != nil {
return err
}
url = client.ServiceURL(url)

_, err = client.Get(
url, nil,
&golangsdk.RequestOpts{MoreHeaders: map[string]string{"Content-Type": "application/json"}})
if err == nil {
return fmt.Errorf("sbercloud_dws_cluster still exists at %s", url)
}
}

return nil
}

func testAccCheckDwsClusterExists() resource.TestCheckFunc {
return func(s *terraform.State) error {
config := testAccProvider.Meta().(*config.Config)
client, err := config.DwsV1Client(SBC_REGION_NAME)
if err != nil {
return fmt.Errorf("Error creating sdk client, err=%s", err)
}

rs, ok := s.RootModule().Resources["sbercloud_dws_cluster.cluster"]
if !ok {
return fmt.Errorf("Error checking sbercloud_dws_cluster.cluster exist, err=not found sbercloud_dws_cluster.cluster")
}

url, err := replaceVarsForTest(rs, "clusters/{id}")
if err != nil {
return fmt.Errorf("Error checking sbercloud_dws_cluster.cluster exist, err=building url failed: %s", err)
}
url = client.ServiceURL(url)

_, err = client.Get(
url, nil,
&golangsdk.RequestOpts{MoreHeaders: map[string]string{"Content-Type": "application/json"}})
if err != nil {
if _, ok := err.(golangsdk.ErrDefault404); ok {
return fmt.Errorf("sbercloud_dws_cluster.cluster is not exist")
}
return fmt.Errorf("Error checking sbercloud_dws_cluster.cluster exist, err=send request failed: %s", err)
}
return nil
}
}

0 comments on commit ab6d3f0

Please sign in to comment.