Skip to content

Commit

Permalink
Add data source for Host Pool
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwilcox9 committed Feb 16, 2023
1 parent 3a43723 commit 61d4256
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/services/desktopvirtualization/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func (r Registration) WebsiteCategories() []string {

// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource {
return map[string]*pluginsdk.Resource{}
return map[string]*pluginsdk.Resource{
"azurerm_virtual_desktop_host_pool": dataSourceVirtualDesktopHostPool(),
}
}

// SupportedResources returns the supported Resources supported by this Service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
package desktopvirtualization

import (
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/desktopvirtualization/2022-02-10-preview/hostpool"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/internal/timeouts"
)

func dataSourceVirtualDesktopHostPool() *pluginsdk.Resource {
return &pluginsdk.Resource{
Read: dataSourceVirtualDesktopHostPoolRead,

Timeouts: &pluginsdk.ResourceTimeout{
Read: pluginsdk.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},

"location": commonschema.LocationComputed(),

"resource_group_name": commonschema.ResourceGroupNameForDataSource(),

"type": {
Type: pluginsdk.TypeString,
Computed: true,
},

"load_balancer_type": {
Type: pluginsdk.TypeString,
Computed: true,
},

"friendly_name": {
Type: pluginsdk.TypeString,
Computed: true,
},

"description": {
Type: pluginsdk.TypeString,
Computed: true,
},

"validate_environment": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"custom_rdp_properties": {
Type: pluginsdk.TypeString,
Computed: true,
},

"personal_desktop_assignment_type": {
Type: pluginsdk.TypeString,
Computed: true,
},

"maximum_sessions_allowed": {
Type: pluginsdk.TypeInt,
Computed: true,
},

"start_vm_on_connect": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"preferred_app_group_type": {
Type: pluginsdk.TypeString,
Computed: true,
},

"scheduled_agent_updates": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"timezone": {
Type: pluginsdk.TypeString,
Computed: true,
},

"use_session_host_timezone": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"schedule": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"day_of_week": {
Type: pluginsdk.TypeString,
Computed: true,
},

"hour_of_day": {
Type: pluginsdk.TypeInt,
Computed: true,
},
},
},
},
},
},
},

"tags": commonschema.TagsDataSource(),
},
}
}

func dataSourceVirtualDesktopHostPoolRead(d *pluginsdk.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DesktopVirtualization.HostPoolsClient
subscriptionId := meta.(*clients.Client).Account.SubscriptionId

ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

id := hostpool.NewHostPoolID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))

resp, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}

return fmt.Errorf("retrieving %s: %+v", id, err)
}

d.SetId(id.ID())
d.Set("name", id.HostPoolName)
d.Set("resource_group_name", id.ResourceGroupName)

if model := resp.Model; model != nil {
d.Set("location", location.NormalizeNilable(model.Location))
if err := tags.FlattenAndSet(d, model.Tags); err != nil {
return err
}

props := model.Properties
maxSessionLimit := 0
if props.MaxSessionLimit != nil {
maxSessionLimit = int(*props.MaxSessionLimit)
}

d.Set("custom_rdp_properties", props.CustomRdpProperty)
d.Set("description", props.Description)
d.Set("friendly_name", props.FriendlyName)
d.Set("maximum_sessions_allowed", maxSessionLimit)
d.Set("load_balancer_type", string(props.LoadBalancerType))
personalDesktopAssignmentType := ""
if props.PersonalDesktopAssignmentType != nil {
personalDesktopAssignmentType = string(*props.PersonalDesktopAssignmentType)
}
d.Set("personal_desktop_assignment_type", personalDesktopAssignmentType)
d.Set("preferred_app_group_type", string(props.PreferredAppGroupType))
d.Set("start_vm_on_connect", props.StartVMOnConnect)
d.Set("type", string(props.HostPoolType))
d.Set("validate_environment", props.ValidationEnvironment)
d.Set("scheduled_agent_updates", flattenAgentUpdate(props.AgentUpdate))
}

return nil
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package desktopvirtualization_test

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
)

type VirtualDesktopHostPoolDataSource struct{}

func TestAccDataShareAccountDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_virtual_desktop_host_pool", "test")
r := VirtualDesktopHostPoolDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("tags.%").HasValue("1"),
check.That(data.ResourceName).Key("friendly_name").HasValue("A Friendly Name!"),
check.That(data.ResourceName).Key("validate_environment").HasValue("true"),
check.That(data.ResourceName).Key("load_balancer_type").HasValue("BreadthFirst"),
check.That(data.ResourceName).Key("maximum_sessions_allowed").HasValue("100"),
),
},
})
}

func (VirtualDesktopHostPoolDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
data "azurerm_virtual_desktop_host_pool" "test" {
name = azurerm_virtual_desktop_host_pool.test.name
resource_group_name = azurerm_resource_group.test.name
}
`, VirtualDesktopHostPoolResource{}.complete(data))
}
86 changes: 86 additions & 0 deletions website/docs/d/virtual_desktop_host_pool.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
---
subcategory: "Desktop Virtualization"
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_virtual_desktop_host_pool"
description: |-
Gets information about an existing Virtual Desktop Host Pool.
---

# Data Source: azurerm_virtual_desktop_host_pool

Use this data source to access information about an existing Virtual Desktop Host Pool.

## Example Usage

```hcl
data "azurerm_virtual_desktop_host_pool" "example" {
name = "example-pool"
resource_group_name = "example-resources"
}
```

## Argument Reference

The following arguments are supported:

* `name` - (Required) The name of the Virtual Desktop Host Pool to retrieve.

* `resource_group_name` - (Required) The name of the resource group where the Virtual Desktop Host Pool exists.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

* `id` - The ID of the Virtual Desktop Host Pool.

* `location` - The location/region where the Virtual Desktop Host Pool is located.

* `type` - The type of the Virtual Desktop Host Pool.

* `load_balancer_type` - The type of load balancing performed by the Host Pool

* `friendly_name` - The friendly name for the Virtual Desktop Host Pool.

* `description` - The description for the Virtual Desktop Host Pool.

* `validate_environment` - Returns `true` if the Host Pool is in Validation mode.

* `start_vm_on_connect` - Returns `true` if the Start VM on Connection Feature is enabled.

* `custom_rdp_properties` - The custom RDP properties string for the Virtual Desktop Host Pool.

* `personal_desktop_assignment_type` - The type of personal desktop assignment in use by the Host Pool

* `maximum_sessions_allowed` - The maximum number of users that can have concurrent sessions on a session host.

* `preferred_app_group_type` - The preferred Application Group type for the Virtual Desktop Host Pool.

* `scheduled_agent_updates` - A `scheduled_agent_updates` block as defined below.

* `tags` - A mapping of tags to assign to the resource.

---

A `scheduled_agent_updates` block exports the following:

* `enabled` - Are scheduled updates of the AVD agent components (RDAgent, Geneva Monitoring agent, and side-by-side stack) enabled on session hosts.
* `timezone` - The time zone in which the agent update schedule will apply.
* `use_session_host_timezone` - Specifies whether scheduled agent updates should be applied based on the timezone of the affected session host.
* `schedule` - A `schedule` block as defined below.

---

A `schedule` block exports the following:

* `day_of_week` - The day of the week on which agent updates should be performed.
* `hour_of_day` - The hour of day the update window should start.

---


## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions:

* `read` - (Defaults to 5 minutes) Used when retrieving the Virtual Desktop Host Pool.

0 comments on commit 61d4256

Please sign in to comment.