-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DCS): add a data source to get the list of DCS templates
- Loading branch information
1 parent
51799d6
commit ba83aa7
Showing
3 changed files
with
219 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,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. |
141 changes: 141 additions & 0 deletions
141
flexibleengine/acceptance/data_source_flexibleengine_dcs_templates_test.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,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"] | ||
) | ||
} | ||
` | ||
} |
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