Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_virtual_desktop_host_pool - support for public_network_access #25611

Merged
merged 4 commits into from
Apr 22, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down Expand Up @@ -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
Expand Down
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
Expand Up @@ -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`.

Expand Down
Loading