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

#24358: Support vm_template for azurerm_virtual_desktop_host_pool resource #24369

Merged
merged 4 commits into from
Feb 16, 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 @@ -196,6 +196,13 @@ func resourceVirtualDesktopHostPool() *pluginsdk.Resource {
},
},

"vm_template": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: validation.StringIsJSON,
DiffSuppressFunc: pluginsdk.SuppressJsonDiff,
},

"tags": commonschema.Tags(),
},
}
Expand All @@ -220,6 +227,15 @@ func resourceVirtualDesktopHostPoolCreate(d *pluginsdk.ResourceData, meta interf
}

personalDesktopAssignmentType := hostpool.PersonalDesktopAssignmentType(d.Get("personal_desktop_assignment_type").(string))
vmTemplate := d.Get("vm_template").(string)
if vmTemplate != "" {
// we have no use with the json object as azure accepts string only
// merely here for validation
_, err := pluginsdk.ExpandJsonFromString(vmTemplate)
if err != nil {
return fmt.Errorf("expanding JSON for `vm_template`: %+v", err)
}
}
payload := hostpool.HostPool{
Location: utils.String(location.Normalize(d.Get("location").(string))),
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
Expand All @@ -235,6 +251,7 @@ func resourceVirtualDesktopHostPoolCreate(d *pluginsdk.ResourceData, meta interf
PersonalDesktopAssignmentType: &personalDesktopAssignmentType,
PreferredAppGroupType: hostpool.PreferredAppGroupType(d.Get("preferred_app_group_type").(string)),
AgentUpdate: expandAgentUpdateCreate(d.Get("scheduled_agent_updates").([]interface{})),
VMTemplate: &vmTemplate,
},
}

Expand Down Expand Up @@ -305,6 +322,10 @@ func resourceVirtualDesktopHostPoolUpdate(d *pluginsdk.ResourceData, meta interf
if d.HasChanges("scheduled_agent_updates") {
payload.Properties.AgentUpdate = expandAgentUpdatePatch(d.Get("scheduled_agent_updates").([]interface{}))
}

if d.HasChanges("vm_template") {
payload.Properties.VMTemplate = utils.String(d.Get("vm_template").(string))
}
}

if _, err := client.Update(ctx, *id, payload); err != nil {
Expand Down Expand Up @@ -365,6 +386,7 @@ func resourceVirtualDesktopHostPoolRead(d *pluginsdk.ResourceData, meta interfac
d.Set("type", string(props.HostPoolType))
d.Set("validate_environment", props.ValidationEnvironment)
d.Set("scheduled_agent_updates", flattenAgentUpdate(props.AgentUpdate))
d.Set("vm_template", props.VMTemplate)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ func TestAccVirtualDesktopHostPool_basic(t *testing.T) {
})
}

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

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.vmTemplate(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("vm_template").IsNotEmpty(),
),
},
})
}

func TestAccVirtualDesktopHostPool_agentupdates(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_virtual_desktop_host_pool", "test")
r := VirtualDesktopHostPoolResource{}
Expand Down Expand Up @@ -253,6 +268,46 @@ resource "azurerm_virtual_desktop_host_pool" "test" {
`, data.RandomInteger, data.Locations.Secondary, data.RandomString)
}

func (VirtualDesktopHostPoolResource) vmTemplate(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"
validate_environment = true
load_balancer_type = "DepthFirst"
vm_template = <<EOF
{
"imageType": "Gallery",
"galleryImageReference": {
"offer": "WindowsServer",
"publisher": "MicrosoftWindowsServer",
"sku": "2019-Datacenter",
"version": "latest"
},
"osDiskType": "Premium_LRS",
"customRdpProperty": {
"audioRedirectionMode": "dynamic",
"redirectClipboard": true,
"redirectDrives": true
}
}
EOF
}
`, data.RandomInteger, data.Locations.Secondary, data.RandomString)
}

func (VirtualDesktopHostPoolResource) complete(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
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 @@ -79,6 +79,8 @@ The following arguments are supported:

* `scheduled_agent_updates` - (Optional) A `scheduled_agent_updates` block as defined below. This enables control of when Agent Updates will be applied to Session Hosts.

* `vm_template` - (Optional) A VM template for session hosts configuration within hostpool. This is a JSON string.

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

---
Expand Down
Loading