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

feat(aom): support dashboard management #5389

Merged
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
70 changes: 70 additions & 0 deletions docs/data-sources/aom_dashboards.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
subcategory: "Application Operations Management (AOM)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_aom_dashboards"
description: |-
Use this data source to get the list of AOM dashboards.
---

# huaweicloud_aom_dashboards

Use this data source to get the list of AOM dashboards.

## Example Usage

```hcl
data "huaweicloud_aom_dashboards" "test" {}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) Specifies the region in which to query the data source.
If omitted, the provider-level region will be used.

* `dashboard_type` - (Optional, String) Specifies the dashboard type.

* `enterprise_project_id` - (Optional, String) Specifies the enterprise project ID to which the dashboard belongs.

## Attribute Reference

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

* `id` - The data source ID.

* `dashboards` - Indicates the dashboards list.
The [dashboards](#attrblock--dashboards) structure is documented below.

<a name="attrblock--dashboards"></a>
The `dashboards` block supports:

* `id` - Indicates the dashboard ID.

* `dashboard_title` - Indicates the dashboard title.

* `dashboard_title_en` - Indicates the dashboard English title.

* `dashboard_type` - Indicates the dashboard type.

* `display` - Indicates whether the dashboard is displayed.

* `enterprise_project_id` - Indicates the enterprise project ID to which the dashboard belongs.

* `folder_id` - Indicates the folder ID to which the dashboard belongs.

* `folder_title` - Indicates the folder name to which the dashboard belongs.

* `dashboard_tags` - Indicates the dashboard tags.

* `is_favorite` - Indicates whether the dashboard is favorited.

* `version` - Indicates the dashboard version.

* `created_at` - Indicates the create time of the dashboard.

* `created_by` - Indicates the creator of the dashboard.

* `updated_at` - Indicates the update time of the dashboard.

* `updated_by` - Indicates the updator of the dashboard.
59 changes: 59 additions & 0 deletions docs/resources/aom_dashboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
subcategory: "Application Operations Management (AOM)"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_aom_dashboard"
description: |-
Manages an AOM dashboard resource within HuaweiCloud.
---

# huaweicloud_aom_dashboard

Manages an AOM dashboard resource within HuaweiCloud.

## Example Usage

```hcl
variable "dashboard_title " {}
variable "folder_title " {}
variable "dashboard_type " {}

resource "huaweicloud_aom_dashboard" "test" {
dashboard_title = var.dashboard_title
folder_title = var.folder_title
dashboard_type = var.dashboard_type
}
```

## Argument Reference

The following arguments are supported:

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

* `dashboard_title` - (Required, String) Specifies the dashboard title.

* `folder_title` - (Required, String) Specifies the folder title.

* `dashboard_type` - (Required, String) Specifies the dashboard type. It's customized by user.

* `is_favorite` - (Optional, Bool) Specifies whether to favorite the dashboard. Defaults to **false**.

* `dashboard_tags` - (Optional, List) Specifies the dashboard tags. It's an array of map.

* `enterprise_project_id` - (Optional, String, ForceNew) Specifies the enterprise project ID to which the dashboards
belongs. Defaults to **0**. Changing this parameter will create a new resource.

## Attribute Reference

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

* `id` - Indicates the resource ID.

## Import

The AOM dashboard resource can be imported using the `id`, e.g.

```bash
$ terraform import huaweicloud_aom_dashboard.test <id>
```
3 changes: 2 additions & 1 deletion docs/resources/aom_dashboards_folder.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ The following arguments are supported:

* `folder_title` - (Required, String) Specifies the dashboards folder title.

* `delete_all` - (Optional, Bool) Specifies whether to delete the dashboards when deleting folder.
* `delete_all` - (Optional, Bool) Specifies whether to delete the dashboards when deleting folder. Defaults to **false**.

* `enterprise_project_id` - (Optional, String, ForceNew) Specifies the enterprise project ID to which the folder belongs.
Defaults to **0**. Changing this parameter will create a new resource.

## Attribute Reference

Expand Down
2 changes: 2 additions & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ func Provider() *schema.Provider {
"huaweicloud_aom_organization_accounts": aom.DataSourceOrganizationAccounts(),
"huaweicloud_aom_dashboards_folders": aom.DataSourceDashboardsFolders(),
"huaweicloud_aom_alarm_rules": aom.DataSourceAlarmRules(),
"huaweicloud_aom_dashboards": aom.DataSourceDashboards(),

"huaweicloud_apig_acl_policies": apig.DataSourceAclPolicies(),
"huaweicloud_apig_api_associated_acl_policies": apig.DataSourceApiAssociatedAclPolicies(),
Expand Down Expand Up @@ -1113,6 +1114,7 @@ func Provider() *schema.Provider {
"huaweicloud_aom_multi_account_aggregation_rule": aom.ResourceMultiAccountAggregationRule(),
"huaweicloud_aom_dashboards_folder": aom.ResourceDashboardsFolder(),
"huaweicloud_aom_cloud_service_access": aom.ResourceCloudServiceAccess(),
"huaweicloud_aom_dashboard": aom.ResourceDashboard(),

"huaweicloud_rfs_stack": rfs.ResourceStack(),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestAccDataSourceDashboardsFolders_basic(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckEpsID(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package aom

import (
"fmt"
"testing"

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

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

func TestAccDataSourceDashboards_basic(t *testing.T) {
dataSource := "data.huaweicloud_aom_dashboards.test"
rName := acceptance.RandomAccResourceName()
dc := acceptance.InitDataSourceCheck(dataSource)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckEpsID(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataSourceDashboards_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestCheckResourceAttrSet(dataSource, "dashboards.#"),
resource.TestCheckResourceAttrSet(dataSource, "dashboards.0.id"),
resource.TestCheckResourceAttrSet(dataSource, "dashboards.0.dashboard_title"),
resource.TestCheckResourceAttrSet(dataSource, "dashboards.0.dashboard_type"),
resource.TestCheckResourceAttrSet(dataSource, "dashboards.0.enterprise_project_id"),
),
},
},
})
}

func testDataSourceDashboards_basic(name string) string {
return fmt.Sprintf(`
%s

data "huaweicloud_aom_dashboards" "test" {
depends_on = [huaweicloud_aom_dashboard.test]

enterprise_project_id = huaweicloud_aom_dashboard.test.enterprise_project_id
dashboard_type = huaweicloud_aom_dashboard.test.dashboard_type
}
`, testDashboard_basic(name, false))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package aom

import (
"fmt"
"strings"
"testing"

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

"github.com/chnsz/golangsdk"

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

func getDashboardResourceFunc(conf *config.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := conf.NewServiceClient("aom", acceptance.HW_REGION_NAME)
if err != nil {
return nil, fmt.Errorf("error creating AOM client: %s", err)
}

listHttpUrl := "v2/{project_id}/aom/dashboards"
listPath := client.Endpoint + listHttpUrl
listPath = strings.ReplaceAll(listPath, "{project_id}", client.ProjectID)
listOpt := golangsdk.RequestOpts{
KeepResponseBody: true,
MoreHeaders: buildHeaders(state),
}

listResp, err := client.Request("GET", listPath, &listOpt)
if err != nil {
return nil, fmt.Errorf("error retrieving dashboards: %s", err)
}
listRespBody, err := utils.FlattenResponse(listResp)
if err != nil {
return nil, fmt.Errorf("error flattening dashboards: %s", err)
}

jsonPath := fmt.Sprintf("dashboards[?dashboard_id=='%s']|[0]", state.Primary.ID)
dashboard := utils.PathSearch(jsonPath, listRespBody, nil)
if dashboard == nil {
return nil, golangsdk.ErrDefault404{}
}

return dashboard, nil
}

func TestAccDashboard_basic(t *testing.T) {
var obj interface{}
rName := acceptance.RandomAccResourceName()
newName := acceptance.RandomAccResourceName()
resourceName := "huaweicloud_aom_dashboard.test"

rc := acceptance.InitResourceCheck(
resourceName,
&obj,
getDashboardResourceFunc,
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckEpsID(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testDashboard_basic(rName, true),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "dashboard_title", rName),
resource.TestCheckResourceAttrPair(resourceName, "folder_title", "huaweicloud_aom_dashboards_folder.test", "folder_title"),
resource.TestCheckResourceAttr(resourceName, "dashboard_type", rName),
resource.TestCheckResourceAttr(resourceName, "is_favorite", "true"),
resource.TestCheckResourceAttrPair(resourceName, "enterprise_project_id",
"huaweicloud_aom_dashboards_folder.test", "enterprise_project_id"),
resource.TestCheckResourceAttr(resourceName, "dashboard_tags.0.key", rName),
),
},
{
Config: testDashboard_basic(newName, false),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "dashboard_title", newName),
resource.TestCheckResourceAttrPair(resourceName, "folder_title", "huaweicloud_aom_dashboards_folder.test", "folder_title"),
resource.TestCheckResourceAttr(resourceName, "dashboard_type", newName),
resource.TestCheckResourceAttr(resourceName, "is_favorite", "false"),
resource.TestCheckResourceAttrPair(resourceName, "enterprise_project_id",
"huaweicloud_aom_dashboards_folder.test", "enterprise_project_id"),
resource.TestCheckResourceAttr(resourceName, "dashboard_tags.0.key", newName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testDashboard_basic(name string, isFavorite bool) string {
return fmt.Sprintf(`
%[1]s

resource "huaweicloud_aom_dashboard" "test" {
depends_on = [huaweicloud_aom_dashboards_folder.test]

dashboard_title = "%[2]s"
folder_title = huaweicloud_aom_dashboards_folder.test.folder_title
dashboard_type = "%[2]s"
is_favorite = %[3]t
enterprise_project_id = huaweicloud_aom_dashboards_folder.test.enterprise_project_id
dashboard_tags = [
{
key = "%[2]s"
}
]
}`, testDashboardsFolder_basic(name, false), name, isFavorite)
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestAccDashboardsFolder_basic(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckEpsID(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Expand All @@ -71,7 +72,7 @@ func TestAccDashboardsFolder_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "folder_title", rName),
resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", "0"),
resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", acceptance.HW_ENTERPRISE_PROJECT_ID_TEST),
resource.TestCheckResourceAttr(resourceName, "delete_all", "true"),
resource.TestCheckResourceAttrSet(resourceName, "is_template"),
resource.TestCheckResourceAttrSet(resourceName, "created_by"),
Expand All @@ -82,7 +83,7 @@ func TestAccDashboardsFolder_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "folder_title", newName),
resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", "0"),
resource.TestCheckResourceAttr(resourceName, "enterprise_project_id", acceptance.HW_ENTERPRISE_PROJECT_ID_TEST),
resource.TestCheckResourceAttr(resourceName, "delete_all", "false"),
resource.TestCheckResourceAttrSet(resourceName, "is_template"),
resource.TestCheckResourceAttrSet(resourceName, "created_by"),
Expand All @@ -101,8 +102,8 @@ func TestAccDashboardsFolder_basic(t *testing.T) {
func testDashboardsFolder_basic(name string, deleteAll bool) string {
return fmt.Sprintf(`
resource "huaweicloud_aom_dashboards_folder" "test" {
folder_title = "%s"
enterprise_project_id = "0"
delete_all = %t
}`, name, deleteAll)
folder_title = "%[1]s"
enterprise_project_id = "%[2]s"
delete_all = %[3]t
}`, name, acceptance.HW_ENTERPRISE_PROJECT_ID_TEST, deleteAll)
}
Loading
Loading