Skip to content

Commit

Permalink
feat(workspace/app): add data source to query authorizations (#5930)
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzhuanhong authored Dec 17, 2024
1 parent 39e78ac commit b4a4d1d
Show file tree
Hide file tree
Showing 5 changed files with 377 additions and 7 deletions.
73 changes: 73 additions & 0 deletions docs/data-sources/workspace_app_group_authorizations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
---
subcategory: "Workspace"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_workspace_app_group_authorizations"
description: |-
Use this data source to get the list of the application group authorizations within HuaweiCloud.
---

# huaweicloud_workspace_app_group_authorizations

Use this data source to get the list of the application group authorizations within HuaweiCloud.

## Example Usage

### Query all application group authorizations

```hcl
data "huaweicloud_workspace_app_group_authorizations" "test" {}
```

### Query the application group authorizations that contains the same name segment and the account type is USER

```hcl
variable "account_name_prefix" {}
data "huaweicloud_workspace_app_group_authorizations" "test" {
account = var.account_name_prefix
account_type = "USER"
}
```

## Argument Reference

The following arguments are supported:

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

* `app_group_id` - (Optional, String) Specifies the authorized application group ID.

* `account` - (Optional, String) Specifies the name of the authorized account. Fuzzy search is supported.

* `account_type` - (Optional, String) Specifies the type of the authorized account.
The valid values are as follows:
+ **USER**
+ **USER_GROUP**

## Attribute Reference

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

* `id` - The data source ID.

* `authorizations` - All authorizations that match the filter parameters.

The [authorizations](#app_group_authorizations) structure is documented below.

<a name="app_group_authorizations"></a>
The `authorizations` block supports:

* `id` - The authorized ID.

* `account_id` - The ID of the authorized account.

* `account` - The name of the authorized account.

* `account_type` - The type of the authorized account.

* `app_group_id` - The application group ID corresponding to the authorized account.

* `app_group_name` - The application group name corresponding to the authorized account.

* `created_at` - The time when the account is authorized to the specified application group, in RFC3339 format.
13 changes: 7 additions & 6 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -1187,12 +1187,13 @@ func Provider() *schema.Provider {
"huaweicloud_dws_workload_queue_associated_users": dws.DataSourceDwsWorkloadQueueAssociatedUsers(),
"huaweicloud_dws_workload_queues": dws.DataSourceWorkloadQueues(),

"huaweicloud_workspace_app_groups": workspace.DataSourceWorkspaceAppGroups(),
"huaweicloud_workspace_app_nas_storages": workspace.DataSourceAppNasStorages(),
"huaweicloud_workspace_app_publishable_apps": workspace.DataSourceWorkspaceAppPublishableApps(),
"huaweicloud_workspace_app_storage_policies": workspace.DataSourceAppStoragePolicies(),
"huaweicloud_workspace_desktops": workspace.DataSourceDesktops(),
"huaweicloud_workspace_flavors": workspace.DataSourceWorkspaceFlavors(),
"huaweicloud_workspace_app_group_authorizations": workspace.DataSourceWorkspaceAppGroupAuthorizations(),
"huaweicloud_workspace_app_groups": workspace.DataSourceWorkspaceAppGroups(),
"huaweicloud_workspace_app_nas_storages": workspace.DataSourceAppNasStorages(),
"huaweicloud_workspace_app_publishable_apps": workspace.DataSourceWorkspaceAppPublishableApps(),
"huaweicloud_workspace_app_storage_policies": workspace.DataSourceAppStoragePolicies(),
"huaweicloud_workspace_desktops": workspace.DataSourceDesktops(),
"huaweicloud_workspace_flavors": workspace.DataSourceWorkspaceFlavors(),

// Legacy
"huaweicloud_images_image_v2": ims.DataSourceImagesImageV2(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package workspace

import (
"fmt"
"regexp"
"testing"

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

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

func TestAccDataSourceAppGroupAuthorizations_basic(t *testing.T) {
var (
rName = acceptance.RandomAccResourceName()
dataSource = "data.huaweicloud_workspace_app_group_authorizations.test"
dc = acceptance.InitDataSourceCheck(dataSource)

byAppGroupId = "data.huaweicloud_workspace_app_group_authorizations.filter_by_app_group_id"
dcByAppGroupId = acceptance.InitDataSourceCheck(byAppGroupId)

byAccount = "data.huaweicloud_workspace_app_group_authorizations.filter_by_account"
dcByAccount = acceptance.InitDataSourceCheck(byAccount)

byAccountType = "data.huaweicloud_workspace_app_group_authorizations.filter_by_account_type"
dcByAccountType = acceptance.InitDataSourceCheck(byAccountType)
)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckWorkspaceAppServerGroup(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testDataSourceAppGroupAuthorizations_basic(rName),
Check: resource.ComposeTestCheckFunc(
dc.CheckResourceExists(),
resource.TestMatchResourceAttr(dataSource, "authorizations.#", regexp.MustCompile(`^[1-9]([0-9]*)?$`)),
dcByAppGroupId.CheckResourceExists(),
resource.TestCheckOutput("is_app_group_id_filter_useful", "true"),
resource.TestCheckResourceAttrSet(byAppGroupId, "authorizations.0.id"),
resource.TestCheckResourceAttrSet(byAppGroupId, "authorizations.0.account_id"),
resource.TestCheckResourceAttrSet(byAppGroupId, "authorizations.0.app_group_id"),
resource.TestCheckResourceAttrSet(byAppGroupId, "authorizations.0.app_group_name"),
resource.TestMatchResourceAttr(byAppGroupId, "authorizations.0.created_at",
regexp.MustCompile(`^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}?(Z|([+-]\d{2}:\d{2}))$`)),
dcByAccount.CheckResourceExists(),
resource.TestCheckOutput("is_account_filter_useful", "true"),
dcByAccountType.CheckResourceExists(),
resource.TestCheckOutput("is_account_type_filter_useful", "true"),
),
},
},
})
}

func testDataSourceAppGroupAuthorizations_basic(name string) string {
return fmt.Sprintf(`
%[1]s
data "huaweicloud_workspace_app_group_authorizations" "test" {
depends_on = [huaweicloud_workspace_app_group_authorization.test]
}
locals {
app_group_id = huaweicloud_workspace_app_group.test.id
authorized_account = huaweicloud_workspace_app_group_authorization.test.accounts[0].account
authorized_account_type = huaweicloud_workspace_app_group_authorization.test.accounts[0].type
}
data "huaweicloud_workspace_app_group_authorizations" "filter_by_app_group_id" {
depends_on = [huaweicloud_workspace_app_group_authorization.test]
app_group_id = local.app_group_id
}
locals {
app_group_id_filter_result = [
for v in data.huaweicloud_workspace_app_group_authorizations.filter_by_app_group_id.authorizations[*].app_group_id : v == local.app_group_id
]
}
output "is_app_group_id_filter_useful" {
value = length(local.app_group_id_filter_result) > 0 && alltrue(local.app_group_id_filter_result)
}
# Fuzzy search is supported.
data "huaweicloud_workspace_app_group_authorizations" "filter_by_account" {
depends_on = [huaweicloud_workspace_app_group_authorization.test]
account = local.authorized_account
}
locals {
account_filter_result = [
for v in data.huaweicloud_workspace_app_group_authorizations.filter_by_account.authorizations[*].account :
strcontains(v, local.authorized_account)
]
}
output "is_account_filter_useful" {
value = length(local.account_filter_result) > 0 && alltrue(local.account_filter_result)
}
data "huaweicloud_workspace_app_group_authorizations" "filter_by_account_type" {
depends_on = [huaweicloud_workspace_app_group_authorization.test]
account_type = local.authorized_account_type
}
locals {
account_type_filter_result = [
for v in data.huaweicloud_workspace_app_group_authorizations.filter_by_account_type.authorizations[*].account_type :
v == local.authorized_account_type
]
}
output "is_account_type_filter_useful" {
value = length(local.account_type_filter_result) > 0 && alltrue(local.account_type_filter_result)
}
`, testAccAppGroupAuthorization_basic(name))
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccResourceAppGroupAuthorization_basic(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckWorkspaceAppServerGroupId(t)
acceptance.TestAccPreCheckWorkspaceAppServerGroup(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
CheckDestroy: nil,
Expand Down
Loading

0 comments on commit b4a4d1d

Please sign in to comment.