Skip to content

Commit fe8d2ee

Browse files
feat(hss): support hss_antivirus_virus_scan_tasks data source (#7402)
1 parent dcd6914 commit fe8d2ee

File tree

5 files changed

+735
-0
lines changed

5 files changed

+735
-0
lines changed
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
---
2+
subcategory: "Host Security Service (HSS)"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_hss_antivirus_virus_scan_tasks"
5+
description: |-
6+
Use this data source to get the list of HSS virus scan tasks within HuaweiCloud.
7+
---
8+
# huaweicloud_hss_antivirus_virus_scan_tasks
9+
10+
Use this data source to get the list of HSS virus scan tasks within HuaweiCloud.
11+
12+
## Example Usage
13+
14+
```hcl
15+
data "huaweicloud_hss_antivirus_virus_scan_tasks" "test" {}
16+
```
17+
18+
## Argument Reference
19+
20+
The following arguments are supported:
21+
22+
* `region` - (Optional, String) Specifies the region in which to query the resource.
23+
If omitted, the provider-level region will be used.
24+
25+
* `whether_paid_task` - (Required, Bool) Specifies whether this scanning task is paid or not.
26+
The valid values are as follows:
27+
+ **true**
28+
+ **false**
29+
30+
* `task_name` - (Optional, String) Specifies the task name.
31+
32+
* `last_days` - (Optional, Int) Specifies the number of days within the query time range. Which is mutually exclusive
33+
with parameters `begin_time` and `end_time`.
34+
35+
* `begin_time` - (Optional, String) Specifies the starting time of the query time period, with a millisecond-level
36+
timestamp. It is mutually exclusive with parameter `last_days`, and it needs to satisfy the condition that the
37+
difference between `end_time` and `begin_time` is less than or equal to `2` days.
38+
39+
* `end_time` - (Optional, String) Specifies the end time of the query time period, with a millisecond-level
40+
timestamp. It is mutually exclusive with parameter `last_days`, and it needs to satisfy the condition that the
41+
difference between `end_time` and `begin_time` is less than or equal to `2` days.
42+
43+
* `task_status` - (Optional, String) Specifies the task status.
44+
The valid values are as follows:
45+
+ **scanning**
46+
+ **cancel**
47+
+ **fail**
48+
+ **finish**
49+
50+
* `host_name` - (Optional, String) Specifies the host name.
51+
52+
* `private_ip` - (Optional, String) Specifies the host private IP address.
53+
54+
* `public_ip` - (Optional, String) Specifies the host public IP address.
55+
56+
* `host_task_status` - (Optional, List) Specifies the list of host scanning status.
57+
The valid values are as follows:
58+
+ **scanning**
59+
+ **success**
60+
+ **fail**
61+
+ **cancel**
62+
63+
* `enterprise_project_id` - (Optional, String) Specifies the enterprise project ID.
64+
This parameter is valid only when the enterprise project is enabled.
65+
The default value is **0**, indicating the default enterprise project.
66+
If you need to query data for all enterprise projects, the value is **all_granted_eps**.
67+
If you only have permissions for a specific enterprise project, you need set the enterprise project ID. Otherwise,
68+
the operation may fail due to insufficient permissions.
69+
70+
## Attributes Reference
71+
72+
In addition to all arguments above, the following attributes are exported:
73+
74+
* `id` - The data source ID in UUID format.
75+
76+
* `total_num` - The total number of tasks.
77+
78+
* `data_list` - The list of virus scan tasks details.
79+
The [data_list](#data_list_struct) structure is documented below.
80+
81+
<a name="data_list_struct"></a>
82+
The `data_list` block supports:
83+
84+
* `task_id` - The task ID.
85+
86+
* `task_name` - The task name.
87+
88+
* `scan_type` - The scan type.
89+
The valid values are as follows:
90+
+ **quick**
91+
+ **full**
92+
+ **custom**
93+
94+
* `start_type` - The startup type.
95+
The valid values are as follows:
96+
+ **now**
97+
+ **later**
98+
+ **period**
99+
100+
* `action` - The disposal action.
101+
The valid values are as follows:
102+
+ **auto**
103+
+ **manual**
104+
105+
* `start_time` - The startup time in milliseconds.
106+
107+
* `task_status` - The task status.
108+
The valid values are as follows:
109+
+ **scanning**
110+
+ **finish**
111+
112+
* `host_num` - The number of associated hosts.
113+
114+
* `success_host_num` - The number of hosts successfully scanned.
115+
116+
* `fail_host_num` - The number of hosts with scanning failures.
117+
118+
* `cancel_host_num` - The number of hosts cancelled.
119+
120+
* `host_info_list` - The list of host details.
121+
The [host_info_list](#host_info_list_struct) structure is documented below.
122+
123+
* `rescan` - Do you need to rescan.
124+
125+
* `whether_paid_task` - Is this scanning task paid or not.
126+
127+
<a name="host_info_list_struct"></a>
128+
The `host_info_list` block supports:
129+
130+
* `host_id` - The host ID.
131+
132+
* `host_name` - The host name.
133+
134+
* `private_ip` - The host private IP address.
135+
136+
* `public_ip` - The host public IP address.
137+
138+
* `asset_value` - The importance of assets.
139+
The valid values are as follows:
140+
+ **important**: Deleted.
141+
+ **common*: Not deleted.
142+
+ **test*: Not deleted.
143+
144+
* `start_time` - The start time in milliseconds.
145+
146+
* `run_duration` - The running time in seconds.
147+
148+
* `scan_progress` - The scan progress.
149+
150+
* `virus_num` - The number of hosts cancelled.
151+
152+
* `scan_file_num` - The number of scanned files.
153+
154+
* `host_task_status` - The host scanning status.
155+
156+
* `fail_reason` - The failure reason.
157+
158+
* `deleted` - Do you want to delete it.
159+
The valid values are as follows:
160+
+ **true**: Deleted.
161+
+ **false*: Not deleted.
162+
163+
* `whether_using_quota` - Whether to use virus scanning and removal quota on a per-use basis.
164+
165+
* `agent_id` - The agent ID.
166+
167+
* `os_type` - The operating system type.
168+
The valid values are as follows:
169+
+ **Linux**
170+
+ **Windows*
171+
172+
* `host_status` - The host status.
173+
174+
* `agent_status` - The agent status.
175+
The valid values are as follows:
176+
+ **installed**
177+
+ **not_installed*
178+
+ **online**
179+
+ **offline**
180+
+ **install_failed**
181+
+ **installing**
182+
+ **not_online**
183+
184+
* `protect_status` - The protection status.
185+
The valid values are as follows:
186+
+ **closed**
187+
+ **opened**
188+
189+
* `os_name` - The operating system name.
190+
191+
* `os_version` - The operating system version.

huaweicloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@ func Provider() *schema.Provider {
11201120
"huaweicloud_hss_antivirus_available_hosts": hss.DataSourceAntivirusAvailableHosts(),
11211121
"huaweicloud_hss_antivirus_statistic": hss.DataSourceAntivirusStatistic(),
11221122
"huaweicloud_hss_antivirus_pay_per_scan_switch_status": hss.DataSourceAntivirusPayPerScanSwitchStatus(),
1123+
"huaweicloud_hss_antivirus_virus_scan_tasks": hss.DataSourceAntivirusVirusScanTasks(),
11231124
"huaweicloud_hss_backup_policy": hss.DataSourceBackupPolicy(),
11241125

11251126
"huaweicloud_identity_permissions": iam.DataSourceIdentityPermissions(),

huaweicloud/services/acceptance/acceptance.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ var (
626626
HW_HSS_EVENT_ALARM_WHITE_LIST_EVENT_TYPE = os.Getenv("HW_HSS_EVENT_ALARM_WHITE_LIST_EVENT_TYPE")
627627
HW_HSS_EVENT_ALARM_WHITE_LIST_HASH = os.Getenv("HW_HSS_EVENT_ALARM_WHITE_LIST_HASH")
628628
HW_HSS_EVENT_ALARM_WHITE_LIST_DESCRIPTION = os.Getenv("HW_HSS_EVENT_ALARM_WHITE_LIST_DESCRIPTION")
629+
HW_HSS_ANTIVIRUS_ENABLED = os.Getenv("HW_HSS_ANTIVIRUS_ENABLED")
629630
// The vulnerability ID
630631
HW_HSS_VUL_ID = os.Getenv("HW_HSS_VUL_ID")
631632
HW_HSS_POLICY_ID = os.Getenv("HW_HSS_POLICY_ID")
@@ -3162,6 +3163,13 @@ func TestAccPreCheckHSSEventAlarmWhiteListDeleteEnabled(t *testing.T) {
31623163
}
31633164
}
31643165

3166+
// lintignore:AT003
3167+
func TestAccPreCheckHSSAntivirusEnabled(t *testing.T) {
3168+
if HW_HSS_ANTIVIRUS_ENABLED == "" {
3169+
t.Skip("HW_HSS_ANTIVIRUS_ENABLED must be set for the acceptance test")
3170+
}
3171+
}
3172+
31653173
// lintignore:AT003
31663174
func TestAccPreCheckHSSCCEProtection(t *testing.T) {
31673175
if HW_CCE_CLUSTER_ID == "" || HW_CCE_CLUSTER_NAME == "" {
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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 TestAccDataSourceAntivirusVirusScanTasks_basic(t *testing.T) {
12+
var (
13+
dataSource = "data.huaweicloud_hss_antivirus_virus_scan_tasks.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 preparation of virus scanning task data.
21+
acceptance.TestAccPreCheckHSSAntivirusEnabled(t)
22+
},
23+
ProviderFactories: acceptance.TestAccProviderFactories,
24+
Steps: []resource.TestStep{
25+
{
26+
Config: testAccDataSourceAntivirusVirusScanTasks_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.task_id"),
32+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.task_name"),
33+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.scan_type"),
34+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.start_type"),
35+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.action"),
36+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.start_time"),
37+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.task_status"),
38+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_num"),
39+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.success_host_num"),
40+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.fail_host_num"),
41+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.cancel_host_num"),
42+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_info_list.#"),
43+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_info_list.0.host_id"),
44+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_info_list.0.host_name"),
45+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_info_list.0.start_time"),
46+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_info_list.0.run_duration"),
47+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_info_list.0.scan_progress"),
48+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_info_list.0.virus_num"),
49+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_info_list.0.scan_file_num"),
50+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_info_list.0.host_task_status"),
51+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_info_list.0.deleted"),
52+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.host_info_list.0.whether_using_quota"),
53+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.rescan"),
54+
resource.TestCheckResourceAttrSet(dataSource, "data_list.0.whether_paid_task"),
55+
56+
resource.TestCheckOutput("is_task_name_filter_useful", "true"),
57+
resource.TestCheckOutput("is_last_days_filter_useful", "true"),
58+
resource.TestCheckOutput("is_task_status_filter_useful", "true"),
59+
resource.TestCheckOutput("is_enterprise_project_id_filter_useful", "true"),
60+
resource.TestCheckOutput("not_found_validation_pass", "true"),
61+
),
62+
},
63+
},
64+
})
65+
}
66+
67+
const testAccDataSourceAntivirusVirusScanTasks_basic string = `
68+
data "huaweicloud_hss_antivirus_virus_scan_tasks" "test" {
69+
whether_paid_task = false
70+
}
71+
72+
# Filter using task_name.
73+
locals {
74+
task_name = data.huaweicloud_hss_antivirus_virus_scan_tasks.test.data_list[0].task_name
75+
}
76+
77+
data "huaweicloud_hss_antivirus_virus_scan_tasks" "task_name_filter" {
78+
whether_paid_task = false
79+
task_name = local.task_name
80+
}
81+
82+
# The task_name is fuzzy match.
83+
output "is_task_name_filter_useful" {
84+
value = length(data.huaweicloud_hss_antivirus_virus_scan_tasks.task_name_filter.data_list) > 0
85+
}
86+
87+
# Filter using last_days.
88+
data "huaweicloud_hss_antivirus_virus_scan_tasks" "last_days_filter" {
89+
whether_paid_task = false
90+
last_days = 30
91+
}
92+
93+
output "is_last_days_filter_useful" {
94+
value = length(data.huaweicloud_hss_antivirus_virus_scan_tasks.last_days_filter.data_list) > 0
95+
}
96+
97+
# Filter using task_status.
98+
locals {
99+
task_status = data.huaweicloud_hss_antivirus_virus_scan_tasks.test.data_list[0].task_status
100+
}
101+
102+
data "huaweicloud_hss_antivirus_virus_scan_tasks" "task_status_filter" {
103+
whether_paid_task = false
104+
task_status = local.task_status
105+
}
106+
107+
output "is_task_status_filter_useful" {
108+
value = length(data.huaweicloud_hss_antivirus_virus_scan_tasks.task_status_filter.data_list) > 0 && alltrue(
109+
[for v in data.huaweicloud_hss_antivirus_virus_scan_tasks.task_status_filter.data_list[*].task_status : v == local.task_status]
110+
)
111+
}
112+
113+
# Filter using enterprise_project_id.
114+
data "huaweicloud_hss_antivirus_virus_scan_tasks" "enterprise_project_id_filter" {
115+
whether_paid_task = false
116+
enterprise_project_id = "all_granted_eps"
117+
}
118+
119+
output "is_enterprise_project_id_filter_useful" {
120+
value = length(data.huaweicloud_hss_antivirus_virus_scan_tasks.enterprise_project_id_filter.data_list) > 0
121+
}
122+
123+
# Filter using non existent task_name.
124+
data "huaweicloud_hss_antivirus_virus_scan_tasks" "not_found" {
125+
whether_paid_task = false
126+
task_name = "resource_not_found"
127+
}
128+
129+
output "not_found_validation_pass" {
130+
value = length(data.huaweicloud_hss_antivirus_virus_scan_tasks.not_found.data_list) == 0
131+
}
132+
`

0 commit comments

Comments
 (0)