Skip to content

Commit

Permalink
feat(aom): support dashboard management
Browse files Browse the repository at this point in the history
  • Loading branch information
saf3dfsa committed Aug 14, 2024
1 parent 564646b commit f94eba6
Show file tree
Hide file tree
Showing 8 changed files with 800 additions and 1 deletion.
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.
58 changes: 58 additions & 0 deletions docs/resources/aom_dashboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
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 dashboard belongs.

## 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>
```
2 changes: 1 addition & 1 deletion docs/resources/aom_dashboards_folder.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ 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.

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

"huaweicloud_apig_acl_policies": apig.DataSourceAclPolicies(),
"huaweicloud_apig_api_associated_acl_policies": apig.DataSourceApiAssociatedAclPolicies(),
Expand Down Expand Up @@ -1093,6 +1094,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
@@ -0,0 +1,49 @@
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)
},
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,124 @@
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: map[string]string{
"Content-Type": "application/json",
},
}

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)
},
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)
}
Loading

0 comments on commit f94eba6

Please sign in to comment.