Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat(AOM): support to install UniAgent by remote #6398

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 118 additions & 0 deletions docs/resources/aom_uniagent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
subcategory: "Application Operations Management (AOM)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_aom_uniagent"
description: |-
Manages an AOM UniAgent resource within HuaweiCloud.
---

# huaweicloud_aom_uniagent

Manages an AOM UniAgent resource within HuaweiCloud.

-> Destroying resource does not uninstall the UniAgent.

## Example Usage

### Install UniAgent for a host

```hcl
variable "installer_agent_id" {}
variable "inner_ip" {}
variable "account" {}
variable "password" {}
resource "huaweicloud_aom_uniagent" "test" {
installer_agent_id = var.installer_agent_id
version = "1.1.6"
public_net_flag = false
proxy_region_id = 0
inner_ip = var.inner_ip
port = 22
account = var.account
password = var.password
os_type = "LINUX"
}
```

### Reinstall UniAgent for a host

```hcl
variable "installer_agent_id" {}
variable "inner_ip" {}
variable "account" {}
variable "password" {}
variable "agent_id" {}
resource "huaweicloud_aom_uniagent" "test" {
installer_agent_id = var.installer_agent_id
version = "1.1.6"
public_net_flag = false
proxy_region_id = 0
agent_id = var.agent_id
inner_ip = var.inner_ip
port = 22
account = var.account
password = var.password
os_type = "LINUX"
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String, ForceNew) Specifies the region in which to create the resource.
If omitted, the provider-level region will be used. Changing this creates a new resource.

* `installer_agent_id` - (Required, String, NonUpdatable) Specifies the installer agent ID.

* `version` - (Required, String) Specifies the UniAgent version to be installed.

-> When updating the `version`, `agent_id` must be specified.

* `public_net_flag` - (Required, Bool, NonUpdatable) Specifies the whether to use public network access.

* `proxy_region_id` - (Required, Int, NonUpdatable) Specifies the proxy region ID.
+ Specifies it as **0** to use the direct access.
+ Specifies it as specific proxy region ID to use the proxy access.

* `inner_ip` - (Required, String, NonUpdatable) Specifies the IP of the host where the UniAgent will be installed.

* `port` - (Required, String, NonUpdatable) Specifies the login port of the host where the UniAgent will be installed.

* `account` - (Required, String, NonUpdatable) Specifies the login account of the host where the UniAgent will be
installed.

* `password` - (Required, String, NonUpdatable) Specifies the login password of the host where the UniAgent will be
installed.

* `os_type` - (Required, String, NonUpdatable) Specifies the OS type of the host where the UniAgent will be installed.

* `agent_id` - (Optional, String) Specifies the agent ID of the host where the UniAgent will be installed.

-> If you are reinstalling the UniAgent or updating the UniAgent version, `agent_id` must specified.

* `vpc_id` - (Optional, String, NonUpdatable) Specifies the VPC ID of the host where the UniAgent will be installed.

* `coc_cmdb_id` - (Optional, String, NonUpdatable) Specifies the COC CMDB ID of the host where the UniAgent will be
installed.

* `icagent_install_flag` - (Optional, Bool, NonUpdatable) Specifies whether to install ICAgent. Defaults to **false**.

* `icagent_install_version` - (Optional, String, NonUpdatable) Specifies the ICAgent version to be installed.
If it's not specified and `icagent_install_flag` is **true**, install the latest version by default.

* `access_key` - (Optional, String, NonUpdatable) Specifies the access key of the IAM account where the host ICAgent is
not installed.

* `secret_key` - (Optional, String, NonUpdatable) Specifies the secret key of the IAM account where the host ICAgent is
not installed.

-> AK/SK is required only when installing the older version of ICAgent.

## Attribute Reference

In addition to all arguments above, the following attributes are exported:

* `id` - The resource ID in UUID format.
2 changes: 1 addition & 1 deletion huaweicloud/config/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,6 @@ func isSecurityFields(field string) bool {
// request JSON body
securityFields := []string{"adminpass", "encrypted_user_data", "nonce", "email", "phone", "phone_number", "phone_num",
"sip_number", "signature", "user_passwd", "auth", "cert_content", "private_key", "trusted_root_ca", "sk", "src_sk",
"dst_sk"}
"dst_sk", "domain_sk"}
return utils.StrSliceContains(securityFields, checkField)
}
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,7 @@ func Provider() *schema.Provider {
"huaweicloud_access_analyzer_archive_rule": accessanalyzer.ResourceArchiveRule(),
"huaweicloud_access_analyzer_archive_rule_apply": accessanalyzer.ResourceArchiveRuleApply(),

"huaweicloud_aom_uniagent": aom.ResourceUniAgent(),
"huaweicloud_aom_alarm_rule": aom.ResourceAlarmRule(),
"huaweicloud_aomv4_alarm_rule": aom.ResourceAlarmRuleV4(),
"huaweicloud_aom_event_alarm_rule": aom.ResourceEventAlarmRule(),
Expand Down
8 changes: 8 additions & 0 deletions huaweicloud/services/acceptance/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ var (
// The CMDB sub-application ID of AOM service
HW_AOM_SUB_APPLICATION_ID = os.Getenv("HW_AOM_SUB_APPLICATION_ID")
HW_AOM_MULTI_ACCOUNT_AGGREGATION_RULE_ENABLE = os.Getenv("HW_AOM_MULTI_ACCOUNT_AGGREGATION_RULE_ENABLE")
HW_AOM_UNIAGENT_AGENT_ID = os.Getenv("HW_AOM_UNIAGENT_AGENT_ID")

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

// lintignore:AT003
func TestAccPreCheckAOMUniAgentAgentID(t *testing.T) {
if HW_AOM_UNIAGENT_AGENT_ID == "" {
t.Skip("HW_AOM_UNIAGENT_AGENT_ID must be set for the acceptance test")
}
}

// lintignore:AT003
func TestAccPreCheckCocInstanceID(t *testing.T) {
if HW_COC_INSTANCE_ID == "" {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package aom

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"

"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance/common"
)

func TestAccUniAgent_basic(t *testing.T) {
rName := acceptance.RandomAccResourceName()
resourceName := "huaweicloud_aom_uniagent.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckAOMUniAgentAgentID(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: nil,
Steps: []resource.TestStep{
{
Config: testUniAgent_basic(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "version", "1.1.6"),
),
},
{
Config: testUniAgent_update(rName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resourceName, "version", "1.1.5"),
),
},
},
})
}

func testUniAgent_ECS_base(name string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_compute_instance" "test" {
name = "%[2]s"
image_id = data.huaweicloud_images_image.test.id
flavor_id = data.huaweicloud_compute_flavors.test.ids[0]
availability_zone = data.huaweicloud_availability_zones.test.names[0]
admin_pass = "Terraform@123"
delete_disks_on_termination = true
security_group_ids = [huaweicloud_networking_secgroup.test.id]
network {
uuid = huaweicloud_vpc_subnet.test.id
}
}`, common.TestBaseComputeResources(name), name)
}

func testUniAgent_basic(name string) string {
return fmt.Sprintf(`
%[1]s
resource "huaweicloud_aom_uniagent" "test" {
installer_agent_id = "%[2]s"
version = "1.1.6"
public_net_flag = false
proxy_region_id = 0
inner_ip = huaweicloud_compute_instance.test.access_ip_v4
port = 22
account = "root"
password = "Terraform@123"
os_type = "LINUX"
}`, testUniAgent_ECS_base(name), acceptance.HW_AOM_UNIAGENT_AGENT_ID)
}

func testUniAgent_update(name string) string {
return fmt.Sprintf(`
%[1]s
# enter installer_agent_id to agent_id, just for test
# when update version, API do not check for agent_id, and response will be success, but actually do nothing
resource "huaweicloud_aom_uniagent" "test" {
installer_agent_id = "%[2]s"
version = "1.1.5"
public_net_flag = false
proxy_region_id = 0
agent_id = "%[2]s"
inner_ip = huaweicloud_compute_instance.test.access_ip_v4
port = 22
account = "root"
password = "Terraform@123"
os_type = "LINUX"
}`, testUniAgent_ECS_base(name), acceptance.HW_AOM_UNIAGENT_AGENT_ID)
}
Loading
Loading