Skip to content

Commit

Permalink
azurerm_virtual_desktop_host_pool - support for `public_network_acc…
Browse files Browse the repository at this point in the history
…ess` (#25611)

* added `public_network_access_enabled` attribute, tests and docs

* support for other network access types

* format and updated docs

* fix incompatable type as per failing linter
  • Loading branch information
ASHR4 authored Apr 22, 2024
1 parent ce4cc57 commit f8cb26b
Showing 3 changed files with 159 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import (
"log"
"time"

"github.com/hashicorp/go-azure-helpers/lang/pointer"
"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
@@ -114,6 +115,13 @@ func resourceVirtualDesktopHostPool() *pluginsdk.Resource {
}, false),
},

"public_network_access": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(hostpool.PossibleValuesForHostpoolPublicNetworkAccess(), false),
Default: string(hostpool.HostpoolPublicNetworkAccessEnabled),
},

"maximum_sessions_allowed": {
Type: pluginsdk.TypeInt,
Optional: true,
@@ -250,6 +258,7 @@ func resourceVirtualDesktopHostPoolCreate(d *pluginsdk.ResourceData, meta interf
LoadBalancerType: hostpool.LoadBalancerType(d.Get("load_balancer_type").(string)),
PersonalDesktopAssignmentType: &personalDesktopAssignmentType,
PreferredAppGroupType: hostpool.PreferredAppGroupType(d.Get("preferred_app_group_type").(string)),
PublicNetworkAccess: pointer.To(hostpool.HostpoolPublicNetworkAccess(d.Get("public_network_access").(string))),
AgentUpdate: expandAgentUpdateCreate(d.Get("scheduled_agent_updates").([]interface{})),
VMTemplate: &vmTemplate,
},
@@ -282,7 +291,7 @@ func resourceVirtualDesktopHostPoolUpdate(d *pluginsdk.ResourceData, meta interf
payload.Tags = tags.Expand(d.Get("tags").(map[string]interface{}))
}

if d.HasChanges("custom_rdp_properties", "description", "friendly_name", "load_balancer_type", "maximum_sessions_allowed", "preferred_app_group_type", "start_vm_on_connect", "validate_environment", "scheduled_agent_updates") {
if d.HasChanges("custom_rdp_properties", "description", "friendly_name", "load_balancer_type", "maximum_sessions_allowed", "preferred_app_group_type", "public_network_access", "start_vm_on_connect", "validate_environment", "scheduled_agent_updates") {
payload.Properties = &hostpool.HostPoolPatchProperties{}

if d.HasChange("custom_rdp_properties") {
@@ -311,6 +320,10 @@ func resourceVirtualDesktopHostPoolUpdate(d *pluginsdk.ResourceData, meta interf
payload.Properties.PreferredAppGroupType = &preferredAppGroupType
}

if d.HasChange("public_network_access") {
payload.Properties.PublicNetworkAccess = pointer.To(hostpool.HostpoolPublicNetworkAccess(d.Get("public_network_access").(string)))
}

if d.HasChange("start_vm_on_connect") {
payload.Properties.StartVMOnConnect = utils.Bool(d.Get("start_vm_on_connect").(bool))
}
@@ -382,6 +395,7 @@ func resourceVirtualDesktopHostPoolRead(d *pluginsdk.ResourceData, meta interfac
}
d.Set("personal_desktop_assignment_type", personalDesktopAssignmentType)
d.Set("preferred_app_group_type", string(props.PreferredAppGroupType))
d.Set("public_network_access", string(pointer.From(props.PublicNetworkAccess)))
d.Set("start_vm_on_connect", props.StartVMOnConnect)
d.Set("type", string(props.HostPoolType))
d.Set("validate_environment", props.ValidationEnvironment)
Original file line number Diff line number Diff line change
@@ -128,6 +128,49 @@ func TestAccVirtualDesktopHostPool_update(t *testing.T) {
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.complete(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("public_network_access").HasValue("Enabled"),
),
},
{
Config: r.publicNetworkAccessDisabledUpdate(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("public_network_access").HasValue("Disabled"),
),
},
{
Config: r.publicNetworkAccessClientOnlyUpdate(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("public_network_access").HasValue("EnabledForClientsOnly"),
),
},
{
Config: r.publicNetworkAccessSessionHostOnlyUpdate(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("public_network_access").HasValue("EnabledForSessionHostsOnly"),
),
},
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("public_network_access").HasValue("Enabled"),
),
},
})
}

func TestAccVirtualDesktopHostPool_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_virtual_desktop_host_pool", "test")
r := VirtualDesktopHostPoolResource{}
@@ -340,6 +383,105 @@ resource "azurerm_virtual_desktop_host_pool" "test" {
`, data.RandomInteger, data.Locations.Secondary, data.RandomString)
}

func (VirtualDesktopHostPoolResource) publicNetworkAccessClientOnlyUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-vdesktophp-%d"
location = "%s"
}
resource "azurerm_virtual_desktop_host_pool" "test" {
name = "acctestHP%s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
type = "Pooled"
friendly_name = "A Friendly Name!"
description = "A Description!"
validate_environment = true
start_vm_on_connect = true
load_balancer_type = "BreadthFirst"
maximum_sessions_allowed = 100
preferred_app_group_type = "Desktop"
custom_rdp_properties = "audiocapturemode:i:1;audiomode:i:0;"
public_network_access = "EnabledForClientsOnly"
tags = {
Purpose = "Acceptance-Testing"
}
}
`, data.RandomInteger, data.Locations.Secondary, data.RandomString)
}

func (VirtualDesktopHostPoolResource) publicNetworkAccessSessionHostOnlyUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-vdesktophp-%d"
location = "%s"
}
resource "azurerm_virtual_desktop_host_pool" "test" {
name = "acctestHP%s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
type = "Pooled"
friendly_name = "A Friendly Name!"
description = "A Description!"
validate_environment = true
start_vm_on_connect = true
load_balancer_type = "BreadthFirst"
maximum_sessions_allowed = 100
preferred_app_group_type = "Desktop"
custom_rdp_properties = "audiocapturemode:i:1;audiomode:i:0;"
public_network_access = "EnabledForSessionHostsOnly"
tags = {
Purpose = "Acceptance-Testing"
}
}
`, data.RandomInteger, data.Locations.Secondary, data.RandomString)
}

func (VirtualDesktopHostPoolResource) publicNetworkAccessDisabledUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-vdesktophp-%d"
location = "%s"
}
resource "azurerm_virtual_desktop_host_pool" "test" {
name = "acctestHP%s"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
type = "Pooled"
friendly_name = "A Friendly Name!"
description = "A Description!"
validate_environment = true
start_vm_on_connect = true
load_balancer_type = "BreadthFirst"
maximum_sessions_allowed = 100
preferred_app_group_type = "Desktop"
custom_rdp_properties = "audiocapturemode:i:1;audiomode:i:0;"
public_network_access = "Disabled"
tags = {
Purpose = "Acceptance-Testing"
}
}
`, data.RandomInteger, data.Locations.Secondary, data.RandomString)
}

func (r VirtualDesktopHostPoolResource) requiresImport(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
2 changes: 2 additions & 0 deletions website/docs/r/virtual_desktop_host_pool.html.markdown
Original file line number Diff line number Diff line change
@@ -72,6 +72,8 @@ The following arguments are supported:

~> **NOTE:** `personal_desktop_assignment_type` is required if the `type` of your Virtual Desktop Host Pool is `Personal`

* `public_network_access` - (Optional) Whether public network access is allowed for the Virtual Desktop Host Pool. Possible values are `Enabled`, `Disabled`, `EnabledForClientsOnly` and `EnabledForSessionHostsOnly`. Defaults to `Enabled`.

* `maximum_sessions_allowed` - (Optional) A valid integer value from 0 to 999999 for the maximum number of users that have concurrent sessions on a session host.
Should only be set if the `type` of your Virtual Desktop Host Pool is `Pooled`.

0 comments on commit f8cb26b

Please sign in to comment.