Skip to content

Commit

Permalink
feat(css): add data source CSS clusters (#4724)
Browse files Browse the repository at this point in the history
  • Loading branch information
luoping-12345 authored Apr 30, 2024
1 parent 0a4d9ad commit 8517639
Show file tree
Hide file tree
Showing 4 changed files with 789 additions and 0 deletions.
194 changes: 194 additions & 0 deletions docs/data-sources/css_clusters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
---
subcategory: "Cloud Search Service (CSS)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_css_clusters"
description: |-
Use this data source to get the list of CSS clusters.
---

# huaweicloud_css_clusters

Use this data source to get the list of CSS clusters.

## Example Usage

```hcl
variable "cluster_id" {}
data "huaweicloud_css_clusters" "test" {
cluster_id = var.cluster_id
}
```

## 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` - (Optional, String) Specifies the cluster ID.

* `name` - (Optional, String) Specifies the cluster name.

* `engine_type` - (Optional, String) Specifies the engine type. The values can be **elasticsearch** and **logstash**.

* `engine_version` - (Optional, String) Specifies the engine version.
[For details](https://support.huaweicloud.com/intl/en-us/bulletin-css/css_05_0001.html)

## Attribute Reference

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

* `id` - The data source ID.

* `clusters` - The list of cluster objects.

The [clusters](#clusters_struct) structure is documented below.

<a name="clusters_struct"></a>
The `clusters` block supports:

* `id` - The cluster ID.

* `name` - The cluster name.

* `security_group_id` - The security group ID.

* `bandwidth_size` - The public network bandwidth. The unit is Mbit/s.

* `actions` - The current behavior of a cluster.
+ **REBOOTING** indicates that the cluster is being restarted.
+ **GROWING** indicates that the cluster is being scaled.
+ **RESTORING** indicates that the cluster is being restored.
+ **SNAPSHOTTING** indicates that a snapshot is being created.

* `period` - Whether a cluster is billed on the yearly/monthly mode.
+ **true**: The cluster is billed on the yearly/monthly mode.
+ **false**: The cluster is billed on the pay-per-use mode.

* `instances` - The list of node objects.

The [instances](#clusters_instances_struct) structure is documented below.

* `public_ip` - The public IP address information.

* `status` - The cluster status.
+ **100**: Creating.
+ **200**: Available.
+ **303**: Unavailable, for example, due to a creation failure.

* `subnet_id` - The subnet ID.

* `backup_available` - Whether the snapshot function is enabled.
+ **true**: The snapshot function is enabled.
+ **false**: The snapshot function is disabled.

* `enterprise_project_id` - The ID of the enterprise project that a cluster belongs to.
If the user of the cluster does not enable the enterprise project,
the setting of this parameter is not returned.

* `public_kibana_resp` - The kibana public network access information.

The [public_kibana_resp](#clusters_public_kibana_resp_struct) structure is documented below.

* `vpc_id` - The ID of a VPC.

* `datastore` - The cluster data store.

The [datastore](#clusters_datastore_struct) structure is documented below.

* `endpoint` - The IP address and port number of the user used to access the VPC.

* `https_enable` - The communication encryption status.
+ **false**: Communication encryption is not enabled.
+ **true**: Communication encryption is enabled.

* `authority_enable` - Whether to enable authentication.
+ **true**: Authentication is enabled for the cluster.
+ **false**: Authentication is not enabled for the cluster.

* `disk_encrypted` - Whether disks are encrypted.
+ **true**: Disks are encrypted.
+ **false**: Disks are not encrypted.

* `elb_white_list` - The EIP whitelist.

The [elb_white_list](#clusters_elb_white_list_struct) structure is documented below.

* `updated_at` - The last modification time of a cluster.

* `created_at` - The cluster creation time.
The returned cluster list is sorted by creation time in descending order.
The latest cluster is displayed at the top.

* `bandwidth_resource_id` - The resource id for ES public network access.

<a name="clusters_instances_struct"></a>
The `instances` block supports:

* `spec_code` - The node specifications.

* `az_code` - The AZ of a node.

* `ip` - The instance IP address.

* `volume` - The instance volume.

The [volume](#instances_volume_struct) structure is documented below.

* `status` - The node status.
+ **100**: Creating.
+ **200**: Available.
+ **303**: Unavailable, for example, due to a creation failure.

* `type` - The type of the current node.

* `id` - The cluster instance ID.

* `name` - The cluster instance name.

<a name="instances_volume_struct"></a>
The `volume` block supports:

* `type` - The instance volume type.

* `size` - The instance volume size.

<a name="clusters_public_kibana_resp_struct"></a>
The `public_kibana_resp` block supports:

* `eip_size` - The bandwidth range. The unit is Mbit/s.

* `elb_white_list_resp` - The elb white list of the cluster public kibana.

The [elb_white_list_resp](#public_kibana_resp_elb_white_list_resp_struct) structure is documented below.

* `public_kibana_ip` - The IP address for accessing kibana.

* `bandwidth_resource_id` - The resource id for ES public network access.

<a name="public_kibana_resp_elb_white_list_resp_struct"></a>
The `elb_white_list_resp` block supports:

* `enable_white_list` - Whether the kibana access control is enabled.
+ **true**: Access control is enabled.
+ **false**: Access control is disabled.

* `white_list` - Whitelist of public network for accessing kibana.

<a name="clusters_datastore_struct"></a>
The `datastore` block supports:

* `type` - The engine type.

* `version` - The version of the CSS cluster engine.

<a name="clusters_elb_white_list_struct"></a>
The `elb_white_list` block supports:

* `enable_white_list` - Whether the public network access control is enabled.
+ **true**: Public network access control is enabled.
+ **false**: Public network access control is disabled.

* `white_list` - Whitelist for public network access.
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ func Provider() *schema.Provider {
"huaweicloud_csms_secret_version": dew.DataSourceDewCsmsSecret(),
"huaweicloud_csms_events": dew.DataSourceDewCsmsEvents(),
"huaweicloud_css_flavors": css.DataSourceCssFlavors(),
"huaweicloud_css_clusters": css.DataSourceCssClusters(),

"huaweicloud_dataarts_architecture_ds_template_optionals": dataarts.DataSourceTemplateOptionalFields(),
"huaweicloud_dataarts_studio_data_connections": dataarts.DataSourceDataConnections(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package css

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
)

func TestAccDataSourceCssClusters_basic(t *testing.T) {
dataSource := "data.huaweicloud_css_clusters.test"
rName := acceptance.RandomAccResourceName()
dc := acceptance.InitDataSourceCheck(dataSource)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataSourceDataSourceCssClusters_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(dataSource, "clusters.0.id"),
resource.TestCheckResourceAttrSet(dataSource, "clusters.0.name"),
resource.TestCheckResourceAttrSet(dataSource, "clusters.0.datastore.0.type"),
resource.TestCheckResourceAttrSet(dataSource, "clusters.0.datastore.0.version"),

resource.TestCheckOutput("id_filter_is_useful", "true"),
resource.TestCheckOutput("name_filter_is_useful", "true"),
resource.TestCheckOutput("engine_type_filter_is_useful", "true"),
resource.TestCheckOutput("engine_version_filter_is_useful", "true"),
),
},
},
})
}

func testDataSourceDataSourceCssClusters_basic(name string) string {
return fmt.Sprintf(`
%s
data "huaweicloud_css_clusters" "test" {
depends_on = [
huaweicloud_css_cluster.test,
huaweicloud_css_logstash_cluster.test,
]
}
locals {
cluster_id = data.huaweicloud_css_clusters.test.clusters[0].id
name = data.huaweicloud_css_clusters.test.clusters[0].name
engine_type = data.huaweicloud_css_clusters.test.clusters[0].datastore[0].type
engine_version = data.huaweicloud_css_clusters.test.clusters[0].datastore[0].version
}
data "huaweicloud_css_clusters" "filter_by_id" {
cluster_id = local.cluster_id
}
data "huaweicloud_css_clusters" "filter_by_name" {
name = local.name
}
data "huaweicloud_css_clusters" "filter_by_engine_type" {
engine_type = local.engine_type
}
data "huaweicloud_css_clusters" "filter_by_engine_version" {
engine_version = local.engine_version
}
locals {
list_by_id = data.huaweicloud_css_clusters.filter_by_id.clusters
list_by_name = data.huaweicloud_css_clusters.filter_by_name.clusters
list_by_engine_type = data.huaweicloud_css_clusters.filter_by_engine_type.clusters
list_by_engine_version = data.huaweicloud_css_clusters.filter_by_engine_version.clusters
}
output "id_filter_is_useful" {
value = length(local.list_by_id) > 0 && alltrue(
[for v in local.list_by_id[*].id : v == local.cluster_id]
)
}
output "name_filter_is_useful" {
value = length(local.list_by_name) > 0 && alltrue(
[for v in local.list_by_name[*].name : v == local.name]
)
}
output "engine_type_filter_is_useful" {
value = length(local.list_by_engine_type) > 0 && alltrue(
[for v in local.list_by_engine_type[*].datastore[0].type : v == local.engine_type]
)
}
output "engine_version_filter_is_useful" {
value = length(local.list_by_engine_version) > 0 && alltrue(
[for v in local.list_by_engine_version[*].datastore[0].version : v == local.engine_version]
)
}
`, testDataSourceCssClusters_data_basic(name))
}

func testDataSourceCssClusters_data_basic(name string) string {
clusterString := testAccCssCluster_basic(name, "Test@passw0rd", 7, "bar")
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_css_logstash_cluster" "test" {
name = "%[2]s_1"
engine_version = "7.10.0"
node_config {
flavor = "ess.spec-4u8g"
instance_number = 1
volume {
volume_type = "HIGH"
size = 40
}
}
availability_zone = data.huaweicloud_availability_zones.test.names[0]
security_group_id = huaweicloud_networking_secgroup.test.id
subnet_id = huaweicloud_vpc_subnet.test.id
vpc_id = huaweicloud_vpc.test.id
}
`, clusterString, name)
}
Loading

0 comments on commit 8517639

Please sign in to comment.