-
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(workspace/app_group): add application group resource (#5747)
- Loading branch information
1 parent
1190268
commit 843581c
Showing
6 changed files
with
429 additions
and
0 deletions.
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,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> | ||
``` |
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
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
111 changes: 111 additions & 0 deletions
111
huaweicloud/services/acceptance/workspace/resource_huaweicloud_workspace_app_group_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,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) | ||
} |
Oops, something went wrong.