Using https://techcommunity.microsoft.com/t5/azure-virtual-desktop/arm-avd-with-terraform/m-p/2639806 as inspiration, I want to deploy AVD but with AAD joined VMs using terraform. I have defined a VM and extension in Terraform alongside a Azure Virtual Desktop deployment(host pool, app group, workspace) as per the article, and I have adapted the extensions based on the ARM template generated by Azure when VMs are added to the Host Pool and joined with AAD 'manually'/through the portal.
The terraform applies and the extensions run through successfully but the VMs do not join the domain.
When I look at the logs on the deployed VM one of the main errors is 'DsrCmdAzureHelper::GetTenantId: Unable to get Tenant Id, status code 400'. I get 400 status code when getting metadata from Targeting host name:169.254.169.254, url path: /metadata/identity/info?api-version=2018-02-01 and the 'identity not found' errors follow.
What is the issue here? Below is the terraform for the extensions, let me know if more is required.
locals {
registration_token = azurerm_virtual_desktop_host_pool.hostpool.registration_info[0].token
}
resource "azurerm_virtual_machine_extension" "domain_join" {
count = var.rdsh_count
name = "${var.prefix}-${count.index + 1}-domainJoin"
virtual_machine_id = azurerm_windows_virtual_machine.avd_vm.*.id[count.index]
publisher = "Microsoft.Azure.ActiveDirectory"
type = "AADLoginForWindows"
type_handler_version = "1.0"
auto_upgrade_minor_version = true
depends_on = [
azurerm_virtual_machine_extension.vmext_dsc
]
}
resource "azurerm_virtual_machine_extension" "vmext_dsc" {
count = var.rdsh_count
name = "${var.prefix}${count.index + 1}-avd_dsc"
# virtual_machine_id = azurerm_windows_virtual_machine.avd_vm.*.id[count.index]
virtual_machine_id = azurerm_windows_virtual_machine.avd_vm.*.id[count.index]
publisher = "Microsoft.Powershell"
type = "DSC"
type_handler_version = "2.73"
auto_upgrade_minor_version = true
settings = <<-SETTINGS
{
"modulesUrl": "https://wvdportalstorageblob.blob.core.windows.net/galleryartifacts/Configuration_9-30-2021.zip",
"configurationFunction": "Configuration.ps1\\AddSessionHost",
"properties": {
"HostPoolName":"${azurerm_virtual_desktop_host_pool.hostpool.name}",
"aadJoin": true
}
}
SETTINGS
protected_settings = <<PROTECTED_SETTINGS
{
"properties": {
"registrationInfoToken": "${local.registration_token}"
}
}
PROTECTED_SETTINGS
depends_on = [
azurerm_virtual_desktop_host_pool.hostpool
]
}
I tested it in my environment and the issue was same like below :
As per the discussion in this
Microsoft Q & A Thread
, It is mentioned that a keyAADJPrivate
should be present under pathHKLM\Software\microsoft\RDInfraAgent
, if it is not present then the VM will add the extensions properly but fail to domain join with Azure AD.So, as a solution , I changed few things in the code like :
After Modifications ,I tried with something like below :
Output:
Note: As per this
GitHub Issue
, you have to use azurerm provider version 2.90.0.