Skip to content

azurermVirtualDesktopScalingPlan

Manages a Virtual Desktop Scaling Plan.

Disclaimers

-> Note Scaling Plans are currently in preview and are only supported in a limited number of regions. Both the Scaling Plan and any referenced Host Pools must be deployed in a supported region. Autoscale (preview) for Azure Virtual Desktop host pools.

-> Note Scaling Plans require specific permissions to be granted to the Windows Virtual Desktop application before a 'host_pool' can be configured. Required Permissions for Scaling Plans.

Example Usage

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as azurerm from "./.gen/providers/azurerm";
import * as random from "./.gen/providers/random";
import * as azuread from "./.gen/providers/azuread";
/*The following providers are missing schema information and might need manual adjustments to synthesize correctly: azurerm, random, azuread.
For a more precise conversion please use the --provider flag in convert.*/
const azurermResourceGroupExample = new azurerm.resourceGroup.ResourceGroup(
  this,
  "example",
  {
    location: "West Europe",
    name: "example-resources",
  }
);
const azurermRoleDefinitionExample = new azurerm.roleDefinition.RoleDefinition(
  this,
  "example_1",
  {
    assignable_scopes: [azurermResourceGroupExample.id],
    description: "AVD AutoScale Role",
    name: "AVD-AutoScale",
    permissions: [
      {
        actions: [
          "Microsoft.Insights/eventtypes/values/read",
          "Microsoft.Compute/virtualMachines/deallocate/action",
          "Microsoft.Compute/virtualMachines/restart/action",
          "Microsoft.Compute/virtualMachines/powerOff/action",
          "Microsoft.Compute/virtualMachines/start/action",
          "Microsoft.Compute/virtualMachines/read",
          "Microsoft.DesktopVirtualization/hostpools/read",
          "Microsoft.DesktopVirtualization/hostpools/write",
          "Microsoft.DesktopVirtualization/hostpools/sessionhosts/read",
          "Microsoft.DesktopVirtualization/hostpools/sessionhosts/write",
          "Microsoft.DesktopVirtualization/hostpools/sessionhosts/usersessions/delete",
          "Microsoft.DesktopVirtualization/hostpools/sessionhosts/usersessions/read",
          "Microsoft.DesktopVirtualization/hostpools/sessionhosts/usersessions/sendMessage/action",
          "Microsoft.DesktopVirtualization/hostpools/sessionhosts/usersessions/read",
        ],
        not_actions: [],
      },
    ],
    scope: azurermResourceGroupExample.id,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermRoleDefinitionExample.overrideLogicalId("example");
const azurermVirtualDesktopHostPoolExample =
  new azurerm.virtualDesktopHostPool.VirtualDesktopHostPool(this, "example_2", {
    load_balancer_type: "BreadthFirst",
    location: azurermResourceGroupExample.location,
    name: "example-hostpool",
    resource_group_name: azurermResourceGroupExample.name,
    type: "Pooled",
    validate_environment: true,
  });
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermVirtualDesktopHostPoolExample.overrideLogicalId("example");
const azurermVirtualDesktopScalingPlanExample =
  new azurerm.virtualDesktopScalingPlan.VirtualDesktopScalingPlan(
    this,
    "example_3",
    {
      description: "Example Scaling Plan",
      friendly_name: "Scaling Plan Example",
      host_pool: [
        {
          hostpool_id: azurermVirtualDesktopHostPoolExample.id,
          scaling_plan_enabled: true,
        },
      ],
      location: azurermResourceGroupExample.location,
      name: "example-scaling-plan",
      resource_group_name: azurermResourceGroupExample.name,
      schedule: [
        {
          days_of_week: [
            "Monday",
            "Tuesday",
            "Wednesday",
            "Thursday",
            "Friday",
          ],
          name: "Weekdays",
          off_peak_load_balancing_algorithm: "DepthFirst",
          off_peak_start_time: "22:00",
          peak_load_balancing_algorithm: "BreadthFirst",
          peak_start_time: "09:00",
          ramp_down_capacity_threshold_percent: 5,
          ramp_down_force_logoff_users: false,
          ramp_down_load_balancing_algorithm: "DepthFirst",
          ramp_down_minimum_hosts_percent: 10,
          ramp_down_notification_message:
            "Please log off in the next 45 minutes...",
          ramp_down_start_time: "19:00",
          ramp_down_stop_hosts_when: "ZeroSessions",
          ramp_down_wait_time_minutes: 45,
          ramp_up_capacity_threshold_percent: 10,
          ramp_up_load_balancing_algorithm: "BreadthFirst",
          ramp_up_minimum_hosts_percent: 20,
          ramp_up_start_time: "05:00",
        },
      ],
      time_zone: "GMT Standard Time",
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermVirtualDesktopScalingPlanExample.overrideLogicalId("example");
const randomUuidExample = new random.uuid.Uuid(this, "example_4", {});
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
randomUuidExample.overrideLogicalId("example");
const dataAzureadServicePrincipalExample =
  new azuread.dataAzureadServicePrincipal.DataAzureadServicePrincipal(
    this,
    "example_5",
    {
      display_name: "Windows Virtual Desktop",
    }
  );
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
dataAzureadServicePrincipalExample.overrideLogicalId("example");
const azurermRoleAssignmentExample = new azurerm.roleAssignment.RoleAssignment(
  this,
  "example_6",
  {
    name: randomUuidExample.result,
    principal_id: dataAzureadServicePrincipalExample.id,
    role_definition_id: azurermRoleDefinitionExample.roleDefinitionResourceId,
    scope: azurermResourceGroupExample.id,
    skip_service_principal_aad_check: true,
  }
);
/*This allows the Terraform resource name to match the original name. You can remove the call if you don't need them to match.*/
azurermRoleAssignmentExample.overrideLogicalId("example");

Arguments Reference

The following arguments are supported:

  • location - (Required) The Azure Region where the Virtual Desktop Scaling Plan should exist. Changing this forces a new Virtual Desktop Scaling Plan to be created.

  • name - (Required) The name which should be used for this Virtual Desktop Scaling Plan . Changing this forces a new Virtual Desktop Scaling Plan to be created.

  • resourceGroupName - (Required) The name of the Resource Group where the Virtual Desktop Scaling Plan should exist. Changing this forces a new Virtual Desktop Scaling Plan to be created.

  • schedule - (Required) One or more schedule blocks as defined below.

  • hostPool - (Required) One or more hostPool blocks as defined below.

  • timeZone - (Required) Specifies the Time Zone which should be used by the Scaling Plan for time based events, the possible values are defined here.


  • description - (Optional) A description of the Scaling Plan.

  • exclusionTag - (Optional) The name of the tag associated with the VMs you want to exclude from autoscaling.

  • friendlyName - (Optional) Friendly name of the Scaling Plan.

  • hostPool - (Optional) One or more hostPool blocks as defined below.

  • tags - (Optional) A mapping of tags which should be assigned to the Virtual Desktop Scaling Plan .


A hostPool block supports the following:

  • hostpoolId - (Required) The ID of the HostPool to assign the Scaling Plan to.

  • scalingPlanEnabled - (Required) Specifies if the scaling plan is enabled or disabled for the HostPool.


A schedule block supports the following:

  • daysOfWeek - (Required) A list of Days of the Week on which this schedule will be used. Possible values are monday, tuesday, wednesday, thursday, friday, saturday, and sunday

  • name - (Required) The name of the schedule.

  • offPeakLoadBalancingAlgorithm - (Required) The load Balancing Algorithm to use during Off-Peak Hours. Possible values are depthFirst and breadthFirst.

  • offPeakStartTime - (Required) The time at which Off-Peak scaling will begin. This is also the end-time for the Ramp-Down period. The time must be specified in "HH:MM" format.

  • peakLoadBalancingAlgorithm - (Required) The load Balancing Algorithm to use during Peak Hours. Possible values are depthFirst and breadthFirst.

  • peakStartTime - (Required) The time at which Peak scaling will begin. This is also the end-time for the Ramp-Up period. The time must be specified in "HH:MM" format.

  • rampDownCapacityThresholdPercent - (Required) This is the value in percentage of used host pool capacity that will be considered to evaluate whether to turn on/off virtual machines during the ramp-down and off-peak hours. For example, if capacity threshold is specified as 60% and your total host pool capacity is 100 sessions, autoscale will turn on additional session hosts once the host pool exceeds a load of 60 sessions.

  • rampDownForceLogoffUsers - (Required) Whether users will be forced to log-off session hosts once the rampDownWaitTimeMinutes value has been exceeded during the Ramp-Down period. Possible

  • rampDownLoadBalancingAlgorithm - (Required) The load Balancing Algorithm to use during the Ramp-Down period. Possible values are depthFirst and breadthFirst.

  • rampDownMinimumHostsPercent - (Required) The minimum percentage of session host virtual machines that you would like to get to for ramp-down and off-peak hours. For example, if Minimum percentage of hosts is specified as 10% and total number of session hosts in your host pool is 10, autoscale will ensure a minimum of 1 session host is available to take user connections.

  • rampDownNotificationMessage - (Required) The notification message to send to users during Ramp-Down period when they are required to log-off.

  • rampDownStartTime - (Required) The time at which Ramp-Down scaling will begin. This is also the end-time for the Ramp-Up period. The time must be specified in "HH:MM" format.

  • rampDownStopHostsWhen - (Required) Controls Session Host shutdown behaviour during Ramp-Down period. Session Hosts can either be shutdown when all sessions on the Session Host have ended, or when there are no Active sessions left on the Session Host. Possible values are zeroSessions and zeroActiveSessions.

  • rampDownWaitTimeMinutes - (Required) The number of minutes during Ramp-Down period that autoscale will wait after setting the session host VMs to drain mode, notifying any currently signed in users to save their work before forcing the users to logoff. Once all user sessions on the session host VM have been logged off, Autoscale will shut down the VM.

  • rampUpLoadBalancingAlgorithm - (Required) The load Balancing Algorithm to use during the Ramp-Up period. Possible values are depthFirst and breadthFirst.

  • rampUpStartTime - (Required) The time at which Ramp-Up scaling will begin. This is also the end-time for the Ramp-Up period. The time must be specified in "HH:MM" format.

  • rampUpCapacityThresholdPercent - (Optional) This is the value of percentage of used host pool capacity that will be considered to evaluate whether to turn on/off virtual machines during the ramp-up and peak hours. For example, if capacity threshold is specified as 60% and your total host pool capacity is 100 sessions, autoscale will turn on additional session hosts once the host pool exceeds a load of 60 sessions.

  • rampUpMinimumHostsPercent - (Optional) Specifies the minimum percentage of session host virtual machines to start during ramp-up for peak hours. For example, if Minimum percentage of hosts is specified as 10% and total number of session hosts in your host pool is 10, autoscale will ensure a minimum of 1 session host is available to take user connections.

Attributes Reference

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

  • id - The ID of the Virtual Desktop Scaling Plan.

Timeouts

The timeouts block allows you to specify timeouts for certain actions:

  • create - (Defaults to 1 hour) Used when creating the Virtual Desktop Scaling Plan.
  • read - (Defaults to 5 minutes) Used when retrieving the Virtual Desktop Scaling Plan.
  • update - (Defaults to 1 hour) Used when updating the Virtual Desktop Scaling Plan.
  • delete - (Defaults to 1 hour) Used when deleting the Virtual Desktop Scaling Plan.

Import

Virtual Desktop Scaling Plans can be imported using the resourceId, e.g.

terraform import azurerm_virtual_desktop_scaling_plan.example /subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resGroup1/providers/Microsoft.DesktopVirtualization/scalingPlans/plan1