Skip to content

Commit bc788b5

Browse files
feat(hss): add new resource to create a vulnerability scan task (#8410)
1 parent bfc3c8a commit bc788b5

File tree

5 files changed

+453
-0
lines changed

5 files changed

+453
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
subcategory: "Host Security Service (HSS)"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_hss_vulnerability_scan_task"
5+
description: |-
6+
Manages a vulnerability scan task resource within HuaweiCloud.
7+
---
8+
9+
# huaweicloud_hss_vulnerability_scan_task
10+
11+
Manages a vulnerability scan task resource within HuaweiCloud.
12+
13+
-> This resource is a one-time action resource. Deleting this resource will not clear the corresponding request record,
14+
but will only remove the resource information from the tf state file.
15+
16+
## Example Usage
17+
18+
```hcl
19+
variable "manual_scan_type" {
20+
type = list(string)
21+
}
22+
23+
resource "huaweicloud_hss_vulnerability_scan_task" "test" {
24+
manual_scan_type = var.manual_scan_type
25+
batch_flag = true
26+
range_type = "all_host"
27+
}
28+
```
29+
30+
## Argument Reference
31+
32+
The following arguments are supported:
33+
34+
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
35+
If omitted, the provider-level region will be used.
36+
Changing this parameter will create a new resource.
37+
38+
* `manual_scan_type` - (Required, List, NonUpdatable) Specifies the operation type.
39+
The valid values are as follows:
40+
+ **linux_vul**: Linux vulnerability.
41+
+ **windows_vul**: Windows vulnerability.
42+
+ **web_cms**: Web-CMS vulnerability.
43+
+ **app_vul**: Application vulnerability.
44+
+ **urgent_vul**: Emergency vulnerability.
45+
46+
* `batch_flag` - (Required, Bool, NonUpdatable) Specifies Whether the operation is performed in batches.
47+
If the value is true, all supported servers are scanned.
48+
The valid values are as follows:
49+
+ **true**
50+
+ **false**
51+
52+
* `range_type` - (Required, String, NonUpdatable) Specifies the range of servers to be scanned.
53+
The valid values are as follows:
54+
+ **all_host**
55+
+ **specific_host**
56+
57+
* `agent_id_list` - (Optional, List, NonUpdatable) Specifies the ID list of the server agent.
58+
59+
-> This parameter is valid and required when the `range_type` is set to **specific_host**.
60+
61+
* `urgent_vul_id_list` - (Optional, List, NonUpdatable) Specifies the scan all ID list of emergency vulnerabilities.
62+
If this parameter is left blank, all emergency vulnerabilities are scanned.
63+
The valid values are as follows:
64+
+ **URGENT-CVE-2023-46604**
65+
+ **URGENT-HSSVD-2020-1109**
66+
+ **URGENT-CVE-2022-26134**
67+
+ **URGENT-CVE-2023-22515**
68+
+ **URGENT-CVE-2023-22518**
69+
+ **URGENT-CVE-2023-28432**
70+
+ **URGENT-CVE-2023-37582**
71+
+ **URGENT-CVE-2023-33246**
72+
+ **URGENT-CNVD-2023-02709**
73+
+ **URGENT-CVE-2022-36804**
74+
+ **URGENT-CVE-2022-22965**
75+
+ **URGENT-CVE-2022-25845**
76+
+ **URGENT-CVE-2019-14439**
77+
+ **URGENT-CVE-2020-13933**
78+
+ **URGENT-CVE-2020-26217**
79+
+ **URGENT-CVE-2021-4034**
80+
+ **URGENT-CVE-2021-44228**
81+
+ **URGENT-CVE-2022-0847**
82+
83+
-> For more details, please refer to [document](https://support.huaweicloud.com/intl/en-us/api-hss2.0/CreateVulnerabilityScanTask_0.html).
84+
85+
* `enterprise_project_id` - (Optional, String, NonUpdatable) Specifies the enterprise project ID.
86+
This parameter is valid only when the enterprise project is enabled.
87+
The default value is **0**, indicating the default enterprise project.
88+
If it is necessary to operate the hosts under all enterprise projects, the value is **all_granted_eps**.
89+
If you only have permissions for a specific enterprise project, you need set the enterprise project ID. Otherwise,
90+
the operation may fail due to insufficient permissions.
91+
92+
## Attribute Reference
93+
94+
In addition to all arguments above, the following attributes are exported:
95+
96+
* `id` - The resource ID.
97+
98+
* `scan_type` - The scan task type.
99+
100+
* `start_time` - The scan task start time.
101+
102+
* `end_time` - The scan task end time.
103+
104+
* `scan_vul_types` - The list of vulnerability types scanned by the task.
105+
106+
* `status` - The scan task status.
107+
The valid values are as follows:
108+
+ **running**
109+
+ **finished**
110+
111+
* `scanning_host_num` - The number of hosts are being scanned.
112+
113+
* `success_host_num` - The number of hosts have been successfully scanned.
114+
115+
* `failed_host_num` - The number of hosts fail to be scanned.
116+
117+
* `estimated_time` - The expected completion time.

huaweicloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3099,6 +3099,7 @@ func Provider() *schema.Provider {
30993099
"huaweicloud_hss_setting_two_factor_login_config": hss.ResourceSettingTwoFactorLoginConfig(),
31003100
"huaweicloud_hss_switch_honeypot_port_policy": hss.ResourceSwitchHoneypotPortPolicy(),
31013101
"huaweicloud_hss_vulnerability_information_export": hss.ResourceVulnerabilityInformationExport(),
3102+
"huaweicloud_hss_vulnerability_scan_task": hss.ResourceVulnerabilityScanTask(),
31023103
"huaweicloud_hss_vulnerability_task_user_trace": hss.ResourceVulnerabilityTaskUserTrace(),
31033104
"huaweicloud_hss_vulnerability_history_export_task": hss.ResourceVulnerabilityHistoryExportTask(),
31043105
"huaweicloud_hss_file_download": hss.ResourceFileDownload(),

huaweicloud/services/acceptance/acceptance.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ var (
738738
HW_HSS_DOMAIN = os.Getenv("HW_HSS_DOMAIN")
739739
HW_HSS_IAC_FILE_ID = os.Getenv("HW_HSS_IAC_FILE_ID")
740740
HW_HSS_TASK_ID = os.Getenv("HW_HSS_TASK_ID")
741+
HW_HSS_AGENT_ID = os.Getenv("HW_HSS_AGENT_ID")
741742

742743
HW_DDM_INSTANCE_ID = os.Getenv("HW_DDM_INSTANCE_ID")
743744
HW_DDM_PROCESS_ID = os.Getenv("HW_DDM_PROCESS_ID")
@@ -3922,6 +3923,13 @@ func TestAccPreCheckHSSTaskId(t *testing.T) {
39223923
}
39233924
}
39243925

3926+
// lintignore:AT003
3927+
func TestAccPreCheckHSSAgentId(t *testing.T) {
3928+
if HW_HSS_AGENT_ID == "" {
3929+
t.Skip("HW_HSS_AGENT_ID must be set for the acceptance test")
3930+
}
3931+
}
3932+
39253933
// lintignore:AT003
39263934
func TestAccPreCheckDDMInstanceID(t *testing.T) {
39273935
if HW_DDM_INSTANCE_ID == "" {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package hss
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
9+
10+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config"
11+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
12+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/hss"
13+
)
14+
15+
func getResourceVulnerabilityScanTaskFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) {
16+
client, err := cfg.NewServiceClient("hss", acceptance.HW_REGION_NAME)
17+
if err != nil {
18+
return nil, fmt.Errorf("error creating HSS client: %s", err)
19+
}
20+
21+
return hss.GetVulnerabilityScanTask(client, state.Primary.ID, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST)
22+
}
23+
24+
func TestAccResourceVulnerabilityScanTask_basic(t *testing.T) {
25+
var (
26+
resourceName = "huaweicloud_hss_vulnerability_scan_task.test"
27+
28+
object interface{}
29+
rc = acceptance.InitResourceCheck(
30+
resourceName,
31+
&object,
32+
getResourceVulnerabilityScanTaskFunc,
33+
)
34+
)
35+
36+
resource.ParallelTest(t, resource.TestCase{
37+
PreCheck: func() {
38+
acceptance.TestAccPreCheck(t)
39+
acceptance.TestAccPreCheckEpsID(t)
40+
acceptance.TestAccPreCheckHSSAgentId(t)
41+
},
42+
ProviderFactories: acceptance.TestAccProviderFactories,
43+
CheckDestroy: nil,
44+
Steps: []resource.TestStep{
45+
{
46+
Config: testAccVulnerabilityScanTask_basic(),
47+
Check: resource.ComposeTestCheckFunc(
48+
rc.CheckResourceExists(),
49+
resource.TestCheckResourceAttr(resourceName, "manual_scan_type.#", "2"),
50+
resource.TestCheckResourceAttr(resourceName, "batch_flag", "false"),
51+
resource.TestCheckResourceAttr(resourceName, "range_type", "specific_host"),
52+
resource.TestCheckResourceAttr(resourceName, "agent_id_list.#", "1"),
53+
resource.TestCheckResourceAttr(resourceName, "urgent_vul_id_list.#", "1"),
54+
resource.TestCheckResourceAttrSet(resourceName, "scan_type"),
55+
resource.TestCheckResourceAttrSet(resourceName, "status"),
56+
),
57+
},
58+
},
59+
})
60+
}
61+
62+
func testAccVulnerabilityScanTask_basic() string {
63+
return fmt.Sprintf(`
64+
resource "huaweicloud_hss_vulnerability_scan_task" "test" {
65+
manual_scan_type = ["linux_vul","app_vul"]
66+
batch_flag = false
67+
range_type = "specific_host"
68+
agent_id_list = ["%[1]s"]
69+
urgent_vul_id_list = ["URGENT-HSSVD-2020-1109"]
70+
enterprise_project_id = "%[2]s"
71+
}
72+
`, acceptance.HW_HSS_AGENT_ID, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST)
73+
}

0 commit comments

Comments
 (0)