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(CSS): import CSS resource, unit test and document. #1054

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
62 changes: 62 additions & 0 deletions docs/data-sources/css_flavors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
subcategory: "Cloud Search Service (CSS)"
---

# flexibleengine_css_flavors
Zippo-Wang marked this conversation as resolved.
Show resolved Hide resolved

Use this data source to get available flavors of FlexibleEngine CSS node instance.

## Example Usage

```hcl
data "flexibleengine_css_flavors" "test" {
type = "ess"
version = "7.9.3"
vcpus = 4
memory = 32
}
```

## Argument Reference

* `region` - (Optional, String) Specifies the region in which to obtain the CSS flavors. If omitted, the
provider-level region will be used.

* `type` - (Optional, String) Specifies the node instance type. The options are `ess`, `ess-cold`, `ess-master`
and `ess-client`.

* `version` - (Optional, String) Specifies the engine version. The options are `6.5.4`, `7.1.1`, `7.6.2`, `7.9.3`
and `7.10.2`.

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

* `vcpus` - (Optional, Int) Specifies the number of vCPUs in the CSS flavor.

* `memory` - (Optional, Int) Specifies the memory size(GB) in the CSS flavor.

## Attribute Reference

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

* `id` - Indicates a data source ID in UUID format.

* `flavors` - Indicates the flavor information. The [flavors](#css_flavors) object structure is documented below.

<a name="css_flavors"></a>
The `flavors` block supports:

* `name` - The name of the CSS flavor. It is referenced by `node_config.flavor` in `flexibleengine_css_cluster`.

* `id` - The ID of CSS flavor.

* `region` - The region where the node resides.

* `type` - The node instance type.

* `version` - The engine version.

* `vcpus` - The number of vCPUs.

* `memory` - The memory size in GB.

* `disk_range` - The disk capacity range of an instance, in GB.
6 changes: 3 additions & 3 deletions docs/data-sources/smn_message_templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data "flexibleengine_smn_message_templates" "test" {

The following arguments are supported:

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

* `name` - (Optional, String) Specifies the name of the message template.
Expand All @@ -35,7 +35,7 @@ In addition to all arguments above, the following attributes are exported:

* `id` - The data source ID.

* `templates` - The list of message templates.
* `templates` - The list of message templates.
The [templates](#SmnMessageTemplate_MessageTemplate) structure is documented below.

<a name="SmnMessageTemplate_MessageTemplate"></a>
Expand All @@ -47,7 +47,7 @@ The `templates` block supports:

* `protocol` - Indicates the protocol supported by the template.

* `tag_names` - Indicates the variable list. The variable name will be quoted in braces ({}) in the template.
* `tag_names` - Indicates the variable list. The variable name will be quoted in braces ({}) in the template.
When you use a template to send messages, you can replace the variable with any content.

* `created_at` - Indicates the create time.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
package acceptance

import (
"testing"

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

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

func TestAccCssFlavorsDataSource_basic(t *testing.T) {
var (
typeFilter = acceptance.InitDataSourceCheck("data.flexibleengine_css_flavors.type_filter")
typeFilterCold = acceptance.InitDataSourceCheck("data.flexibleengine_css_flavors.type_filter_cold")
typeFilterMaster = acceptance.InitDataSourceCheck("data.flexibleengine_css_flavors.type_filter_master")
typeFilterClient = acceptance.InitDataSourceCheck("data.flexibleengine_css_flavors.type_filter_client")
versionFilter654 = acceptance.InitDataSourceCheck("data.flexibleengine_css_flavors.version_filter_654")
versionFilter711 = acceptance.InitDataSourceCheck("data.flexibleengine_css_flavors.version_filter_711")
versionFilter762 = acceptance.InitDataSourceCheck("data.flexibleengine_css_flavors.version_filter_762")
versionFilter793 = acceptance.InitDataSourceCheck("data.flexibleengine_css_flavors.version_filter_793")
versionFilter7102 = acceptance.InitDataSourceCheck("data.flexibleengine_css_flavors.version_filter_7102")
vcpusFilter = acceptance.InitDataSourceCheck("data.flexibleengine_css_flavors.vcpus_filter")
memoryFilter = acceptance.InitDataSourceCheck("data.flexibleengine_css_flavors.memory_filter")
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceCssFlavors_basic,
Check: resource.ComposeTestCheckFunc(
typeFilter.CheckResourceExists(),
resource.TestCheckOutput("is_type_filter_useful", "true"),
typeFilterCold.CheckResourceExists(),
resource.TestCheckOutput("is_type_filter_cold_useful", "true"),
typeFilterMaster.CheckResourceExists(),
resource.TestCheckOutput("is_type_filter_master_useful", "true"),
typeFilterClient.CheckResourceExists(),
resource.TestCheckOutput("is_type_filter_client_useful", "true"),
versionFilter654.CheckResourceExists(),
resource.TestCheckOutput("is_version_filter_654_useful", "true"),
versionFilter711.CheckResourceExists(),
resource.TestCheckOutput("is_version_filter_711_useful", "true"),
versionFilter762.CheckResourceExists(),
resource.TestCheckOutput("is_version_filter_762_useful", "true"),
versionFilter793.CheckResourceExists(),
resource.TestCheckOutput("is_version_filter_793_useful", "true"),
versionFilter7102.CheckResourceExists(),
resource.TestCheckOutput("is_version_filter_7102_useful", "true"),
vcpusFilter.CheckResourceExists(),
resource.TestCheckOutput("is_vcpus_filter_useful", "true"),
memoryFilter.CheckResourceExists(),
resource.TestCheckOutput("is_memory_filter_useful", "true"),
),
},
},
})
}

const testAccDataSourceCssFlavors_basic = `
data "flexibleengine_css_flavors" "type_filter" {
type = "ess"
}
output "is_type_filter_useful" {
value = !contains([for v in data.flexibleengine_css_flavors.type_filter.flavors[*].type : v == "ess"], "false")
}
data "flexibleengine_css_flavors" "type_filter_cold" {
type = "ess-cold"
}
output "is_type_filter_cold_useful" {
value = !contains([for v in data.flexibleengine_css_flavors.type_filter_cold.flavors[*].type : v == "ess-cold"], "false")
}
data "flexibleengine_css_flavors" "type_filter_master" {
type = "ess-master"
}
output "is_type_filter_master_useful" {
value = !contains([for v in data.flexibleengine_css_flavors.type_filter_master.flavors[*].type : v == "ess-master"], "false")
}
data "flexibleengine_css_flavors" "type_filter_client" {
type = "ess-client"
}
output "is_type_filter_client_useful" {
value = !contains([for v in data.flexibleengine_css_flavors.type_filter_client.flavors[*].type : v == "ess-client"], "false")
}
data "flexibleengine_css_flavors" "version_filter_654" {
version = "6.5.4"
}
output "is_version_filter_654_useful" {
value = !contains([for v in data.flexibleengine_css_flavors.version_filter_654.flavors[*].version : v == "6.5.4"], "false")
}
data "flexibleengine_css_flavors" "version_filter_711" {
version = "7.1.1"
}
output "is_version_filter_711_useful" {
value = !contains([for v in data.flexibleengine_css_flavors.version_filter_711.flavors[*].version : v == "7.1.1"], "false")
}
data "flexibleengine_css_flavors" "version_filter_762" {
version = "7.6.2"
}
output "is_version_filter_762_useful" {
value = !contains([for v in data.flexibleengine_css_flavors.version_filter_762.flavors[*].version : v == "7.6.2"], "false")
}
data "flexibleengine_css_flavors" "version_filter_793" {
version = "7.9.3"
}
output "is_version_filter_793_useful" {
value = !contains([for v in data.flexibleengine_css_flavors.version_filter_793.flavors[*].version : v == "7.9.3"], "false")
}
data "flexibleengine_css_flavors" "version_filter_7102" {
version = "7.10.2"
}
output "is_version_filter_7102_useful" {
value = !contains([for v in data.flexibleengine_css_flavors.version_filter_7102.flavors[*].version : v == "7.10.2"], "false")
}
data "flexibleengine_css_flavors" "vcpus_filter" {
vcpus = 32
}
output "is_vcpus_filter_useful" {
value = !contains([for v in data.flexibleengine_css_flavors.vcpus_filter.flavors[*].vcpus : v == 32], "false")
}
data "flexibleengine_css_flavors" "memory_filter" {
memory = 256
}
output "is_memory_filter_useful" {
value = !contains([for v in data.flexibleengine_css_flavors.memory_filter.flavors[*].memory : v == 256], "false")
}
`

func TestAccCssFlavorsDataSource_all(t *testing.T) {
dataSourceName := "data.flexibleengine_css_flavors.test"

dc := acceptance.InitDataSourceCheck(dataSourceName)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceCssFlavors_version_654,
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.type", "ess"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.version", "6.5.4"),
resource.TestCheckResourceAttrSet(dataSourceName, "flavors.0.id"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.region", "eu-west-0"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.name", "ess.spec-4u8g"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.memory", "8"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.vcpus", "4"),
resource.TestCheckResourceAttrSet(dataSourceName, "flavors.0.disk_range"),
),
},
{
Config: testAccDataSourceCssFlavors_version_711,
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.type", "ess-cold"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.version", "7.1.1"),
resource.TestCheckResourceAttrSet(dataSourceName, "flavors.0.id"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.region", "eu-west-0"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.name", "ess.spec-4u8g"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.memory", "8"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.vcpus", "4"),
resource.TestCheckResourceAttrSet(dataSourceName, "flavors.0.disk_range"),
),
},
{
Config: testAccDataSourceCssFlavors_version_762,
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.type", "ess-master"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.version", "7.6.2"),
resource.TestCheckResourceAttrSet(dataSourceName, "flavors.0.id"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.region", "eu-west-0"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.name", "ess.spec-4u8g"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.memory", "8"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.vcpus", "4"),
resource.TestCheckResourceAttrSet(dataSourceName, "flavors.0.disk_range"),
),
},
{
Config: testAccDataSourceCssFlavors_version_793,
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.type", "ess-client"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.version", "7.9.3"),
resource.TestCheckResourceAttrSet(dataSourceName, "flavors.0.id"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.region", "eu-west-0"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.name", "ess.spec-4u8g"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.memory", "8"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.vcpus", "4"),
resource.TestCheckResourceAttrSet(dataSourceName, "flavors.0.disk_range"),
),
},
{
Config: testAccDataSourceCssFlavors_version_7102,
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.type", "ess"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.version", "7.10.2"),
resource.TestCheckResourceAttrSet(dataSourceName, "flavors.0.id"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.region", "eu-west-0"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.name", "ess.spec-4u8g"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.memory", "8"),
resource.TestCheckResourceAttr(dataSourceName, "flavors.0.vcpus", "4"),
resource.TestCheckResourceAttrSet(dataSourceName, "flavors.0.disk_range"),
),
},
},
})
}

const testAccDataSourceCssFlavors_version_654 = `
data "flexibleengine_css_flavors" "test" {
type = "ess"
version = "6.5.4"
vcpus = 4
memory = 8
region = "eu-west-0"
name = "ess.spec-4u8g"
}
`

const testAccDataSourceCssFlavors_version_711 = `
data "flexibleengine_css_flavors" "test" {
type = "ess-cold"
version = "7.1.1"
vcpus = 4
memory = 8
region = "eu-west-0"
name = "ess.spec-4u8g"
}
`

const testAccDataSourceCssFlavors_version_762 = `
data "flexibleengine_css_flavors" "test" {
type = "ess-master"
version = "7.6.2"
vcpus = 4
memory = 8
region = "eu-west-0"
name = "ess.spec-4u8g"
}
`

const testAccDataSourceCssFlavors_version_793 = `
data "flexibleengine_css_flavors" "test" {
type = "ess-client"
version = "7.9.3"
vcpus = 4
memory = 8
region = "eu-west-0"
name = "ess.spec-4u8g"
}
`

const testAccDataSourceCssFlavors_version_7102 = `
data "flexibleengine_css_flavors" "test" {
type = "ess"
version = "7.10.2"
vcpus = 4
memory = 8
region = "eu-west-0"
name = "ess.spec-4u8g"
}
`
3 changes: 3 additions & 0 deletions flexibleengine/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/cbr"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/cce"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/cse"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/css"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/dcs"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/ddm"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/dds"
Expand Down Expand Up @@ -294,6 +295,8 @@ func Provider() *schema.Provider {

"flexibleengine_compute_servergroups": ecs.DataSourceComputeServerGroups(),

"flexibleengine_css_flavors": css.DataSourceCssFlavors(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should align with other rows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not mandatory.

Zippo-Wang marked this conversation as resolved.
Show resolved Hide resolved

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

Expand Down
Loading