Skip to content

Commit

Permalink
feat(workspace/app_group): add application group resource (#5747)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzhuanhong authored Oct 29, 2024
1 parent 1190268 commit 843581c
Show file tree
Hide file tree
Showing 6 changed files with 429 additions and 0 deletions.
58 changes: 58 additions & 0 deletions docs/resources/workspace_app_group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
subcategory: "Workspace"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_workspace_app_group"
description: |-
Manages a Workspace APP group resource within HuaweiCloud.
---

# huaweicloud_workspace_app_group

Manages a Workspace APP group resource within HuaweiCloud.

## Example Usage

```hcl
variable "app_group_name" {}
resource "huaweicloud_workspace_app_group" "test" {
name = var.app_group_name
}
```

## 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 will create new resource.

* `name` - (Required, String) Specifies the name of the application group.
The valid length is limited from `1` to `64`, only Chinese and English characters, digits, underscores (_) and
hyphens (-) are allowed.

* `type` - (Optional, String, ForceNew) Specifies the type of the application group.
If omitted, the defult value is **COMMON_APP**.
The valid values are as follows:
+ **COMMON_APP**
+ **SESSION_DESKTOP_APP**

* `server_group_id` - (Optional, String) Specifies the server group ID associated with the application group.

* `description` - (Optional, String) Specifies the description of the application group.

## Attribute Reference

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

* `id` - The resource ID.

* `created_at` - The creation time of the application group, in RFC3339 format.

## Import

The Workspace APP group resource can be imported using the `id`, e.g.

```bash
$ terraform import huaweicloud_workspace_app_group.test <id>
```
5 changes: 5 additions & 0 deletions huaweicloud/config/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ var allServiceCatalog = map[string]ServiceCatalog{
Version: "v2",
Product: "Workspace",
},
"appstream": {
Name: "appstream",
Version: "v1",
Product: "Workspace",
},
"er": {
Name: "er",
Version: "v3",
Expand Down
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,7 @@ func Provider() *schema.Provider {
"huaweicloud_waf_instance_group_associate": waf.ResourceWafInstGroupAssociate(),
"huaweicloud_waf_reference_table": waf.ResourceWafReferenceTableV1(),

"huaweicloud_workspace_app_group": workspace.ResourceWorkspaceAppGroup(),
"huaweicloud_workspace_user_group": workspace.ResourceUserGroup(),
"huaweicloud_workspace_access_policy": workspace.ResourceAccessPolicy(),
"huaweicloud_workspace_desktop_name_rule": workspace.ResourceDesktopNameRule(),
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 @@ -196,6 +196,7 @@ var (
HW_WORKSPACE_AD_NETWORK_ID = os.Getenv("HW_WORKSPACE_AD_NETWORK_ID") // The network ID to which the AD server belongs.
// The internet access port to which the Workspace service.
HW_WORKSPACE_INTERNET_ACCESS_PORT = os.Getenv("HW_WORKSPACE_INTERNET_ACCESS_PORT")
HW_WORKSPACE_APP_SERVER_GROUP_ID = os.Getenv("HW_WORKSPACE_APP_SERVER_GROUP_ID")

HW_FGS_AGENCY_NAME = os.Getenv("HW_FGS_AGENCY_NAME")
HW_FGS_TEMPLATE_ID = os.Getenv("HW_FGS_TEMPLATE_ID")
Expand Down Expand Up @@ -1423,6 +1424,13 @@ func TestAccPreCheckWorkspaceInternetAccessPort(t *testing.T) {
}
}

// lintignore:AT003
func TestAccPreCheckWorkspaceAppServerGroupId(t *testing.T) {
if HW_WORKSPACE_APP_SERVER_GROUP_ID == "" {
t.Skip("HW_WORKSPACE_APP_SERVER_GROUP_ID must be set for Workspace service acceptance tests.")
}
}

// lintignore:AT003
func TestAccPreCheckER(t *testing.T) {
if HW_ER_TEST_ON == "" {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
package workspace

import (
"fmt"
"regexp"
"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/helper/httphelper"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance"
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils"
)

func getResourceWorkspaceAppGroupFunc(cfg *config.Config, state *terraform.ResourceState) (interface{}, error) {
client, err := cfg.NewServiceClient("appstream", acceptance.HW_REGION_NAME)
if err != nil {
return nil, fmt.Errorf("error creating Workspace APP client: %s", err)
}

uri := "/v1/{project_id}/app-groups"
queryParam := map[string]any{
"app_group_id": state.Primary.ID,
}
resp, err := httphelper.New(client).
Method("GET").
URI(uri).
Query(queryParam).
Request().
Data()

groups := utils.PathSearch("items", resp, make([]interface{}, 0))
if len(groups.([]interface{})) == 0 {
return nil, golangsdk.ErrDefault404{}
}

return resp, err
}

func TestAccResourceWorkspaceAppGroup_basic(t *testing.T) {
var (
resourceName = "huaweicloud_workspace_app_group.test"
name = acceptance.RandomAccResourceName()
updateName = acceptance.RandomAccResourceName()

appGroup interface{}
rc = acceptance.InitResourceCheck(
resourceName,
&appGroup,
getResourceWorkspaceAppGroupFunc,
)
)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckWorkspaceAppServerGroupId(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: rc.CheckResourceDestroy(),
Steps: []resource.TestStep{
{
Config: testResourceWorkspaceAppGroup_basic_step1(name),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "name", name),
resource.TestCheckResourceAttr(resourceName, "type", "COMMON_APP"),
resource.TestCheckResourceAttr(resourceName, "server_group_id", acceptance.HW_WORKSPACE_APP_SERVER_GROUP_ID),
resource.TestCheckResourceAttr(resourceName, "description", "Created APP group by script"),
resource.TestMatchResourceAttr(resourceName, "created_at",
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)),
),
},
{
Config: testResourceWorkspaceAppGroup_basic_step2(updateName),
Check: resource.ComposeTestCheckFunc(
rc.CheckResourceExists(),
resource.TestCheckResourceAttr(resourceName, "name", updateName),
resource.TestCheckResourceAttr(resourceName, "server_group_id", ""),
resource.TestCheckResourceAttr(resourceName, "description", ""),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testResourceWorkspaceAppGroup_basic_step1(name string) string {
return fmt.Sprintf(`
resource "huaweicloud_workspace_app_group" "test" {
name = "%[1]s"
server_group_id = "%[2]s"
description = "Created APP group by script"
}
`, name, acceptance.HW_WORKSPACE_APP_SERVER_GROUP_ID)
}

func testResourceWorkspaceAppGroup_basic_step2(updateName string) string {
return fmt.Sprintf(`
resource "huaweicloud_workspace_app_group" "test" {
name = "%[1]s"
}
`, updateName)
}
Loading

0 comments on commit 843581c

Please sign in to comment.