Skip to content

Commit

Permalink
feat(dli): add new datasource to get list of elastic resource pools (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzhuanhong authored Apr 7, 2024
1 parent 2615802 commit 8ff5879
Show file tree
Hide file tree
Showing 4 changed files with 500 additions and 0 deletions.
78 changes: 78 additions & 0 deletions docs/data-sources/dli_elastic_resource_pools.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
subcategory: "Data Lake Insight (DLI)"
---

# huaweicloud_dli_elastic_resource_pools

Use this data source to get the list of DLI elastic resource pools within HuaweiCloud.

## Example Usage

```hcl
variable "resoure_pool_name" {}
data "huaweicloud_dli_elastic_resource_pools" "test" {
name = var.resoure_pool_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.

* `name` - (Optional, String) Specifies the name of the elastic resource pool.

* `status` - (Optional, String) Specifies the status of the elastic resource pool.
The valid values are as follows:
+ **available**
+ **failed**

* `tags` - (Optional, Map) Specifies the key/value pairs to associate with the elastic resource pool.

## Attribute Reference

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

* `id` - The data source ID.

* `elastic_resource_pools` - All elastic resource pools that match the filter parameters.

The [elastic_resource_pools](#elastic_resource_pools_struct) structure is documented below.

<a name="elastic_resource_pools_struct"></a>
The `elastic_resource_pools` block supports:

* `id` - The elastic resource pool ID.

* `name` - The elastic resource pool name.

* `max_cu` - The maximum CUs number of the elastic resource pool.

* `min_cu` - The minimum CUs number of the elastic resource pool.

* `current_cu` - The current CUs number of the elastic resource pool.

* `actual_cu` - The actual CUs number of the elastic resource pool.

* `cidr` - The CIDR block of network to associate with the elastic resource pool.

* `resource_id` - The resource ID of the elastic resource pool.

* `enterprise_project_id` - The enterprise project ID corresponding to the elastic resource pool.

* `queues` - The list of queues association with the elastic resource pool.

* `description` - The description of the elastic resource pool.

* `status` - The current status of the elastic resource pool.

* `owner` - The account name for creating elastic resource pool.

* `manager` - The type of the elastic resource pool.

* `fail_reason` - The reason of elastic resource pool creation failed.

* `created_at` - The creation time of the elastic resource pool.
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ func Provider() *schema.Provider {

"huaweicloud_dli_datasource_auths": dli.DataSourceAuths(),
"huaweicloud_dli_datasource_connections": dli.DataSourceConnections(),
"huaweicloud_dli_elastic_resource_pools": dli.DataSourceDliElasticPools(),
"huaweicloud_dli_quotas": dli.DataSourceDliQuotas(),

"huaweicloud_dms_kafka_flavors": dms.DataSourceKafkaFlavors(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
package dli

import (
"fmt"
"testing"

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

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

func TestAccDataSourceDliElasticResourcePools_basic(t *testing.T) {
var (
dataSource = "data.huaweicloud_dli_elastic_resource_pools.test"
rName = acceptance.RandomAccResourceName()
dc = acceptance.InitDataSourceCheck(dataSource)

byName = "data.huaweicloud_dli_elastic_resource_pools.filter_by_name"
dcByName = acceptance.InitDataSourceCheck(byName)

byNameNotFound = "data.huaweicloud_dli_elastic_resource_pools.filter_by_name_not_found"
dcByNameNotFound = acceptance.InitDataSourceCheck(byNameNotFound)

byStatus = "data.huaweicloud_dli_elastic_resource_pools.filter_by_name_not_found"
dcByStatus = acceptance.InitDataSourceCheck(byStatus)

byTags = "data.huaweicloud_dli_elastic_resource_pools.filter_by_tags"
dcByTags = acceptance.InitDataSourceCheck(byTags)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataSourceDataSourceDliElasticPools_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),

dcByName.CheckResourceExists(),
resource.TestCheckOutput("is_name_filter_useful", "true"),
resource.TestCheckResourceAttrSet(byName, "elastic_resource_pools.0.id"),
resource.TestCheckResourceAttr(byName, "elastic_resource_pools.0.name", rName),
resource.TestCheckResourceAttr(byName, "elastic_resource_pools.0.max_cu", "64"),
resource.TestCheckResourceAttr(byName, "elastic_resource_pools.0.min_cu", "64"),
resource.TestCheckResourceAttr(byName, "elastic_resource_pools.0.current_cu", "64"),
resource.TestCheckResourceAttr(byName, "elastic_resource_pools.0.cidr", "172.16.0.0/12"),
resource.TestCheckResourceAttr(byName, "elastic_resource_pools.0.enterprise_project_id", "0"),
resource.TestCheckResourceAttr(byName, "elastic_resource_pools.0.queues.0", rName),
resource.TestCheckResourceAttr(byName, "elastic_resource_pools.0.description", "Created by terraform script"),
resource.TestCheckResourceAttrSet(byName, "elastic_resource_pools.0.resource_id"),
resource.TestCheckResourceAttrSet(byName, "elastic_resource_pools.0.owner"),
resource.TestCheckResourceAttrSet(byName, "elastic_resource_pools.0.manager"),
resource.TestCheckResourceAttrSet(byName, "elastic_resource_pools.0.created_at"),

dcByNameNotFound.CheckResourceExists(),
resource.TestCheckOutput("is_name_filter_useful_not_found", "true"),

dcByStatus.CheckResourceExists(),
resource.TestCheckOutput("is_name_filter_useful_not_found", "true"),

dcByStatus.CheckResourceExists(),
resource.TestCheckOutput("is_status_filter_useful", "true"),

dcByTags.CheckResourceExists(),
resource.TestCheckOutput("is_tags_filter_useful", "true"),

waitForDeletionCooldownComplete(),
),
},
},
})
}

func testDataSourceDataSourceDliElasticPools_basic(name string) string {
return fmt.Sprintf(`
locals {
tags = {
foo = "bar"
terraform = "elastic_resource_pool"
}
}
resource "huaweicloud_dli_elastic_resource_pool" "test" {
name = "%[1]s"
max_cu = 64
min_cu = 64
enterprise_project_id = "0"
description = "Created by terraform script"
tags = local.tags
}
resource "huaweicloud_dli_queue" "test" {
depends_on = [
huaweicloud_dli_elastic_resource_pool.test,
]
name = "%[1]s"
cu_count = 16
resource_mode = 1
elastic_resource_pool_name = huaweicloud_dli_elastic_resource_pool.test.name
}
data "huaweicloud_dli_elastic_resource_pools" "test" {
depends_on = [
huaweicloud_dli_elastic_resource_pool.test,
huaweicloud_dli_queue.test
]
}
data "huaweicloud_dli_elastic_resource_pools" "filter_by_name" {
depends_on = [
huaweicloud_dli_elastic_resource_pool.test,
huaweicloud_dli_queue.test
]
name = "%[1]s"
}
locals {
name_filter_result = [
for v in data.huaweicloud_dli_elastic_resource_pools.filter_by_name.elastic_resource_pools[*].name : v == "%[1]s"
]
}
output "is_name_filter_useful" {
value = length(local.name_filter_result) == 1 && alltrue(local.name_filter_result)
}
data "huaweicloud_dli_elastic_resource_pools" "filter_by_name_not_found" {
depends_on = [
huaweicloud_dli_elastic_resource_pool.test,
huaweicloud_dli_queue.test
]
name = "not_found"
}
output "is_name_filter_useful_not_found" {
value = length(data.huaweicloud_dli_elastic_resource_pools.filter_by_name_not_found.elastic_resource_pools) == 0
}
locals {
status = huaweicloud_dli_elastic_resource_pool.test.status
}
data "huaweicloud_dli_elastic_resource_pools" "filter_by_status" {
depends_on = [
huaweicloud_dli_elastic_resource_pool.test,
huaweicloud_dli_queue.test
]
status = local.status
}
locals {
status_filter_result = [
for v in data.huaweicloud_dli_elastic_resource_pools.filter_by_status.elastic_resource_pools[*].status : v == local.status
]
}
output "is_status_filter_useful" {
value = length(local.status_filter_result) > 0 && alltrue(local.status_filter_result)
}
data "huaweicloud_dli_elastic_resource_pools" "filter_by_tags" {
depends_on = [
huaweicloud_dli_elastic_resource_pool.test,
huaweicloud_dli_queue.test
]
tags = local.tags
}
output "is_tags_filter_useful" {
value = length(data.huaweicloud_dli_elastic_resource_pools.filter_by_tags) >= 1
}
`, name)
}
Loading

0 comments on commit 8ff5879

Please sign in to comment.