-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(aom): support dashboard management
- Loading branch information
Showing
8 changed files
with
800 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
huaweicloud/services/acceptance/aom/data_source_huaweicloud_aom_dashboards_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} |
124 changes: 124 additions & 0 deletions
124
huaweicloud/services/acceptance/aom/resource_huaweicloud_aom_dashboard_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
Oops, something went wrong.