Skip to content

Commit 60d7de7

Browse files
feat(hss/hss_antivirus_available_hosts): support hss_antivirus_available_hosts data source (#7339)
1 parent e3d99a9 commit 60d7de7

File tree

4 files changed

+448
-0
lines changed

4 files changed

+448
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
---
2+
subcategory: "Host Security Service (HSS)"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_hss_antivirus_available_hosts"
5+
description: |-
6+
Use this data source to get the list of HSS antivirus available hosts within HuaweiCloud.
7+
---
8+
# huaweicloud_hss_antivirus_available_hosts
9+
10+
Use this data source to get the list of HSS antivirus available hosts within HuaweiCloud.
11+
12+
## Example Usage
13+
14+
```hcl
15+
variable "scan_type" {}
16+
variable "start_type" {}
17+
18+
data "huaweicloud_hss_antivirus_available_hosts" "test" {
19+
scan_type = var.scan_type
20+
start_type = var.start_type
21+
}
22+
```
23+
24+
## Argument Reference
25+
26+
The following arguments are supported:
27+
28+
* `region` - (Optional, String) Specifies the region in which to query the resource.
29+
If omitted, the provider-level region will be used.
30+
31+
* `scan_type` - (Required, String) Specifies the scan type.
32+
The valid values are as follows:
33+
+ **quick**: Quick scan.
34+
+ **full**: Full scan.
35+
+ **custom**: Custom scan.
36+
37+
* `start_type` - (Required, String) Specifies the startup type.
38+
The valid values are as follows:
39+
+ **now**
40+
+ **period**
41+
42+
* `host_id` - (Optional, String) Specifies the host ID.
43+
44+
* `host_name` - (Optional, String) Specifies the host name.
45+
46+
* `private_ip` - (Optional, String) Specifies the host private IP address.
47+
48+
* `public_ip` - (Optional, String) Specifies the host public IP address.
49+
50+
* `group_id` - (Optional, String) Specifies the host group ID.
51+
52+
* `policy_id` - (Optional, String) Specifies the policy ID.
53+
54+
* `next_start_time` - (Optional, Int) Specifies the next startup time in milliseconds.
55+
56+
* `enterprise_project_id` - (Optional, String) Specifies the enterprise project ID.
57+
This parameter is valid only when the enterprise project is enabled.
58+
The default value is **0**, indicating the default enterprise project.
59+
If you need to query data for all enterprise projects, the value is **all_granted_eps**.
60+
If you only have permissions for a specific enterprise project, you need set the enterprise project ID. Otherwise,
61+
the operation may fail due to insufficient permissions.
62+
63+
## Attributes Reference
64+
65+
In addition to all arguments above, the following attributes are exported:
66+
67+
* `id` - The data source ID in UUID format.
68+
69+
* `total_num` - The total number of available hosts.
70+
71+
* `data_list` - The list of available hosts details.
72+
The [data_list](#data_list_struct) structure is documented below.
73+
74+
<a name="data_list_struct"></a>
75+
The `data_list` block supports:
76+
77+
* `host_id` - The host ID.
78+
79+
* `host_name` - The host name.
80+
81+
* `public_ip` - The host public IP address.
82+
83+
* `private_ip` - The host private IP address.
84+
85+
* `agent_id` - The host agent ID.
86+
87+
* `os_type` - The host operating system type. The valid value can be **Linux** or **Windows**.
88+
89+
* `group_id` - The host group ID.

huaweicloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ func Provider() *schema.Provider {
10951095
"huaweicloud_hss_vulnerability_statistics": hss.DataSourceVulnerabilityStatistics(),
10961096
"huaweicloud_hss_webtamper_hosts": hss.DataSourceWebTamperHosts(),
10971097
"huaweicloud_hss_antivirus_custom_scan_policies": hss.DataSourceAntivirusCustomScanPolicies(),
1098+
"huaweicloud_hss_antivirus_available_hosts": hss.DataSourceAntivirusAvailableHosts(),
10981099

10991100
"huaweicloud_identity_permissions": iam.DataSourceIdentityPermissions(),
11001101
"huaweicloud_identity_role": iam.DataSourceIdentityRole(),
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package hss
2+
3+
import (
4+
"testing"
5+
6+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
7+
8+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
9+
)
10+
11+
func TestAccDataSourceAntivirusAvailableHosts_basic(t *testing.T) {
12+
var (
13+
dataSource = "data.huaweicloud_hss_antivirus_available_hosts.test"
14+
dc = acceptance.InitDataSourceCheck(dataSource)
15+
)
16+
17+
resource.ParallelTest(t, resource.TestCase{
18+
PreCheck: func() {
19+
acceptance.TestAccPreCheck(t)
20+
// This test case requires setting a host ID with container version host protection enabled.
21+
acceptance.TestAccPreCheckHSSHostProtectionHostId(t)
22+
},
23+
ProviderFactories: acceptance.TestAccProviderFactories,
24+
Steps: []resource.TestStep{
25+
{
26+
Config: testAccDataSourceAntivirusAvailableHosts_basic,
27+
Check: resource.ComposeTestCheckFunc(
28+
dc.CheckResourceExists(),
29+
resource.TestCheckResourceAttrSet(dataSource, "total_num"),
30+
resource.TestCheckResourceAttrSet(dataSource, "data_list.#"),
31+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_id"),
32+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_name"),
33+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.private_ip"),
34+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.agent_id"),
35+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.os_type"),
36+
37+
resource.TestCheckOutput("is_host_id_filter_useful", "true"),
38+
resource.TestCheckOutput("is_host_name_filter_useful", "true"),
39+
resource.TestCheckOutput("is_private_ip_filter_useful", "true"),
40+
resource.TestCheckOutput("is_enterprise_project_id_filter_useful", "true"),
41+
resource.TestCheckOutput("not_found_validation_pass", "true"),
42+
),
43+
},
44+
},
45+
})
46+
}
47+
48+
const testAccDataSourceAntivirusAvailableHosts_basic string = `
49+
data "huaweicloud_hss_antivirus_available_hosts" "test" {
50+
scan_type = "custom"
51+
start_type = "now"
52+
}
53+
54+
# Filter using host_id.
55+
locals {
56+
host_id = data.huaweicloud_hss_antivirus_available_hosts.test.data_list[0].host_id
57+
}
58+
59+
data "huaweicloud_hss_antivirus_available_hosts" "host_id_filter" {
60+
scan_type = "custom"
61+
start_type = "now"
62+
host_id = local.host_id
63+
}
64+
65+
output "is_host_id_filter_useful" {
66+
value = length(data.huaweicloud_hss_antivirus_available_hosts.host_id_filter.data_list) > 0 && alltrue(
67+
[for v in data.huaweicloud_hss_antivirus_available_hosts.host_id_filter.data_list[*].host_id : v == local.host_id]
68+
)
69+
}
70+
71+
# Filter using host_name.
72+
locals {
73+
host_name = data.huaweicloud_hss_antivirus_available_hosts.test.data_list[0].host_name
74+
}
75+
76+
data "huaweicloud_hss_antivirus_available_hosts" "host_name_filter" {
77+
scan_type = "custom"
78+
start_type = "now"
79+
host_name = local.host_name
80+
}
81+
82+
output "is_host_name_filter_useful" {
83+
value = length(data.huaweicloud_hss_antivirus_available_hosts.host_name_filter.data_list) > 0 && alltrue(
84+
[for v in data.huaweicloud_hss_antivirus_available_hosts.host_name_filter.data_list[*].host_name : v == local.host_name]
85+
)
86+
}
87+
88+
# Filter using private_ip.
89+
locals {
90+
private_ip = data.huaweicloud_hss_antivirus_available_hosts.test.data_list[0].private_ip
91+
}
92+
93+
data "huaweicloud_hss_antivirus_available_hosts" "private_ip_filter" {
94+
scan_type = "custom"
95+
start_type = "now"
96+
private_ip = local.private_ip
97+
}
98+
99+
output "is_private_ip_filter_useful" {
100+
value = length(data.huaweicloud_hss_antivirus_available_hosts.private_ip_filter.data_list) > 0 && alltrue(
101+
[for v in data.huaweicloud_hss_antivirus_available_hosts.private_ip_filter.data_list[*].private_ip : v == local.private_ip]
102+
)
103+
}
104+
105+
# Filter using enterprise_project_id.
106+
data "huaweicloud_hss_antivirus_available_hosts" "enterprise_project_id_filter" {
107+
scan_type = "custom"
108+
start_type = "now"
109+
enterprise_project_id = "all_granted_eps"
110+
}
111+
112+
output "is_enterprise_project_id_filter_useful" {
113+
value = length(data.huaweicloud_hss_antivirus_available_hosts.enterprise_project_id_filter.data_list) > 0
114+
}
115+
116+
# Filter using non existent host_name.
117+
data "huaweicloud_hss_antivirus_available_hosts" "not_found" {
118+
scan_type = "custom"
119+
start_type = "now"
120+
host_name = "resource_not_found"
121+
}
122+
123+
output "not_found_validation_pass" {
124+
value = length(data.huaweicloud_hss_antivirus_available_hosts.not_found.data_list) == 0
125+
}
126+
`

0 commit comments

Comments
 (0)