Skip to content

Commit 6d2fb89

Browse files
authored
feat(hss): add new data source to query hss app (#7023)
1 parent 450db65 commit 6d2fb89

File tree

4 files changed

+472
-0
lines changed

4 files changed

+472
-0
lines changed

docs/data-sources/hss_asset_apps.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
subcategory: "Host Security Service (HSS)"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_hss_asset_apps"
5+
description: |-
6+
Use this data source to query the HSS asset app list within HuaweiCloud.
7+
---
8+
9+
# huaweicloud_hss_asset_apps
10+
11+
Use this data source to query the HSS asset app list within HuaweiCloud.
12+
13+
## Example Usage
14+
15+
```hcl
16+
data "huaweicloud_hss_asset_apps" "test" {}
17+
```
18+
19+
## Argument Reference
20+
21+
The following arguments are supported:
22+
23+
* `region` - (Optional, String) Specifies the region in which to query the resource.
24+
If omitted, the provider-level region will be used.
25+
26+
* `enterprise_project_id` - (Optional, String) Specifies the ID of the enterprise project to which the hosts belong.
27+
This parameter is valid only when the enterprise project function is enabled.
28+
The value **all_granted_eps** indicates all enterprise projects.
29+
If omitted, the default enterprise project will be used.
30+
31+
* `host_id` - (Optional, String) Specifies the host ID.
32+
33+
* `host_name` - (Optional, String) Specifies the host name.
34+
35+
* `app_name` - (Optional, String) Specifies the software name.
36+
37+
* `host_ip` - (Optional, String) Specifies the host IP address.
38+
39+
* `version` - (Optional, String) Specifies the software version.
40+
41+
* `install_dir` - (Optional, String) Specifies the installation directory.
42+
43+
* `category` - (Optional, String) Specifies the type. The default value is **host**.
44+
The valid values are as follows:
45+
+ **host**: Host.
46+
+ **container**: Container.
47+
48+
* `part_match` - (Optional, Bool) Specifies whether fuzzy match is used. The default value is **false**.
49+
50+
## Attribute Reference
51+
52+
In addition to all arguments above, the following attributes are exported:
53+
54+
* `id` - The data source ID.
55+
56+
* `data_list` - The software list.
57+
The [data_list](#app_structure) structure is documented below.
58+
59+
<a name="app_structure"></a>
60+
The `data_list` block supports:
61+
62+
* `agent_id` - The agent ID.
63+
64+
* `host_id` - The host ID.
65+
66+
* `host_name` - The host name.
67+
68+
* `host_ip` - The host IP address.
69+
70+
* `app_name` - The software name.
71+
72+
* `version` - The version number.
73+
74+
* `update_time` - The latest update time, in milliseconds.
75+
76+
* `recent_scan_time` - The latest scanning time, in milliseconds.
77+
78+
* `container_id` - The container ID.
79+
80+
* `container_name` - The container name.

huaweicloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ func Provider() *schema.Provider {
10301030
"huaweicloud_hss_resource_quotas": hss.DataSourceResourceQuotas(),
10311031
"huaweicloud_hss_auto_launch_statistics": hss.DataSourceAutoLaunchStatistics(),
10321032
"huaweicloud_hss_event_unblock_ips": hss.DataSourceEventUnblockIps(),
1033+
"huaweicloud_hss_asset_apps": hss.DataSourceAssetApps(),
10331034

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

0 commit comments

Comments
 (0)