Hello all,
The year 2024 has been the year of AI and Microsoft has jumped the hype with Copilot. Copilot can make the life of the users easier but also that of the IT admin.
At the moment of writing this blog post, Azure Copilot is in Public Preview. Azure Copilot can help the IT admin to understand Azure better and ask help with how Azure can help with saving costs. More info about Copilot for Azure can be found here.
Now let’s look at the topic of this blog post. Let’s discover how Copilot can help IT admins to deploy AVD. Copilot can be asked a lot of different things, but we can also ask it to create scripts. In this case, I want to know if it can create a Terraform script to deploy AVD. This can be helpful if your knowledge of writing Terraform or Bicep, PowerShell isn’t enough or if you are learning those languages.
Access Azure Copilot
To start using Azure Copilot, Click on the Copilot button next to the Azure portal search box.

Lets first see how to create a host pool with the question “Create a terraform script to create a host pool”.
# This configuration has been generated by the Azure deployments handler which utilizes Generative AI which may result in unintended or inaccurate configuration code. A human must validate that this configuration accomplishes the desired goal before applying the configuration.
provider "azurerm" {
features {}
}
variable "az_rg_name" {
type = string
default = "example-host-pool-rg"
}
variable "location" {
type = string
default = "West Europe"
}
variable "az_vdhp_name" {
type = string
default = "myHostPool"
}
variable "az_vdhp_friendly_name" {
type = string
default = "My Host Pool"
}
variable "az_vdhp_type" {
type = string
default = "Pooled"
}
variable "az_vdhp_load_balancer_type" {
type = string
default = "DepthFirst"
}
resource "azurerm_resource_group" "az_rg" {
name = var.az_rg_name
location = var.location
}
resource "azurerm_virtual_desktop_host_pool" "az_vdhp" {
location = azurerm_resource_group.az_rg.location
resource_group_name = azurerm_resource_group.az_rg.name
name = var.az_vdhp_name
friendly_name = var.az_vdhp_friendly_name
validate_environment = true
start_vm_on_connect = true
load_balancer_type = var.az_vdhp_load_balancer_type
type = var.az_vdhp_type
maximum_sessions_allowed = 50
scheduled_agent_updates {
enabled = true
schedule {
day_of_week = "Saturday"
hour_of_day = 2
}
}
}
So this is a basic script for a host pool. Let’s now add a workspace and an application group.
# This configuration has been generated by the Azure deployments handler which utilizes Generative AI which may result in unintended or inaccurate configuration code. A human must validate that this configuration accomplishes the desired goal before applying the configuration.
provider "azurerm" {
features {}
}
variable "az_rg_name" {
type = string
default = "rg-example-virtualdesktop"
}
variable "location" {
type = string
default = "East US"
}
variable "workspace_name" {
type = string
default = "example-workspace"
}
variable "workspace_friendly_name" {
type = string
default = "Example Workspace"
}
variable "host_pool_name" {
type = string
default = "example-host-pool"
}
variable "host_pool_type" {
type = string
default = "Pooled"
}
variable "host_pool_load_balancer_type" {
type = string
default = "BreadthFirst"
}
variable "desktopapp_name" {
type = string
default = "example-desktop-app"
}
variable "desktopapp_friendly_name" {
type = string
default = "Example Desktop Application Group"
}
resource "azurerm_resource_group" "az_rg" {
name = var.az_rg_name
location = var.location
}
resource "azurerm_virtual_desktop_workspace" "workspace" {
name = var.workspace_name
location = azurerm_resource_group.az_rg.location
resource_group_name = azurerm_resource_group.az_rg.name
friendly_name = var.workspace_friendly_name
description = "A workspace for the Azure Virtual Desktop environment"
}
resource "azurerm_virtual_desktop_host_pool" "host_pool" {
name = var.host_pool_name
location = azurerm_resource_group.az_rg.location
resource_group_name = azurerm_resource_group.az_rg.name
type = var.host_pool_type
load_balancer_type = var.host_pool_load_balancer_type
}
resource "azurerm_virtual_desktop_application_group" "desktop_app" {
name = var.desktopapp_name
location = azurerm_resource_group.az_rg.location
resource_group_name = azurerm_resource_group.az_rg.name
type = "Desktop"
host_pool_id = azurerm_virtual_desktop_host_pool.host_pool.id
friendly_name = var.desktopapp_friendly_name
description = "A desktop application group for the Azure Virtual Desktop environment"
}
Now let’s see if we can add custom variables to copilot to add in the script like a subnet and vnet for the session hosts.
Create a terraform script to create a host pool, workspace, desktop application group and session host that are entra joined to subnet
snet-prd-jvn-avd-shared-sessionhosts-01 in vnet vnet-prd-jvn-avd-we-01
# This configuration has been generated by the Azure deployments handler which utilizes Generative AI which may result in unintended or inaccurate configuration code. A human must validate that this configuration accomplishes the desired goal before applying the configuration.
provider "azurerm" {
features {}
}
variable "az_rg_name" {
type = string
default = "rg-example-virtualdesktop"
}
variable "location" {
type = string
default = "East US"
}
variable "host_pool_name" {
type = string
default = "hostpool-example"
}
variable "workspace_name" {
type = string
default = "workspace-example"
}
variable "application_group_name" {
type = string
default = "appgroup-example"
}
variable "vnet_name" {
type = string
default = "vnet-prd-jvn-avd-we-01"
}
variable "subnet_name" {
type = string
default = "snet-prd-jvn-avd-shared-sessionhosts-01"
}
resource "azurerm_resource_group" "az_rg" {
name = var.az_rg_name
location = var.location
}
resource "azurerm_virtual_desktop_host_pool" "host_pool" {
name = var.host_pool_name
location = azurerm_resource_group.az_rg.location
resource_group_name = azurerm_resource_group.az_rg.name
type = "Pooled"
load_balancer_type = "BreadthFirst"
}
resource "azurerm_virtual_desktop_workspace" "workspace" {
name = var.workspace_name
location = azurerm_resource_group.az_rg.location
resource_group_name = azurerm_resource_group.az_rg.name
friendly_name = "Example Workspace"
description = "An example workspace for Azure Virtual Desktop."
}
resource "azurerm_virtual_desktop_application_group" "application_group" {
name = var.application_group_name
location = azurerm_resource_group.az_rg.location
resource_group_name = azurerm_resource_group.az_rg.name
type = "Desktop"
host_pool_id = azurerm_virtual_desktop_host_pool.host_pool.id
friendly_name = "Example Application Group"
description = "An example application group for Azure Virtual Desktop."
}
data "azurerm_virtual_network" "vnet" {
name = var.vnet_name
resource_group_name = azurerm_resource_group.az_rg.name
}
data "azurerm_subnet" "subnet" {
name = var.subnet_name
virtual_network_name = data.azurerm_virtual_network.vnet.name
resource_group_name = azurerm_resource_group.az_rg.name
}
resource "azurerm_virtual_desktop_session_host" "session_host" {
name = "sessionhost-example"
resource_group_name = azurerm_resource_group.az_rg.name
host_pool_id = azurerm_virtual_desktop_host_pool.host_pool.id
subnet_id = data.azurerm_subnet.subnet.id
os_type = "Windows"
admin_username = "adminuser"
admin_password = "AdminPassword123!" # Ensure to use secure methods for passwords in production
azure_ad_join = true
}
And what happens, Copilot creates the script with the custom variables. This can be very helpful for IT admin who are not very proficient in scripting but want to learn in.
Important to know is that these are basic examples, if your organization has multiple subscriptions in Azure, you will have to work with different Terraform providers in the script. The provider block includes the subscription id.
Conclusion
IT admins can use Azure Copilot to learn more about all aspects off Azure, deploy Azure resources and learn about best practices. Although Azure Copilot is currently still in public preview, I find it very useful to quickly search information about resources in Azure.
I hope you find this blog post helpful and until next time.