Skip to content

Commit e9839a2

Browse files
committed
feat(AOM): support to install UniAgent by remote
1 parent 16c2883 commit e9839a2

File tree

6 files changed

+517
-1
lines changed

6 files changed

+517
-1
lines changed

docs/resources/aom_uniagent.md

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
subcategory: "Application Operations Management (AOM)"
3+
layout: "huaweicloud"
4+
page_title: "HuaweiCloud: huaweicloud_aom_uniagent"
5+
description: |-
6+
Manages an AOM UniAgent resource within HuaweiCloud.
7+
---
8+
9+
# huaweicloud_aom_uniagent
10+
11+
Manages an AOM UniAgent resource within HuaweiCloud.
12+
13+
-> Destroying resource does not uninstall the UniAgent.
14+
15+
## Example Usage
16+
17+
### Install UniAgent for a host
18+
19+
```hcl
20+
variable "installer_agent_id" {}
21+
variable "inner_ip" {}
22+
variable "account" {}
23+
variable "password" {}
24+
25+
resource "huaweicloud_aom_uniagent" "test" {
26+
installer_agent_id = var.installer_agent_id
27+
version = "1.1.6"
28+
public_net_flag = false
29+
proxy_region_id = 0
30+
inner_ip = var.inner_ip
31+
port = 22
32+
account = var.account
33+
password = var.password
34+
os_type = "LINUX"
35+
}
36+
```
37+
38+
### Reinstall UniAgent for a host
39+
40+
```hcl
41+
variable "installer_agent_id" {}
42+
variable "inner_ip" {}
43+
variable "account" {}
44+
variable "password" {}
45+
variable "agent_id" {}
46+
47+
resource "huaweicloud_aom_uniagent" "test" {
48+
installer_agent_id = var.installer_agent_id
49+
version = "1.1.6"
50+
public_net_flag = false
51+
proxy_region_id = 0
52+
agent_id = var.agent_id
53+
inner_ip = var.inner_ip
54+
port = 22
55+
account = var.account
56+
password = var.password
57+
os_type = "LINUX"
58+
}
59+
```
60+
61+
## Argument Reference
62+
63+
The following arguments are supported:
64+
65+
* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
66+
If omitted, the provider-level region will be used. Changing this creates a new resource.
67+
68+
* `installer_agent_id` - (Required, String, NonUpdatable) Specifies the installer agent ID.
69+
70+
* `version` - (Required, String) Specifies the UniAgent version to be installed.
71+
72+
-> When updating the `version`, `agent_id` must be specified.
73+
74+
* `public_net_flag` - (Required, Bool, NonUpdatable) Specifies the whether to use public network access.
75+
76+
* `proxy_region_id` - (Required, Int, NonUpdatable) Specifies the proxy region ID.
77+
+ Specifies it as **0** to use the direct access.
78+
+ Specifies it as specific proxy region ID to use the proxy access.
79+
80+
* `inner_ip` - (Required, String, NonUpdatable) Specifies the IP of the host where the UniAgent will be installed.
81+
82+
* `port` - (Required, String, NonUpdatable) Specifies the login port of the host where the UniAgent will be installed.
83+
84+
* `account` - (Required, String, NonUpdatable) Specifies the login account of the host where the UniAgent will be
85+
installed.
86+
87+
* `password` - (Required, String, NonUpdatable) Specifies the login password of the host where the UniAgent will be
88+
installed.
89+
90+
* `os_type` - (Required, String, NonUpdatable) Specifies the OS type of the host where the UniAgent will be installed.
91+
92+
* `agent_id` - (Optional, String) Specifies the agent ID of the host where the UniAgent will be installed.
93+
94+
-> If you are reinstalling the UniAgent or updating the UniAgent version, `agent_id` must specified.
95+
96+
* `vpc_id` - (Optional, String, NonUpdatable) Specifies the VPC ID of the host where the UniAgent will be installed.
97+
98+
* `coc_cmdb_id` - (Optional, String, NonUpdatable) Specifies the COC CMDB ID of the host where the UniAgent will be
99+
installed.
100+
101+
* `icagent_install_flag` - (Optional, Bool, NonUpdatable) Specifies whether to install ICAgent. Defaults to **false**.
102+
103+
* `icagent_install_version` - (Optional, String, NonUpdatable) Specifies the ICAgent version to be installed.
104+
If it's not specified and `icagent_install_flag` is **true**, install the latest version by default.
105+
106+
* `access_key` - (Optional, String, NonUpdatable) Specifies the access key of the IAM account where the host ICAgent is
107+
not installed.
108+
109+
* `secret_key` - (Optional, String, NonUpdatable) Specifies the secret key of the IAM account where the host ICAgent is
110+
not installed.
111+
112+
-> AK/SK is required only when installing the older version of ICAgent.
113+
114+
## Attribute Reference
115+
116+
In addition to all arguments above, the following attributes are exported:
117+
118+
* `id` - The resource ID in UUID format.

huaweicloud/config/logger.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,6 @@ func isSecurityFields(field string) bool {
292292
// request JSON body
293293
securityFields := []string{"adminpass", "encrypted_user_data", "nonce", "email", "phone", "phone_number", "phone_num",
294294
"sip_number", "signature", "user_passwd", "auth", "cert_content", "private_key", "trusted_root_ca", "sk", "src_sk",
295-
"dst_sk"}
295+
"dst_sk", "domain_sk"}
296296
return utils.StrSliceContains(securityFields, checkField)
297297
}

huaweicloud/provider.go

+1
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,7 @@ func Provider() *schema.Provider {
13981398
"huaweicloud_access_analyzer_archive_rule": accessanalyzer.ResourceArchiveRule(),
13991399
"huaweicloud_access_analyzer_archive_rule_apply": accessanalyzer.ResourceArchiveRuleApply(),
14001400

1401+
"huaweicloud_aom_uniagent": aom.ResourceUniAgent(),
14011402
"huaweicloud_aom_alarm_rule": aom.ResourceAlarmRule(),
14021403
"huaweicloud_aomv4_alarm_rule": aom.ResourceAlarmRuleV4(),
14031404
"huaweicloud_aom_event_alarm_rule": aom.ResourceEventAlarmRule(),

huaweicloud/services/acceptance/acceptance.go

+8
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ var (
358358
// The CMDB sub-application ID of AOM service
359359
HW_AOM_SUB_APPLICATION_ID = os.Getenv("HW_AOM_SUB_APPLICATION_ID")
360360
HW_AOM_MULTI_ACCOUNT_AGGREGATION_RULE_ENABLE = os.Getenv("HW_AOM_MULTI_ACCOUNT_AGGREGATION_RULE_ENABLE")
361+
HW_AOM_UNIAGENT_AGENT_ID = os.Getenv("HW_AOM_UNIAGENT_AGENT_ID")
361362

362363
// the ID of ECS instance which has installed uniagent
363364
HW_COC_INSTANCE_ID = os.Getenv("HW_COC_INSTANCE_ID")
@@ -2151,6 +2152,13 @@ func TestAccPreCheckMultiAccountAggregationRuleEnable(t *testing.T) {
21512152
}
21522153
}
21532154

2155+
// lintignore:AT003
2156+
func TestAccPreCheckAOMUniAgentAgentID(t *testing.T) {
2157+
if HW_AOM_UNIAGENT_AGENT_ID == "" {
2158+
t.Skip("HW_AOM_UNIAGENT_AGENT_ID must be set for the acceptance test")
2159+
}
2160+
}
2161+
21542162
// lintignore:AT003
21552163
func TestAccPreCheckCocInstanceID(t *testing.T) {
21562164
if HW_COC_INSTANCE_ID == "" {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package aom
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+
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance/common"
11+
)
12+
13+
func TestAccUniAgent_basic(t *testing.T) {
14+
rName := acceptance.RandomAccResourceName()
15+
resourceName := "huaweicloud_aom_uniagent.test"
16+
17+
resource.ParallelTest(t, resource.TestCase{
18+
PreCheck: func() {
19+
acceptance.TestAccPreCheck(t)
20+
acceptance.TestAccPreCheckAOMUniAgentAgentID(t)
21+
},
22+
ProviderFactories: acceptance.TestAccProviderFactories,
23+
CheckDestroy: nil,
24+
Steps: []resource.TestStep{
25+
{
26+
Config: testUniAgent_basic(rName),
27+
Check: resource.ComposeTestCheckFunc(
28+
resource.TestCheckResourceAttr(resourceName, "version", "1.1.6"),
29+
),
30+
},
31+
{
32+
Config: testUniAgent_update(rName),
33+
Check: resource.ComposeTestCheckFunc(
34+
resource.TestCheckResourceAttr(resourceName, "version", "1.1.5"),
35+
),
36+
},
37+
},
38+
})
39+
}
40+
41+
func testUniAgent_ECS_base(name string) string {
42+
return fmt.Sprintf(`
43+
%[1]s
44+
45+
resource "huaweicloud_compute_instance" "test" {
46+
name = "%[2]s"
47+
image_id = data.huaweicloud_images_image.test.id
48+
flavor_id = data.huaweicloud_compute_flavors.test.ids[0]
49+
availability_zone = data.huaweicloud_availability_zones.test.names[0]
50+
admin_pass = "Terraform@123"
51+
delete_disks_on_termination = true
52+
security_group_ids = [huaweicloud_networking_secgroup.test.id]
53+
54+
network {
55+
uuid = huaweicloud_vpc_subnet.test.id
56+
}
57+
}`, common.TestBaseComputeResources(name), name)
58+
}
59+
60+
func testUniAgent_basic(name string) string {
61+
return fmt.Sprintf(`
62+
%[1]s
63+
64+
resource "huaweicloud_aom_uniagent" "test" {
65+
installer_agent_id = "%[2]s"
66+
version = "1.1.6"
67+
public_net_flag = false
68+
proxy_region_id = 0
69+
inner_ip = huaweicloud_compute_instance.test.access_ip_v4
70+
port = 22
71+
account = "root"
72+
password = "Terraform@123"
73+
os_type = "LINUX"
74+
}`, testUniAgent_ECS_base(name), acceptance.HW_AOM_UNIAGENT_AGENT_ID)
75+
}
76+
77+
func testUniAgent_update(name string) string {
78+
return fmt.Sprintf(`
79+
%[1]s
80+
81+
# enter installer_agent_id to agent_id, just for test
82+
# when update version, API do not check for agent_id, and response will be success, but actually do nothing
83+
resource "huaweicloud_aom_uniagent" "test" {
84+
installer_agent_id = "%[2]s"
85+
version = "1.1.5"
86+
public_net_flag = false
87+
proxy_region_id = 0
88+
agent_id = "%[2]s"
89+
inner_ip = huaweicloud_compute_instance.test.access_ip_v4
90+
port = 22
91+
account = "root"
92+
password = "Terraform@123"
93+
os_type = "LINUX"
94+
}`, testUniAgent_ECS_base(name), acceptance.HW_AOM_UNIAGENT_AGENT_ID)
95+
}

0 commit comments

Comments
 (0)