-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hss): support quotas datasource (#5028)
- Loading branch information
1 parent
a396177
commit a49c4d4
Showing
4 changed files
with
476 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,98 @@ | ||
--- | ||
subcategory: "Host Security Service (HSS)" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_hss_quotas" | ||
description: |- | ||
Use this data source to get the list of HSS quotas within HuaweiCloud. | ||
--- | ||
|
||
# huaweicloud_hss_quotas | ||
|
||
Use this data source to get the list of HSS quotas within HuaweiCloud. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
variable quota_id {} | ||
data "huaweicloud_hss_quotas" "test" { | ||
quota_id = var.quota_id | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String) Specifies the region in which to query the HSS quotas. | ||
If omitted, the provider-level region will be used. | ||
|
||
* `category` - (Optional, String) Specifies the category of the quotas to be queried. | ||
The valid values are as follows: | ||
+ **host_resource**: Host protection quota. | ||
+ **container_resource**: Container protection quota. | ||
|
||
If omitted, return all quotas for host resource. | ||
If set to **container_resource**, return all quotas with version **hss.version.container.enterprise**. | ||
|
||
* `version` - (Optional, String) Specifies the version of the quotas to be queried. | ||
The valid values are as follows: | ||
+ **hss.version.basic**: Basic version. | ||
+ **hss.version.advanced**: Professional version. | ||
+ **hss.version.enterprise**: Enterprise version. | ||
+ **hss.version.premium**: Ultimate version. | ||
+ **hss.version.wtp**: Web page tamper prevention version. | ||
|
||
* `status` - (Optional, String) Specifies the status of the quotas to be queried. | ||
The value can be **normal**, **expired**, or **freeze**. | ||
|
||
* `used_status` - (Optional, String) Specifies the usage status of the quotas to be queried. | ||
The value can be **idle** or **used**. | ||
|
||
* `host_name` - (Optional, String) Specifies the host name for the quota binding to be queried. | ||
|
||
* `quota_id` - (Optional, String) Specifies the ID of the quota to be queried. | ||
|
||
* `charging_mode` - (Optional, String) Specifies the charging mode of the quotas to be queried. | ||
The valid values are as follows: | ||
+ **prePaid**: The yearly/monthly billing mode. | ||
+ **postPaid**: The pay-per-use billing mode. | ||
|
||
* `enterprise_project_id` - (Optional, String) Specifies the ID of the enterprise project to which the quotas belong. | ||
For enterprise users, if omitted, will query the quotas under all enterprise projects. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID in UUID format. | ||
|
||
* `quotas` - All quotas that match the filter parameters. | ||
The [quotas](#hss_quotas) structure is documented below. | ||
|
||
<a name="hss_quotas"></a> | ||
The `quotas` block supports: | ||
|
||
* `id` - The ID of quota. | ||
|
||
* `version` - The version of quota. | ||
|
||
* `status` - The status of quota. | ||
|
||
* `used_status` - The usage status of quota. | ||
|
||
* `host_id` - The host ID for quota binding. | ||
|
||
* `host_name` - The host name for quota binding. | ||
|
||
* `charging_mode` - The charging mode of quota. | ||
|
||
* `expire_time` - The expiration time of quota, in RFC3339 format. This field is valid when the quota is a trial quota. | ||
|
||
* `shared_quota` - Is it a shared quota. The value can be **shared** or **unshared**. | ||
|
||
* `enterprise_project_id` - The enterprise project ID to which the quota belongs. | ||
|
||
* `enterprise_project_name` - The enterprise project name to which the quota belongs. | ||
|
||
* `tags` - The key/value pairs to associate with the HSS quota. |
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
154 changes: 154 additions & 0 deletions
154
huaweicloud/services/acceptance/hss/data_source_huaweicloud_hss_quotas_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,154 @@ | ||
package hss | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
) | ||
|
||
func TestAccDataSourceQuotas_basic(t *testing.T) { | ||
var ( | ||
dataSource = "data.huaweicloud_hss_quotas.test" | ||
dc = acceptance.InitDataSourceCheck(dataSource) | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceQuotas_basic(), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(dataSource, "quotas.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "quotas.0.id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "quotas.0.version"), | ||
resource.TestCheckResourceAttrSet(dataSource, "quotas.0.status"), | ||
resource.TestCheckResourceAttrSet(dataSource, "quotas.0.used_status"), | ||
resource.TestCheckResourceAttrSet(dataSource, "quotas.0.charging_mode"), | ||
resource.TestCheckResourceAttrSet(dataSource, "quotas.0.shared_quota"), | ||
resource.TestCheckResourceAttrSet(dataSource, "quotas.0.enterprise_project_id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "quotas.0.enterprise_project_name"), | ||
resource.TestCheckResourceAttr(dataSource, "quotas.0.tags.foo", "bar"), | ||
resource.TestCheckResourceAttr(dataSource, "quotas.0.tags.key", "value"), | ||
|
||
resource.TestCheckOutput("is_category_filter_useful", "true"), | ||
resource.TestCheckOutput("is_version_filter_useful", "true"), | ||
resource.TestCheckOutput("is_status_filter_useful", "true"), | ||
resource.TestCheckOutput("is_used_status_filter_useful", "true"), | ||
resource.TestCheckOutput("is_quota_id_filter_useful", "true"), | ||
resource.TestCheckOutput("is_charging_mode_filter_useful", "true"), | ||
resource.TestCheckOutput("not_found_validation_pass", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceQuotas_basic() string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "huaweicloud_hss_quotas" "test" { | ||
depends_on = [huaweicloud_hss_quota.test] | ||
} | ||
# Filter using category and category value is **container_resource**. | ||
data "huaweicloud_hss_quotas" "category_filter" { | ||
category = "container_resource" | ||
} | ||
output "is_category_filter_useful" { | ||
value = length(data.huaweicloud_hss_quotas.category_filter.quotas) == 0 | ||
} | ||
# Filter using version. | ||
locals { | ||
version = data.huaweicloud_hss_quotas.test.quotas[0].version | ||
} | ||
data "huaweicloud_hss_quotas" "version_filter" { | ||
version = local.version | ||
} | ||
output "is_version_filter_useful" { | ||
value = length(data.huaweicloud_hss_quotas.version_filter.quotas) > 0 && alltrue( | ||
[for v in data.huaweicloud_hss_quotas.version_filter.quotas[*].version : v == local.version] | ||
) | ||
} | ||
# Filter using status. | ||
locals { | ||
status = data.huaweicloud_hss_quotas.test.quotas[0].status | ||
} | ||
data "huaweicloud_hss_quotas" "status_filter" { | ||
status = local.status | ||
} | ||
output "is_status_filter_useful" { | ||
value = length(data.huaweicloud_hss_quotas.status_filter.quotas) > 0 && alltrue( | ||
[for v in data.huaweicloud_hss_quotas.status_filter.quotas[*].status : v == local.status] | ||
) | ||
} | ||
# Filter using used_status. | ||
locals { | ||
used_status = data.huaweicloud_hss_quotas.test.quotas[0].used_status | ||
} | ||
data "huaweicloud_hss_quotas" "used_status_filter" { | ||
used_status = local.used_status | ||
} | ||
output "is_used_status_filter_useful" { | ||
value = length(data.huaweicloud_hss_quotas.used_status_filter.quotas) > 0 && alltrue( | ||
[for v in data.huaweicloud_hss_quotas.used_status_filter.quotas[*].used_status : v == local.used_status] | ||
) | ||
} | ||
# Filter using quota ID. | ||
locals { | ||
quota_id = data.huaweicloud_hss_quotas.test.quotas[0].id | ||
} | ||
data "huaweicloud_hss_quotas" "quota_id_filter" { | ||
quota_id = local.quota_id | ||
} | ||
output "is_quota_id_filter_useful" { | ||
value = length(data.huaweicloud_hss_quotas.quota_id_filter.quotas) > 0 && alltrue( | ||
[for v in data.huaweicloud_hss_quotas.quota_id_filter.quotas[*].id : v == local.quota_id] | ||
) | ||
} | ||
# Filter using charging mode. | ||
locals { | ||
charging_mode = data.huaweicloud_hss_quotas.test.quotas[0].charging_mode | ||
} | ||
data "huaweicloud_hss_quotas" "charging_mode_filter" { | ||
charging_mode = local.charging_mode | ||
} | ||
output "is_charging_mode_filter_useful" { | ||
value = length(data.huaweicloud_hss_quotas.charging_mode_filter.quotas) > 0 && alltrue( | ||
[for v in data.huaweicloud_hss_quotas.charging_mode_filter.quotas[*].charging_mode : v == local.charging_mode] | ||
) | ||
} | ||
# Filter using non existent quota ID. | ||
data "huaweicloud_hss_quotas" "not_found" { | ||
quota_id = "resource_not_found" | ||
} | ||
output "not_found_validation_pass" { | ||
value = length(data.huaweicloud_hss_quotas.not_found.quotas) == 0 | ||
} | ||
`, testAccQuota_basic()) | ||
} |
Oops, something went wrong.