Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions docs/data-sources/workspace_user_desktop_pool_associations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
subcategory: "Workspace"
layout: "huaweicloud"
page_title: "HuaweiCloud: huaweicloud_workspace_user_desktop_pool_associations"
description: |-
Use this data source to query the desktop pools associated with users within HuaweiCloud.
---

# huaweicloud_workspace_user_desktop_pool_associations

Use this data source to query the desktop pools associated with users within HuaweiCloud.

## Example Usage

```hcl
variable "user_ids" {
type = list(string)
}

data "huaweicloud_workspace_user_desktop_pool_associations" "test" {
user_ids = var.user_ids
}
```

## Argument Reference

The following arguments are supported:

* `region` - (Optional, String) Specifies the region where the user desktop pool associations are located.
If omitted, the provider-level region will be used.

* `user_ids` - (Required, List) Specifies the list of user IDs to be queried.

## Attribute Reference

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

* `id` - The data source ID.

* `associations` - The list of user associations with desktop pools.
The [associations](#workspace_user_desktop_pool_associations) structure is documented below.

<a name="workspace_user_desktop_pool_associations"></a>
The `associations` block supports:

* `user_id` - The ID of the user.

* `desktop_pools` - The list of desktop pools associated with the user.
The [desktop_pools](#workspace_user_desktop_pool_associations_desktop_pools) structure is documented below.

<a name="workspace_user_desktop_pool_associations_desktop_pools"></a>
The `desktop_pools` block supports:

* `id` - The ID of the desktop pool.

* `name` - The name of the desktop pool.

* `is_attached` - Whether a desktop is assigned.
1 change: 1 addition & 0 deletions huaweicloud/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -2278,6 +2278,7 @@ func Provider() *schema.Provider {
"huaweicloud_workspace_tenant_configurations": workspace.DataSourceTenantConfigurations(),
"huaweicloud_workspace_timezones": workspace.DataSourceTimeZones(),
"huaweicloud_workspace_users": workspace.DataSourceUsers(),
"huaweicloud_workspace_user_desktop_pool_associations": workspace.DataSourceUserDesktopPoolAssociations(),
"huaweicloud_workspace_user_groups": workspace.DataSourceUserGroups(),
"huaweicloud_workspace_volume_products": workspace.DataSourceVolumeProducts(),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
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 TestAccDataUserDesktopPoolAssociations_basic(t *testing.T) {
var (
name = acceptance.RandomAccResourceNameWithDash()

all = "data.huaweicloud_workspace_user_desktop_pool_associations.all"
dc = acceptance.InitDataSourceCheck(all)
)

resource.Test(t, resource.TestCase{
PreCheck: func() {
acceptance.TestAccPreCheck(t)
acceptance.TestAccPreCheckWorkspaceDesktopPoolImageId(t)
},
ProviderFactories: acceptance.TestAccProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataUserDesktopPoolAssociations_basic(name),
Check: resource.ComposeTestCheckFunc(
// Without any filter parameter.
dc.CheckResourceExists(),
resource.TestMatchResourceAttr(all, "associations.#", regexp.MustCompile(`^[0-9]+$`)),
resource.TestCheckResourceAttrSet(all, "associations.0.user_id"),
resource.TestMatchResourceAttr(all, "associations.0.desktop_pools.#", regexp.MustCompile(`^[0-9]+$`)),
resource.TestCheckResourceAttrSet(all, "associations.0.desktop_pools.0.id"),
resource.TestCheckResourceAttrSet(all, "associations.0.desktop_pools.0.name"),
resource.TestCheckResourceAttrSet(all, "associations.0.desktop_pools.0.is_attached"),
resource.TestCheckOutput("is_user_ids_filter_useful", "true"),
),
},
},
})
}

func testAccDataUserDesktopPoolAssociations_base(name string) string {
return fmt.Sprintf(`
data "huaweicloud_workspace_service" "test" {}

data "huaweicloud_workspace_flavors" "test" {
os_type = "Windows"
}

locals {
cpu_flavors = [for v in data.huaweicloud_workspace_flavors.test.flavors : v if v.is_gpu == false]
}

data "huaweicloud_availability_zones" "test" {}

resource "huaweicloud_workspace_user" "test" {
count = 2

name = "%[1]s${count.index}"
email = "www.user${count.index}@test.com"
}

resource "huaweicloud_workspace_desktop_pool" "test" {
count = 2
name = "%[1]s-${count.index}"
type = "DYNAMIC"
size = 1
product_id = try(local.cpu_flavors[0].id, "")
image_type = "gold"
image_id = "%[2]s"
subnet_ids = data.huaweicloud_workspace_service.test.network_ids
vpc_id = data.huaweicloud_workspace_service.test.vpc_id
availability_zone = data.huaweicloud_availability_zones.test.names[0]
disconnected_retention_period = 10
enable_autoscale = false

root_volume {
type = "SAS"
size = 80
}

security_groups {
id = data.huaweicloud_workspace_service.test.desktop_security_group[0].id
}

dynamic "authorized_objects" {
for_each = huaweicloud_workspace_user.test

content {
object_type = "USER"
object_id = authorized_objects.value.id
object_name = authorized_objects.value.name
user_group = "administrators"
}
}
}
`, name, acceptance.HW_WORKSPACE_DESKTOP_POOL_IMAGE_ID)
}

func testAccDataUserDesktopPoolAssociations_basic(name string) string {
return fmt.Sprintf(`
%[1]s

locals {
user_ids = huaweicloud_workspace_user.test[*].id
}

data "huaweicloud_workspace_user_desktop_pool_associations" "all" {
user_ids = local.user_ids

depends_on = [
huaweicloud_workspace_desktop_pool.test
]
}

locals {
query_result = [
for v in data.huaweicloud_workspace_user_desktop_pool_associations.all.associations[*].user_id :
contains(local.user_ids, v)
]
}

output "is_user_ids_filter_useful" {
value = length(local.query_result) > 0 && alltrue(local.query_result)
}
`, testAccDataUserDesktopPoolAssociations_base(name))
}
Loading
Loading