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(DCS): add a data source to get the list of DCS templates #1078

Merged
merged 1 commit into from
Dec 25, 2023
Merged
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
77 changes: 77 additions & 0 deletions docs/data-sources/dcs_templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
subcategory: "Distributed Cache Service (DCS)"
---

# flexibleengine_dcs_templates

Use this data source to get the list of DCS templates.

## Example Usage

```hcl
data "flexibleengine_dcs_templates" "test" {
type = "sys"
name = "test_template_name"
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) Specifies the region in which to query the data source.
If omitted, the provider-level region will be used.

* `type` - (Required, String) Specifies the type of the template. Value options:
+ **sys**: system template.
+ **user**: custom template.

* `template_id` - (Optional, String) Specifies the ID of the template.

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

* `engine` - (Optional, String) Specifies the cache engine. Value options: **Redis**, **Memcached**.

* `engine_version` - (Optional, String) Specifies the cache engine version. Value options: **4.0**, **5.0**, **6.0**.

* `cache_mode` - (Optional, String) Specifies the DCS instance type. Value options:
+ **single**: single-node.
+ **ha**: master/standby.
+ **cluster**: Redis Cluster.
+ **proxy**: Proxy Cluster.

* `product_type` - (Optional, String) Specifies the product edition. Value options:
+ **generic**: standard edition.
+ **enterprise**: professional edition.

* `storage_type` - (Optional, String) Specifies the storage type. Value options: **DRAM**, **SSD**.

## Attribute Reference

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

* `id` - The resource ID.

* `templates` - Indicates the list of DCS templates.
The [templates](#Templates_Template) structure is documented below.

<a name="Templates_Template"></a>
The `templates` block supports:

* `template_id` - Indicates the ID of the template.

* `name` - Indicates the name of the template.

* `type` - Indicates the type of the template.

* `engine` - Indicates the cache engine.

* `engine_version` - Indicates the cache engine version.

* `cache_mode` - Indicates the DCS instance type.

* `product_type` - Indicates the product edition.

* `storage_type` - Indicates the storage type.

* `description` - Indicates the description of the template.
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package acceptance

import (
"testing"

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

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

func TestAccDatasourceTemplates_basic(t *testing.T) {
rName := "data.flexibleengine_dcs_templates.test"
dc := acceptance.InitDataSourceCheck(rName)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDatasourceTemplates_basic(),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(rName, "templates.0.template_id"),
resource.TestCheckResourceAttrSet(rName, "templates.0.name"),
resource.TestCheckResourceAttrSet(rName, "templates.0.type"),
resource.TestCheckResourceAttrSet(rName, "templates.0.engine"),
resource.TestCheckResourceAttrSet(rName, "templates.0.engine_version"),
resource.TestCheckResourceAttrSet(rName, "templates.0.cache_mode"),
resource.TestCheckResourceAttrSet(rName, "templates.0.product_type"),
resource.TestCheckResourceAttrSet(rName, "templates.0.storage_type"),

resource.TestCheckOutput("template_id_filter_is_useful", "true"),

resource.TestCheckOutput("name_filter_is_useful", "true"),

resource.TestCheckOutput("engine_filter_is_useful", "true"),

resource.TestCheckOutput("engine_version_filter_is_useful", "true"),

resource.TestCheckOutput("cache_mode_filter_is_useful", "true"),

resource.TestCheckOutput("product_type_filter_is_useful", "true"),

resource.TestCheckOutput("storage_type_filter_is_useful", "true"),
),
},
},
})
}

func testAccDatasourceTemplates_basic() string {
return `
data "flexibleengine_dcs_templates" "test" {
type = "sys"
}

data "flexibleengine_dcs_templates" "template_id_filter" {
type = "sys"
template_id = "6"

depends_on = [data.flexibleengine_dcs_templates.test]
}
output "template_id_filter_is_useful" {
value = length(data.flexibleengine_dcs_templates.template_id_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_dcs_templates.template_id_filter.templates[*].template_id : v == "6"]
)
}

data "flexibleengine_dcs_templates" "name_filter" {
type = "sys"
name = "Default-Redis-6.0-ha-generic-DRAM"

depends_on = [data.flexibleengine_dcs_templates.test]
}
output "name_filter_is_useful" {
value = length(data.flexibleengine_dcs_templates.name_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_dcs_templates.name_filter.templates[*].name : v == "Default-Redis-6.0-ha-generic-DRAM"]
)
}

data "flexibleengine_dcs_templates" "engine_filter" {
type = "sys"
engine = "Redis"

depends_on = [data.flexibleengine_dcs_templates.test]
}
output "engine_filter_is_useful" {
value = length(data.flexibleengine_dcs_templates.engine_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_dcs_templates.engine_filter.templates[*].engine : v == "Redis"]
)
}

data "flexibleengine_dcs_templates" "engine_version_filter" {
type = "sys"
engine_version = "6.0"

depends_on = [data.flexibleengine_dcs_templates.test]
}
output "engine_version_filter_is_useful" {
value = length(data.flexibleengine_dcs_templates.engine_version_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_dcs_templates.engine_version_filter.templates[*].engine_version : v == "6.0"]
)
}

data "flexibleengine_dcs_templates" "cache_mode_filter" {
type = "sys"
cache_mode = "single"

depends_on = [data.flexibleengine_dcs_templates.test]
}
output "cache_mode_filter_is_useful" {
value = length(data.flexibleengine_dcs_templates.cache_mode_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_dcs_templates.cache_mode_filter.templates[*].cache_mode : v == "single"]
)
}

data "flexibleengine_dcs_templates" "product_type_filter" {
type = "sys"
product_type = "generic"

depends_on = [data.flexibleengine_dcs_templates.test]
}
output "product_type_filter_is_useful" {
value = length(data.flexibleengine_dcs_templates.product_type_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_dcs_templates.product_type_filter.templates[*].product_type : v == "generic"]
)
}

data "flexibleengine_dcs_templates" "storage_type_filter" {
type = "sys"
storage_type = "DRAM"

depends_on = [data.flexibleengine_dcs_templates.test]
}
output "storage_type_filter_is_useful" {
value = length(data.flexibleengine_dcs_templates.storage_type_filter.templates) > 0 && alltrue(
[for v in data.flexibleengine_dcs_templates.storage_type_filter.templates[*].storage_type : v == "DRAM"]
)
}
`
}
1 change: 1 addition & 0 deletions flexibleengine/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ func Provider() *schema.Provider {

"flexibleengine_dcs_flavors": dcs.DataSourceDcsFlavorsV2(),
"flexibleengine_dcs_instances": dcs.DataSourceDcsInstance(),
"flexibleengine_dcs_templates": dcs.DataSourceTemplates(),

"flexibleengine_ddm_engines": ddm.DataSourceDdmEngines(),
"flexibleengine_ddm_flavors": ddm.DataSourceDdmFlavors(),
Expand Down
Loading