ARM AVD with Terraform

%3CLINGO-SUB%20id%3D%22lingo-sub-2639806%22%20slang%3D%22en-US%22%3EARM%20AVD%20with%20Terraform%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2639806%22%20slang%3D%22en-US%22%3E%3CH2%20id%3D%22toc-hId--382770572%22%20id%3D%22toc-hId--382770513%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId-2104742261%22%20id%3D%22toc-hId-2104742320%22%3EDeploying%20Azure%20Virtual%20Desktop%20with%20Terraform%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20article%20has%20been%20written%20in%20collaboration%20with%20my%20colleagues%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F645942%22%20target%3D%22_blank%22%3E%40Jensheerin%3C%2FA%3E%26nbsp%3B%2C%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F195573%22%20target%3D%22_blank%22%3E%40Stefan%20Georgiev%3C%2FA%3E%26nbsp%3Band%26nbsp%3BJulie%20NG.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETerraform%20is%20a%20tool%20that%20enables%20you%20to%20completely%20automate%20infrastructure%20builds%20through%20configuration%20files.%20It%20provides%20versioning%20for%20configurations%2C%20which%20makes%20it%20easy%20to%20deploy%20and%20maintain%20your%20existing%20Azure%20Virtual%20Desktop%20deployments%20on%20Microsoft%20Azure.%3C%2FP%3E%0A%3CP%3EThis%20article%20provides%20an%20overview%20of%20how%20to%20use%20Terraform%20to%20deploy%20a%20simple%20Azure%20Virtual%20Desktop%20environment.%26nbsp%3B%20%26nbsp%3B%3CSTRONG%3EThis%20is%20to%20deploy%20ARM%20AVD%2C%20not%20AVD%20Classic.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20several%20pre-requisites%20required%20to%20deploy%20Azure%20Virtual%20Desktop%2C%20which%20we%20will%20assume%20are%20already%20in%20place.%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EEnsure%20that%20you%20meet%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fvirtual-desktop%2Foverview%23requirements%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Erequirements%20for%20Azure%20Virtual%20Desktop%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3ETerraform%20must%20be%20installed%20and%20configured%20as%20outlined%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fterraform%2Fterraform-install-configure%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20are%20completely%20new%20to%20Azure%20Virtual%20Desktop%2C%20please%20check%20them%20out%20here%3A%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-desktop%2Foverview%23requirements%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EWhat%20is%20Azure%20Virtual%20Desktop%3F%20-%20Azure%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%20several%20topics%20that%20should%20be%20considered%20when%20creating%20a%20production%20Azure%20Virtual%20Desktop%20environment%2C%20that%20we%20haven%E2%80%99t%20been%20able%20to%20include%20in%20the%20scope%20of%20this%20article%2C%20such%20as%20security%2C%20monitoring%2C%20BCDR%20and%20image%20build.%26nbsp%3B%26nbsp%3B%20This%20article%20aims%20to%20get%20you%20started%20with%20building%20a%20PoC%20for%20Azure%20Virtual%20Desktop%20via%20Terraform.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAll%20the%20code%20in%20this%20article%20can%20be%20found%20in%20the%20repo%3A%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fnam06.safelinks.protection.outlook.com%2F%3Furl%3Dhttps%253A%252F%252Fgithub.com%252FAzure%252FRDS-Templates%252Ftree%252Fmaster%252Fwvd-sh%252Fterraform-azurerm-azuresvirtualdesktop%26amp%3Bdata%3D04%257C01%257CEmily.McLaren%2540microsoft.com%257C1fbb7286be6444d7691a08d95d4d6452%257C72f988bf86f141af91ab2d7cd011db47%257C1%257C0%257C637643409271648451%257CUnknown%257CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%253D%257C1000%26amp%3Bsdata%3DPZLbIpwjK%252Bmxpda3UAh5ns1cYOCxObnZcElv2yVwsLI%253D%26amp%3Breserved%3D0%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3ERDS-Templates%2Fwvd-sh%2Fterraform-azurerm-azuresvirtualdesktop%20at%20master%20%C2%B7%20Azure%2FRDS-Templates%20(github.com)%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CEM%3ENote%3C%2FEM%3E%3C%2FSTRONG%3E%3CEM%3E%3A%20Terraform%20is%20an%20open%20source%20tool%20hosted%20in%20GitHub.%20As%20such%2C%20it%20is%20published%20%22as%20is%22%20with%20no%20implied%20support%20from%20Microsoft%20or%20any%20other%20organization.%20However%2C%20we%20would%20like%20to%20welcome%20you%20to%20open%20issues%20using%20GitHub%20issues%20to%20collaborate%20toward%20future%20improvements%20to%20the%20tool.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EAVD%20Components%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ETo%20deploy%20AVD%20we%20will%20need%20to%20understand%20what%20components%20are%20required.%26nbsp%3B%20We%E2%80%99re%20assuming%20that%20your%20pre-requisites%20are%20already%20in%20place.%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EActive%20Directory%20-%20in%20this%20worked%20example%2C%20we%20are%20using%20%E2%80%98on-prem%E2%80%99%20AD%20running%20on%20DCs%20in%20a%20separate%20VNet.%26nbsp%3B%20The%20code%20could%20easily%20be%20modified%20to%20use%20AADDS%20though.%3C%2FLI%3E%0A%3CLI%3EUsers%20in%20AAD%20that%20will%20be%20given%20access%20to%20AVD%3C%2FLI%3E%0A%3CLI%3EA%20VM%20Image%20(or%20you%20can%20use%20a%20marketplace%20image)%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EComponents%20we%20will%20deploy%20in%20this%20article%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EVirtual%20Desktop%20Environment%3C%2FLI%3E%0A%3CLI%3ENetworking%20Infrastructure%3C%2FLI%3E%0A%3CLI%3ESession%20Hosts%3C%2FLI%3E%0A%3CLI%3EProfile%20Storage%3C%2FLI%3E%0A%3CLI%3ERole%20Based%20Access%20Control%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EOur%20architecture%20should%20look%20like%20the%20below%20once%20completed%20(sections%20in%20white%20are%20pre-reqs%2C%20grey%20will%20be%20deployed).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorEmilyMclaren_2%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22EmilyMclaren_5-1628763948083.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302661iB8F909AF72FFB199%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22EmilyMclaren_5-1628763948083.png%22%20alt%3D%22EmilyMclaren_5-1628763948083.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-297287798%22%20id%3D%22toc-hId-297287857%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId--1510166665%22%20id%3D%22toc-hId--1510166606%22%3E%3CSTRONG%3ESetting%20up%20Terraform%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%E2%80%99ll%20need%20to%20authenticate%20to%20Azure%20to%20run%20the%20templates%20%E2%80%93%20the%20steps%20to%20do%20that%20are%20here%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20want%20to%20use%20Visual%20Studio%20Code%20please%20have%20a%20look%20at%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fterraform%2Fterraform-vscode-extension%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ethis%3C%2FA%3E%20article.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20your%20environment%20is%20ready%2C%20we%20can%20start%20to%20understand%20how%20to%20deploy%20all%20of%20the%20required%20resources.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-977346168%22%20id%3D%22toc-hId-977346227%22%3E%3CSTRONG%3E1.%20AVD%20environment%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirst%20up%20we%20will%20deploy%20the%20environment%20for%20Azure%20Virtual%20Desktop.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20section%20we%20will%20deploy%20the%20following%20resources%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EResource%20Group%3C%2FLI%3E%0A%3CLI%3EWorkspace%3C%2FLI%3E%0A%3CLI%3EHostpool%3C%2FLI%3E%0A%3CLI%3EHostpool%20registration%20expiration%20date%20(create%20a%20time_rotating%20resource)%3C%2FLI%3E%0A%3CLI%3EApplication%20Group%20(our%20DAG)%3C%2FLI%3E%0A%3CLI%3EApplication%20Group%20association%20to%20workspace%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBefore%20we%20create%20templates%20for%20the%20resources%20we%20need%20to%20configure%20the%20%3CA%20href%3D%22https%3A%2F%2Fregistry.terraform.io%2Fproviders%2Fhashicorp%2Fazurerm%2Flatest%2Fdocs%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EAzure%20Provider%3C%2FA%3E%3CSPAN%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ETo%20do%20this%20we%20will%20create%20a%20%3CSTRONG%3Eproviders.tf%3C%2FSTRONG%3E%20file%20and%20add%20the%20following%3A%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Eterraform%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20required_providers%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20azurerm%20%3D%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20source%20%3D%20%22hashicorp%2Fazurerm%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20version%20%3D%20%22%22~%26gt%3B2.0%22%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Eprovider%20%22azurerm%22%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20features%20%7B%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20full%20code%20for%20%3CSTRONG%3Eprovider.tf%20%3C%2FSTRONG%3Ecan%20be%20found%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2FRDS-Templates%2Fblob%2Fmaster%2Fwvd-sh%2Fterraform-azurerm-azuresvirtualdesktop%2Fprovider.tf%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20Terraform%20documentation%20for%20AVD%20is%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fregistry.terraform.io%2Fproviders%2Fhashicorp%2Fazurerm%2Flatest%2Fdocs%2Fresources%2Fvirtual_desktop_workspace%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eazurerm_virtual_desktop_workspace%20%7C%20Resources%20%7C%20hashicorp%2Fazurerm%20%7C%20Terraform%20Registry%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20to%20create%20the%20resources%2C%20first%20create%20%3CSTRONG%3Emain.tf%20%3C%2FSTRONG%3Eand%20start%20adding%20resources%20in%20the%20format%3A%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Eresource%20%22azurerm_virtual_desktop_workspace%22%20%22workspace%22%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%26nbsp%3Bvar.workspace%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20location%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%26nbsp%3Bvar.deploy_location%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20resource_group_name%20%3D%20azurerm_resource_group.rg.name%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20friendly_name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22%24%7Bvar.prefix%7D%20Workspace%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20description%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22%24%7Bvar.prefix%7D%20Workspace%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3ENote%20that%20there%20are%20several%20dependencies%20in%20the%20order%20that%20resources%20are%20created.%26nbsp%3B%20We%20can%20specify%20those%20using%20the%20following%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3Edepends_on%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%5Bazurerm_virtual_desktop_host_pool.hostpool%2Cazurerm_virtual_desktop_workspace.workspace%5D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20case%20we%20are%20specifying%20the%20dependency%20for%20provisioning%20the%20Desktop%20Application%20group%20%E2%80%93%20that%20the%20hostpool%20and%20workspace%20must%20already%20exist%20before%20we%20try%20to%20create%20this%20resource.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20have%20also%20referenced%20some%20variables%20in%20here%2C%20so%20let%E2%80%99s%20create%20a%20%3CSTRONG%3Evariables.tf%20%3C%2FSTRONG%3Efile%20for%20those%20now%20and%20add%20our%20variables.%26nbsp%3B%20They%20will%20be%20in%20the%20following%20form%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3Evariable%20%22deploy_location%22%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20type%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20string%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20default%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22West%20Europe%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20description%20%3D%20%22location%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EWe%20will%20also%20need%20to%20add%20variables%20for%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EResource%20group%20name%3C%2FLI%3E%0A%3CLI%3EPrefix%20(this%20will%20be%20appended%20to%20resources%20such%20as%20session%20hosts)%3C%2FLI%3E%0A%3CLI%3EHost%20pool%20name%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20full%20list%20of%20the%20variables%20that%20are%20referenced%20are%20listed%20at%20the%20end%20of%20the%20article%20in%20%3CSTRONG%3Estep%207%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20deploy%20at%20this%20point%20and%20it%20will%20create%20the%20basic%20AVD%20components%2C%20but%20no%20session%20hosts.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20add%20the%20session%20hosts%2C%20we%20need%20to%20ensure%20we%20can%20access%20Active%20Directory.%26nbsp%3B%26nbsp%3B%20For%20this%20example%20we%20are%20assuming%20that%20we%20are%20using%20AD%20rather%20than%20AADDS.%26nbsp%3B%20We%20are%20also%20assuming%20you%20have%20a%20domain%20controller%20in%20an%20Azure%20VNet.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--830108295%22%20id%3D%22toc-hId--830108236%22%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3CSTRONG%3E2.%20Networking%20infrastructure%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20will%20create%20a%20new%20VNet%20for%20our%20session%20hosts%20and%20peer%20it%20to%20our%20AD%20VNet.%26nbsp%3B%20we%E2%80%99ve%20also%20included%20an%20NSG%20here%20with%20a%20sample%20rule%20%E2%80%93%20I%E2%80%99d%20strongly%20suggest%20modifying%20them%20to%20meet%20your%20own%20security%20requirements.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EComponents%20we%20will%20deploy%20here%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ESession%20Host%20Virtual%20Network%3C%2FLI%3E%0A%3CLI%3ESession%20Host%20Subnet%3C%2FLI%3E%0A%3CLI%3ENSG%3C%2FLI%3E%0A%3CLI%3ENSG%20%E2%80%93%20Subnet%20association%3C%2FLI%3E%0A%3CLI%3EVNet%20Peering%20to%20Active%20Directory%20VNet%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20full%20template%20can%20be%20found%20in%20%3CSTRONG%3Enetworking.tf%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20new%20concept%20we%20have%20here%20is%20using%20%3CSTRONG%3Edata%3C%2FSTRONG%3E%20to%20retrieve%20the%20properties%20of%20our%20existing%20Active%20Directory%20(Hub)%20VNet.%26nbsp%3B%20We%20can%20then%20pass%20the%20ID%20to%20new%20peering%20we%20are%20creating.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3Edata%20%22azurerm_virtual_network%22%20%22ad_vnet_data%22%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20name%20%3D%20var.ad_vnet%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20resource_group_name%20%3D%20var.ad_rg%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Eresource%20%22azurerm_virtual_network_peering%22%20%22peer1%22%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22peer_avd_ad%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20resource_group_name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20azurerm_resource_group.rg.name%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20virtual_network_name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20azurerm_virtual_network.vnet.name%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20remote_virtual_network_id%20%3D%20data.azurerm_virtual_network.%20ad_vnet_data.id%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Eresource%20%22azurerm_virtual_network_peering%22%20%22peer2%22%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22peer_avd_ad%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20resource_group_name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20var.ad_rg%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20virtual_network_name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20var.ad_vnet%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20remote_virtual_network_id%20%3D%20azurerm_virtual_network.vnet.id%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAgain%2C%20we%20can%20see%20that%20we%20have%20referenced%20several%20variables%2C%20so%20you%E2%80%99ll%20need%20to%20add%20the%20following%20to%20your%20variables.tf%20file%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Ead_vnet%26nbsp%3B%20%E2%80%93%20the%20name%20of%20the%20VNet%20containing%20our%20Domain%20Controllers%3C%2FLI%3E%0A%3CLI%3Ead_rg%26nbsp%3B%20-%20resource%20group%20containing%20DCs%3C%2FLI%3E%0A%3CLI%3Edns_servers%20%E2%80%93%20custom%20DNS%20servers%20that%20we%E2%80%99re%20using%20for%20our%20new%20VNet%3C%2FLI%3E%0A%3CLI%3Evnet_range%20%E2%80%93%20Address%20range%20for%20our%20new%20VNet%3C%2FLI%3E%0A%3CLI%3Esubnet_range%20-%20Address%20range%20for%20our%20new%20subnet%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20we%20should%20have%20all%20our%20basic%20infrastructure%20in%20place%2C%20we%20can%20move%20onto%20the%20session%20hosts.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1657404538%22%20id%3D%22toc-hId-1657404597%22%3E%3CSTRONG%3E3.%20Session%20Hosts%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EHere%20we%20are%20deploying%20and%20configuring%20our%20session%20hosts.%26nbsp%3B%20In%20this%20example%2C%20we%20will%20create%20a%20new%20Terraform%20config%20file%2C%20%3CSTRONG%3Ehost.tf%3C%2FSTRONG%3E%20to%20do%20this.%26nbsp%3B%20Full%20code%20is%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2FRDS-Templates%2Fblob%2Fmaster%2Fwvd-sh%2Fterraform-azurerm-azuresvirtualdesktop%2Fhost.tf%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%20We%20will%20also%20add%20our%20variables%20to%20the%20%3CSTRONG%3Evariables.tf%20%3C%2FSTRONG%3Efile.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EComponents%20to%20deploy%20in%20this%20section%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ENIC%20for%20each%20session%20host%3C%2FLI%3E%0A%3CLI%3ESession%20Host%20VM(s)%3C%2FLI%3E%0A%3CLI%3EDomain-join%20VM%20extension%3C%2FLI%3E%0A%3CLI%3EDsc%20VM%20extension%20to%20register%20session%20host%3C%2FLI%3E%0A%3CLI%3ERandom%20strong%20for%20local%20vm%20password%3C%2FLI%3E%0A%3CLI%3ELocal%20variable%20for%20registration%20token%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20part%20is%20slightly%20more%20complex%20than%20the%20infrastructure%20deployment.%26nbsp%3B%26nbsp%3B%20The%20new%20concepts%20in%20this%20section%20are%20covered%20below.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20firstly%20need%20to%20create%20a%20local%20variable%20for%20our%20registration_info%20token%20to%20allow%20us%20to%20register%20the%20VM%20to%20the%20host%20pool.%26nbsp%3B%20This%20is%20later%20passed%20as%20a%20protected%20setting%20to%20the%20dsc%20extension%20resource.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3Elocals%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20registration_token%20%3D%20azurerm_virtual_desktop_host_pool.hostpool.registration_info%5B0%5D.token%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EWe%E2%80%99re%20also%20creating%20a%20random%20local%20password%20%E2%80%93%20which%20needs%20to%20meet%20the%20AVD%20requirements%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3Eresource%20%22random_string%22%20%22avd_local_password%22%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20count%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22%24%7Bvar.rdsh_count%7D%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20length%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%2016%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20special%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20true%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20min_special%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%202%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20override_special%20%3D%20%22*!%40%23%3F%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EIn%20the%20password%20section%20you%20will%20see%20us%20referencing%20%3CSTRONG%3Erdshcount%3C%2FSTRONG%3E.%26nbsp%3B%20This%20allows%20us%20to%20deploy%20a%20variable%20number%20of%20VMs%20to%20our%20host%20pool.%26nbsp%3B%20Using%20this%20counter%20will%20be%20used%20for%20the%20VM%2C%20the%20NICs%2C%20local%20passwords%20and%20the%20extensions.%26nbsp%3B%20We%20are%20also%20using%20the%20%3CA%20href%3D%22https%3A%2F%2Fwww.terraform.io%2Fdocs%2Flanguage%2Fmeta-arguments%2Fcount.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Ecount%20meta-argument%3C%2FA%3E%20to%20refer%20to%20specific%20instances%3A%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Eresource%20%22azurerm_windows_virtual_machine%22%20%22avd_vm%22%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20count%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22%24%7Bvar.rdsh_count%7D%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22%24%7Bvar.prefix%7D-%24%7Bcount.index%20%2B%201%7D%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20resource_group_name%26nbsp%3B%26nbsp%3B%20%3D%20var.rg_name%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20location%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20var.deploy_location%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20size%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20var.vm_size%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20network_interface_ids%20%3D%20%5B%22%24%7Bazurerm_network_interface.AVD_vm_nic.*.id%5Bcount.index%5D%7D%22%5D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20provision_vm_agent%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20true%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20admin_username%20%3D%20%22%24%7Bvar.local_admin_username%7D%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20admin_password%20%3D%20%22%24%7Brandom_string.AVD-local-password.*.result%5Bcount.index%5D%7D%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20os_disk%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22%24%7Blower(var.prefix)%7D-%24%7Bcount.index%20%2B1%7D%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20caching%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22ReadWrite%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20storage_account_type%20%3D%20%22Standard_LRS%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20source_image_reference%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20publisher%20%3D%20%22MicrosoftWindowsDesktop%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20offer%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22Windows-10%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20sku%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%2220h2-evd%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20version%26nbsp%3B%26nbsp%3B%20%3D%20%22latest%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Edepends_on%20%3D%20%5Bazurerm_resource_group.rg%2C%20azurerm_network_interface.AVD_vm_nic%5D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EThe%20VM%20resource%20is%20also%20where%20we%20specific%20the%20source%20image%20for%20the%20build.%20If%20you%20need%20a%20different%20market%20place%20image%20you%20can%20get%20the%20image%20SKU%20details%20using%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzVMImageSku%20-Location%20%3CLOCATION%3E%20-PublisherName%20MicrosoftWindowsDesktop%20-Offer%20windows-10%3C%2FLOCATION%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E(or%20%3CSTRONG%3E-Offer%20office-365%3C%2FSTRONG%3E%20if%20you%20want%20the%20image%20including%20M365%20apps).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EDeploying%20a%20custom%20image%20with%20the%20shared%20image%20gallery%20is%20a%20topic%20for%20a%20follow%20up%20article.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20additional%20variables%20we%20need%20to%20specify%20now%20are%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Erdsh_count%3C%2FLI%3E%0A%3CLI%3Edomain_name%3C%2FLI%3E%0A%3CLI%3Edomain_user_upn%3C%2FLI%3E%0A%3CLI%3Edomain_password%3C%2FLI%3E%0A%3CLI%3Evm_size%3C%2FLI%3E%0A%3CLI%3Eou_path%3C%2FLI%3E%0A%3CLI%3Elocal_admin_username%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--150049925%22%20id%3D%22toc-hId--150049866%22%3E%3CSTRONG%3E4.%20Profile%20Storage%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20this%20example%20we%E2%80%99ll%20deploy%20our%20profile%20storage%20using%20Azure%20Files.%26nbsp%3B%26nbsp%3B%20%3CSTRONG%3EStep%206%20%3C%2FSTRONG%3Ehas%20the%20steps%20to%20configure%20NetApp%20Files%20if%20you%20prefer%20this%20option.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20do%20this%20we%E2%80%99ll%20need%20to%20deploy%20the%20following%20resources%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EA%20dedicated%20resource%20group%20for%20our%20Storage%20account%3C%2FLI%3E%0A%3CLI%3EAzure%20File%20Storage%20account%3C%2FLI%3E%0A%3CLI%3EAzure%20Storage%20Share%3C%2FLI%3E%0A%3CLI%3EAssign%20AAD%20group%20to%20the%20Storage%20(Storage%20File%20Data%20SMB%20Share%20Contributor)%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EWe%20will%20deploy%20a%20new%20resource%20group.%26nbsp%3B%26nbsp%3B%20We%20are%20using%20a%20random%20string%20to%20generate%20a%20globally%20unique%20name%20for%20our%20Storage%20account.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20are%20creating%20a%20file%20called%20%3CSTRONG%3Eafstorage.tf%3C%2FSTRONG%3E%20for%20this%20(and%20the%20full%20code%20is%20included%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2FRDS-Templates%2Fblob%2Fmaster%2Fwvd-sh%2Fterraform-azurerm-azuresvirtualdesktop%2Fafstorage.tf%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20are%20appending%20a%20random%20string%20to%20the%20storage%20account%20name%20to%20ensure%20uniqueness%20%E2%80%93%20as%20such%20we%20also%20use%20the%20%3CSTRONG%3Eoutput%3C%2FSTRONG%3E%20command%20so%20that%20we%20can%20see%20the%20name%20of%20our%20new%20storage%20account.%26nbsp%3B%20We%20can%20use%20the%20%3CSTRONG%3Eoutputs.tf%3C%2FSTRONG%3E%20file%20to%20define%20our%20outputs.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3Eoutput%20%22storage_account_name%22%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20value%20%3D%20azurerm_storage_account.storage.name%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFurther%20configuration%20will%20be%20needed%20to%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fstorage%2Ffiles%2Fstorage-files-identity-auth-active-directory-domain-service-enable%3Ftabs%3Dazure-portal%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eenable%20AD%20authentication%20if%20you%20choose%20that%20direction%20and%20to%20configure%20NTFS%20permissions%20of%20SMB%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1957504388%22%20id%3D%22toc-hId--1957504329%22%3E%3CSTRONG%3E5.%20RBAC%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CH2%20id%3D%22toc-hId-530008445%22%20id%3D%22toc-hId-530008504%22%3E%26nbsp%3B%3C%2FH2%3E%0A%3CP%3ENow%20that%20we%20have%20all%20our%20infrastructure%20deployed%2C%20let%20us%20give%20our%20users%20access.%26nbsp%3B%20Again%2C%20we%20will%20create%20a%20new%20config%20file%20for%20this%20%E2%80%93%20%3CSTRONG%3E%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2FRDS-Templates%2Fblob%2Fmaster%2Fwvd-sh%2Fterraform-azurerm-azuresvirtualdesktop%2Frbac.tf%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Erbac.tf%3C%2FA%3E%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20can%20also%20be%20modified%20to%20assign%20users%20to%20custom%20roles%2C%20or%20to%20the%20other%20desktop%20virtualization%20roles%20that%20are%20already%20built%20in%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fvirtual-desktop%2Frbac%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EBuilt-in%20roles%20Azure%20Virtual%20Desktop%20-%20Azure%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20components%20we%E2%80%99re%20creating%20here%20are%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EAzure%20Active%20Directory%20Group%3C%2FLI%3E%0A%3CLI%3EAAD%20group%20member%3C%2FLI%3E%0A%3CLI%3EAAD%20role%20assignment%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBefore%20we%20start%2C%20we%E2%80%99ll%20need%20to%20add%20the%20azuread%20provider%20to%20our%20list%20of%20required%20providers%20in%20our%20%3CSTRONG%3Eprovider.tf%3C%2FSTRONG%3E%20as%20we%20need%20to%20use%20this%20for%20some%20of%20the%20AAD%20resources.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3Eterraform%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20required_providers%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20azurerm%20%3D%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20source%20%3D%20%22hashicorp%2Fazurerm%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20version%20%3D%20%22~%26gt%3B2.0%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20azuread%20%3D%20%7B%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20source%20%3D%20%22hashicorp%2Fazuread%22%3C%2FEM%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20assign%20the%20RBAC%20permissions%20we%20need%20to%20pass%20a%20list%20of%20existing%20AAD%20Users%20and%20then%20add%20these%20to%20a%20new%20AAD%20group%20that%20we%20are%20creating.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20will%20use%20the%20AzureAD_user%20and%20azurerm_role_definition%20datasources%20to%20retrieve%20information%20about%20our%20users%20and%20the%20role%20we%E2%80%99re%20assigning%20(in%20this%20case%20the%20builtin%20%3CSTRONG%3EDesktop%20Virtualization%20user%3C%2FSTRONG%3E).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3Edata%20%22azuread_user%22%20%22aad_user%22%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20for_each%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20toset(var.avd_users)%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20user_principal_name%20%3D%20format(%22%25s%22%2C%20each.key)%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Edata%20%22azurerm_role_definition%22%20%22role_def%22%20%7B%20%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20name%20%3D%20%22Desktop%20Virtualization%20User%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EWe%E2%80%99re%20also%20going%20to%20use%20for_each%20to%20loop%20through%20that%20list%20of%20users%20(both%20when%20getting%20the%20UPN%20from%20AAD%20and%20when%20adding%20to%20the%20group).%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Eresource%20%22azuread_group_member%22%20%22aad_group_member%22%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20for_each%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20data.azuread_user.aad_user%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20group_object_id%26nbsp%3B%20%3D%20azuread_group.aad_group.id%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20member_object_id%20%3D%20each.value%5B%22id%22%5D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3ELastly%20we%E2%80%99ll%20scope%20the%20role%20assignment%20to%20the%20application%20group%20we%20created%20at%20the%20start%20and%20apply%20it%20to%20the%20group%20containing%20our%20users.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3Eresource%20%22azurerm_role_assignment%22%20%22role%22%20%7B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20scope%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20azurerm_virtual_desktop_application_group.dag.id%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20role_definition_id%20%3D%20data.azurerm_role_definition.role_def.id%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20principal_id%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20azuread_group.aad_group.id%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%7D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20also%20need%20to%20add%20the%202%20new%20variables%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3Eaad_group_name%3C%2FLI%3E%0A%3CLI%3Eavd_users%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eavd_users%20will%20be%20an%20array%20to%20allow%20us%20to%20pass%20multiple%20users.%26nbsp%3B%20Up%20to%20now%20we%20have%20either%20specified%20default%20values%20for%20our%20variables%20or%20will%20pass%20them%20during%20deployment.%26nbsp%3B%20To%20make%20things%20simpler%20we%20will%20create%20an%20%3CSTRONG%3Eenv.tfvars%3C%2FSTRONG%3E%20file%20to%20pass%20our%20environment%20specific%20variables.%20%26nbsp%3B%26nbsp%3BYou%20can%20add%20as%20many%20(or%20few)%20pre-configured%20variables%20here%2C%20but%20keep%20security%20in%20mind%20if%20you%20are%20putting%20confidential%20data%20in%20there.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20sample%20might%20look%20like%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3Edeploy_location%20%3D%20%22west%20europe%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Erg_name%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3D%20%22avd-resources-rg%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Evnet_range%20%3D%26nbsp%3B%20%5B%2210.1.0.0%2F16%22%5D%20%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Esubnet_range%20%3D%20%5B%2210.1.0.0%2F24%22%5D%20%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Eprefix%20%3D%20%22avd%22%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Eavd_users%20%3D%20%5B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20%22user1%40%3CDOMAIN%3E.com%22%2C%3C%2FDOMAIN%3E%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%26nbsp%3B%20%22user2%40%3CDOMAIN%3E.com%22%3C%2FDOMAIN%3E%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%5D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3Edns_servers%20%3D%20%5B%2210.0.0.4%22%2C%20%22168.63.129.16%22%5D%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-396323721%22%20id%3D%22toc-hId-396323780%22%3E%3CSTRONG%3E6.%20NetApp%20Storage%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20an%20alternate%20to%20Azure%20Files%20you%20also%20have%20the%20option%20to%20deploy%20NetApp%20Storage%20for%20Azure%20Virtual%20Desktop%20profiles.%20To%20use%20NetApp%20Files%20you%20need%20to%20request%20access%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fazure-netapp-files%2Fazure-netapp-files-register%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ERegister%20for%20Azure%20NetApp%20Files%20%7C%20Microsoft%20Docs%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20deploy%20the%20storage%20we%E2%80%99ll%20need%20to%20deploy%20the%20following%20resources%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EA%20dedicated%20subnet%20for%20NetApp%3C%2FLI%3E%0A%3CLI%3ENetApp%20storage%20Account%3C%2FLI%3E%0A%3CLI%3ENetApp%20storage%20Pool%3C%2FLI%3E%0A%3CLI%3ENetApp%20storage%20Volume%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20simplicity%20we%E2%80%99ll%20deploy%20our%20subnet%20to%20the%20same%20Vnet%20we%20created%20earlier%2C%20and%20will%20use%20the%20same%20resource%20group%20and%20location%20variables.%26nbsp%3B%26nbsp%3B%20You%20may%20want%20separate%20resource%20groups%20and%2For%20more%20complex%20networking%20in%20a%20production%20deployment.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20are%20creating%20a%20file%20called%20%3CSTRONG%3Enetappstorage.tf%3C%2FSTRONG%3E%20for%20this%20and%20the%20full%20code%20can%20be%20found%20in%20the%20folder%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2FRDS-Templates%2Ftree%2Fmaster%2Fwvd-sh%2Fterraform-azurerm-azuresvirtualdesktop%2Foptions%2Fnetapp%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Eoptions%2Fnetapp%3C%2FA%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20also%20need%20to%20add%20some%20new%20variables%20(and%20you%E2%80%99ll%20probably%20want%20to%20update%20the%20default%20values%20as%20well)%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ENetApp_acct_name%3C%2FLI%3E%0A%3CLI%3ENetApp_pool_name%3C%2FLI%3E%0A%3CLI%3ENetApp_volume_name%3C%2FLI%3E%0A%3CLI%3ENetApp_smb_name%3C%2FLI%3E%0A%3CLI%3ENetApp_volume_path%3C%2FLI%3E%0A%3CLI%3ENetApp_subnet_name%3C%2FLI%3E%0A%3CLI%3ENetApp_Address%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20we%20should%20have%20created%209%20Files%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EMain.tf%3C%2FLI%3E%0A%3CLI%3ENetworking.tf%3C%2FLI%3E%0A%3CLI%3EHost.tf%3C%2FLI%3E%0A%3CLI%3Eafstorage.tf%20(or%20netappstorage.tf)%3C%2FLI%3E%0A%3CLI%3ERbac.tf%3C%2FLI%3E%0A%3CLI%3EVariables.tf%3C%2FLI%3E%0A%3CLI%3Edefaults.tfvars%3C%2FLI%3E%0A%3CLI%3EOutputs.tf%3C%2FLI%3E%0A%3CLI%3EProviders.tf%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1411130742%22%20id%3D%22toc-hId--1411130683%22%3E%3CSTRONG%3E7.%20Variables%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAll%20of%20the%20variables%20that%20we%20have%20referenced%20so%20far%20are%20described%20here%20(they%20are%20also%20in%20%3CSTRONG%3Evariables.tf%3C%2FSTRONG%3E)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CTABLE%3E%0A%3CTBODY%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3E%3CSTRONG%3EName%3C%2FSTRONG%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CSTRONG%3EDescription%3C%2FSTRONG%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CSTRONG%3EDefault%3C%2FSTRONG%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Erg_name%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EName%20of%20the%20Resource%20Group%20in%20which%20to%20deploy%20these%20resources%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EAVD-TF%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Edeploy_location%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EWest%20Europe%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Ehostpool%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EName%20of%20the%20Azure%20Virtual%20Desktop%20host%20pool%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EAVD-TF-HP%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Ead_vnet%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EName%20of%20domain%20controller%20VNet%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E-%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Edns_servers%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3ECustom%20DNS%20configuration%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E-%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Evnet_range%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EAddress%20range%20for%20deployment%20VNet%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E-%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Esubnet_range%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EAddress%20range%20for%20session%20host%20subnet%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E-%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Eavd_users%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EThe%20resource%20group%20for%20AD%20VM%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%5B%5D%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Eaad_group_name%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EAzure%20Active%20Directory%20Group%20for%20AVD%20users%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E-%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Erdsh_count%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3ENumber%20of%20AVD%20machines%20to%20deploy%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E2%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Eprefix%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EPrefix%20of%20the%20name%20of%20the%20AVD%20machine(s)%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E-%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Edomain_name%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EName%20of%20the%20domain%20to%20join%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E-%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Edomain_user_upn%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EUsername%20for%20domain%20join%20(do%20not%20include%20domain%20name%20as%20this%20is%20appended%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E-%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Edomain_password%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EPassword%20of%20the%20user%20to%20authenticate%20with%20the%20domain%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E-%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Evm_size%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3ESize%20of%20the%20machine%20to%20deploy%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EStandard_DS2_v2%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Eou_path%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EThe%20ou%20path%20for%20AD%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%22%22%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3Elocal_admin_username%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3EThe%20local%20admin%20username%20for%20the%20VM%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E-%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3E%3CEM%3Enetapp_acct_name%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3EThe%20NetApp%20account%20name%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3EAVD_NetApp%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3E%3CEM%3Enetapp_pool_name%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3EThe%20NetApp%20pool%20name%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3EAVD_NetApp_pool%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3E%3CEM%3Enetappvolumename%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3EThe%20NetApp%20volume%20name%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3EAVD_NetApp_volume%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3E%3CEM%3Enetapp_smb_name%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3EThe%20NetApp%20smb%20name%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3EAVDNetApp%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3E%3CEM%3Enetapp_volume_path%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3EThe%20NetApp%20volume%20path%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3EAVDNetAppVolume%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3E%3CEM%3Enetapp_subnet_name%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3EThe%20NetApp%20subnet%20name%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3ENetAppSubnet%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%3E%3CP%3E%3CEM%3Enetapp_address%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3EThe%20Address%20range%20for%20NetApp%20Subnet%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%3E%3CP%3E%3CEM%3E-%3C%2FEM%3E%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENote%3A%20%3C%2FSTRONG%3EVariables%20in%20%3CEM%3Eitalic%3C%2FEM%3E%20are%20optional%20and%20only%20needed%20if%20you%20are%20deploying%20NetApp%20Files%2C%20these%20are%20included%20only%20in%20the%20variables%20template%20in%20the%20netapp%20folder.%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1076382091%22%20id%3D%22toc-hId-1076382150%22%3E%3CSTRONG%3E8.%20Deploy!%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20templates%20can%20be%20downloaded%20from%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FAzure%2FRDS-Templates%2Ftree%2Fmaster%2Fwvd-sh%2Fterraform-azurerm-azuresvirtualdesktop%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Egithub%3C%2FA%3E%20if%20you%20now%20want%20to%20deploy%20this%20yourself.%26nbsp%3B%20There%20are%20also%20some%20additional%20configuration%20files%20for%20other%20functionality%20that%20we%20hope%20to%20cover%20in%20further%20articles%20soon.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorEmilyMclaren_1%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22EmilyMclaren_3-1628763750433.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F302658iDA268EC27B82FE4F%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22EmilyMclaren_3-1628763750433.png%22%20alt%3D%22EmilyMclaren_3-1628763750433.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20Terraform%20is%20setup%20and%20you%20have%20created%20your%20Terraform%20templates%2C%20the%20first%20step%20is%20to%20initialize%20Terraform.%20This%20step%20ensures%20that%20Terraform%20has%20all%20the%20prerequisites%20to%20build%20your%20template%20in%20Azure.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Eterraform%20init%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThe%20next%20step%20is%20to%20have%20Terraform%20review%20and%20validate%20the%20template.%20This%20step%20compares%20the%20requested%20resources%20to%20the%20state%20information%20saved%20by%20Terraform%20and%20then%20outputs%20the%20planned%20execution.%20The%20Azure%20resources%20aren't%20created%20at%20this%20point.%20An%20execution%20plan%20is%20generated%20and%20stored%20in%20the%20file%20specified%20by%20the%20-out%20parameter.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20also%20need%20to%20pass%20our%20variable%20definitions%20file%20during%20the%20plan.%26nbsp%3B%26nbsp%3B%20We%20can%20either%20load%20it%20automatically%20by%20renaming%20env.tfvars%20as%20terraform.tfvars%20OR%20env.auto.tfvars.%20We%20then%20use%20the%20following%20to%20create%20the%20execution%20plan%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Eterraform%20plan%20-out%20terraform_azure.tfplan%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIf%20you%20don%E2%80%99t%20rename%20your%20variable%20file%2C%20use%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Eterraform%20plan%20-var-file%20defaults.tfvars%20-out%20terraform_azure.tfplan%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CSTRONG%3ENote%3A%26nbsp%3B%3C%2FSTRONG%3EWhen%20you're%20ready%20to%20build%20the%20infrastructure%20in%20Azure%2C%20apply%20the%20execution%20plan%20-%20this%20will%20deploy%20the%20resources%3A%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3Eterraform%20apply%20terraform_azure.tfplan%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIf%20you%20update%20the%20templates%20after%20you%20have%20deployed%2C%20you%20will%20need%20to%20rerun%20the%20plan%20and%20apply%20steps%20for%20them%20to%20reflect%20in%20Azure.%20%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--731072372%22%20id%3D%22toc-hId--731072313%22%3E%3CSTRONG%3ETroubleshooting%20Terraform%20deployment%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETerraform%20deployment%20can%20fail%20in%20three%20main%20categories%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EIssues%20with%20Terraform%20code%3C%2FLI%3E%0A%3CLI%3EIssues%20with%20Desired%20State%20Configuration%20(DSC)%3C%2FLI%3E%0A%3CLI%3EConflict%20with%20existing%20resources%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-1756440461%22%20id%3D%22toc-hId-1756440520%22%3E%3CSTRONG%3EIssues%20with%20Terraform%20code%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhile%20it%20is%20rare%20to%20have%20issues%20with%20the%20Terraform%20code%20it%20is%20still%20possible%2C%20however%20most%20often%20errors%20are%20due%20to%20bad%20input%20in%20variables.tf.%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EIf%20there%20are%20errors%20in%20the%20Terraform%20code%2C%20please%20file%20a%20GitHub%20issue.%3C%2FLI%3E%0A%3CLI%3EIf%20there%20are%20warning%20in%20the%20Terraform%20code%20feel%20free%20to%20ignore%20or%20address%20for%20your%20own%20instance%20of%20that%20code.%3C%2FLI%3E%0A%3CLI%3EUsing%20Terraform%20error%20messages%20it's%20a%20good%20starting%20point%20towards%20identifying%20issues%20with%20input%20variables%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CH2%20id%3D%22toc-hId--51014002%22%20id%3D%22toc-hId--51013943%22%3E%3CSTRONG%3EIssues%20with%20DSC%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20troubleshoot%20this%20type%20of%20issue%2C%20navigate%20to%20the%20Azure%20portal%20and%20if%20needed%20reset%20the%20password%20on%20the%20VM%20that%20failed%20DSC.%20Once%20you%20are%20able%20to%20log%20in%20to%20the%20VM%20review%20the%20log%20files%20following%20the%20guidance%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fscripting%2Fdsc%2Ftroubleshooting%2Ftroubleshooting%3Fview%3Dpowershell-7.1%23my-script-wont-run-using-dsc-logs-to-diagnose-script-errors%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ETroubleshooting%20DSC%20-%20PowerShell%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1858468465%22%20id%3D%22toc-hId--1858468406%22%3E%3CSTRONG%3EConflict%20with%20Existing%20resources%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20have%20previously%20deployed%20resources%20with%20the%20same%20name%2C%20you%20may%20see%20a%20deployment%20failure.%26nbsp%3B%20Deployment%20will%20stop%20if%20any%20failures%20occur.%20%26nbsp%3BYou%20can%20use%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETerraform%20destroy%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3ETo%20clean%20up%20resources%20that%20were%20created%20by%20the%20Terraform%20Apply%20command.%26nbsp%3B%20You%20can%20pass%20it%20the%20same%20options%20as%20the%20apply%20command.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20destroy%20command%20may%20fail%20trying%20to%20delete%20the%20subnet%20if%20associated%20resources%20have%20not%20been%20deleted%20first.%26nbsp%3B%20In%20this%20case%20you%20may%20need%20to%20manually%20delete%20resources%20associated%20with%20the%20subnet%20before%20running%20destroy%2C%20or%20you%20can%20delete%20the%20whole%20resource%20group%20manually.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-629044368%22%20id%3D%22toc-hId-629044427%22%3E%3CSTRONG%3E9.%20Final%20Configuration%3C%2FSTRONG%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%E2%80%99ll%20notice%20we%20didn%E2%80%99t%20configure%20the%20session%20hosts%20to%20use%20our%20profile%20storage%20at%20any%20point.%26nbsp%3B%20There%20is%20an%20assumption%20that%20we%20are%20using%20GPO%20to%20manage%20FSLogix%20across%20our%20host%20pools%20as%20documented%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Ffslogix%2Fuse-group-policy-templates-ht%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EUse%20FSLogix%20Group%20Policy%20Template%20Files%20-%20FSLogix%20%7C%20Microsoft%20Docs%3C%2FA%3E.%26nbsp%3B%20At%20a%20minimum%20you%E2%80%99ll%20need%20to%20configure%20the%20registry%20keys%20to%20enable%20FSLogix%20and%20configure%20the%20VHD%20Location%20to%20the%20NetApp%20Share%20URI%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Ffslogix%2Fprofile-container-configuration-reference%23enabled%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EProfile%20Container%20registry%20configuration%20settings%20-%20FSLogix%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20not%20using%20GPO%2C%20the%20registry%20keys%20could%20be%20manually%20added%20as%20part%20of%20the%20build%20to%20the%20session%20host.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20comment%20below%20if%20you%20have%20any%20questions%20or%20feedback!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

 

Deploying Azure Virtual Desktop with Terraform

 

This article has been written in collaboration with my colleagues @Jensheerin , @Stefan Georgiev and Julie NG.

 

Terraform is a tool that enables you to completely automate infrastructure builds through configuration files. It provides versioning for configurations, which makes it easy to deploy and maintain your existing Azure Virtual Desktop deployments on Microsoft Azure.

This article provides an overview of how to use Terraform to deploy a simple Azure Virtual Desktop environment.   This is to deploy ARM AVD, not AVD Classic.

 

There are several pre-requisites required to deploy Azure Virtual Desktop, which we will assume are already in place. 

  1. Ensure that you meet the requirements for Azure Virtual Desktop
  2. Terraform must be installed and configured as outlined here.

 

If you are completely new to Azure Virtual Desktop, please check them out here:

What is Azure Virtual Desktop? - Azure | Microsoft Docs

 

There are several topics that should be considered when creating a production Azure Virtual Desktop environment, that we haven’t been able to include in the scope of this article, such as security, monitoring, BCDR and image build.   This article aims to get you started with building a PoC for Azure Virtual Desktop via Terraform.  

 

All the code in this article can be found in the repo:

RDS-Templates/wvd-sh/terraform-azurerm-azuresvirtualdesktop at master · Azure/RDS-Templates (github....

 

 

Note: Terraform is an open source tool hosted in GitHub. As such, it is published "as is" with no implied support from Microsoft or any other organization. However, we would like to welcome you to open issues using GitHub issues to collaborate toward future improvements to the tool.

 

AVD Components

To deploy AVD we will need to understand what components are required.  We’re assuming that your pre-requisites are already in place. 

  • Active Directory - in this worked example, we are using ‘on-prem’ AD running on DCs in a separate VNet.  The code could easily be modified to use AADDS though.
  • Users in AAD that will be given access to AVD
  • A VM Image (or you can use a marketplace image)

Components we will deploy in this article

  • Virtual Desktop Environment
  • Networking Infrastructure
  • Session Hosts
  • Profile Storage
  • Role Based Access Control

Our architecture should look like the below once completed (sections in white are pre-reqs, grey will be deployed).

 

 

EmilyMclaren_5-1628763948083.png

 

Setting up Terraform

 

You’ll need to authenticate to Azure to run the templates – the steps to do that are here:

 

If you want to use Visual Studio Code please have a look at this article.

 

Once your environment is ready, we can start to understand how to deploy all of the required resources.

 

1. AVD environment

 

First up we will deploy the environment for Azure Virtual Desktop.  

 

In this section we will deploy the following resources:

 

  • Resource Group
  • Workspace
  • Hostpool
  • Hostpool registration expiration date (create a time_rotating resource)
  • Application Group (our DAG)
  • Application Group association to workspace

 

 

 

Before we create templates for the resources we need to configure the Azure Provider.

To do this we will create a providers.tf file and add the following:  

 

 

terraform {

  required_providers {

    azurerm = {

      source = "hashicorp/azurerm"

      version = ""~>2.0""

    }

  }

}

provider "azurerm" {

  features {}

}

 

The full code for provider.tf can be found here.

 

The Terraform documentation for AVD is here: azurerm_virtual_desktop_workspace | Resources | hashicorp/azurerm | Terraform Registry

 

Then to create the resources, first create main.tf and start adding resources in the format:

 

resource "azurerm_virtual_desktop_workspace" "workspace" {

  name                =  var.workspace

  location            =  var.deploy_location

  resource_group_name = azurerm_resource_group.rg.name

 

  friendly_name       = "${var.prefix} Workspace"

  description         = "${var.prefix} Workspace"

}

 

Note that there are several dependencies in the order that resources are created.  We can specify those using the following

 

depends_on          = [azurerm_virtual_desktop_host_pool.hostpool,azurerm_virtual_desktop_workspace.workspace]

 

In this case we are specifying the dependency for provisioning the Desktop Application group – that the hostpool and workspace must already exist before we try to create this resource.

 

We have also referenced some variables in here, so let’s create a variables.tf file for those now and add our variables.  They will be in the following form:

 

variable "deploy_location" {

  type        = string

  default     = "West Europe"

  description = "location"

}

 

We will also need to add variables for:

  • Resource group name
  • Prefix (this will be appended to resources such as session hosts)
  • Host pool name

 

 

A full list of the variables that are referenced are listed at the end of the article in step 7.

 

We can deploy at this point and it will create the basic AVD components, but no session hosts.

 

To add the session hosts, we need to ensure we can access Active Directory.   For this example we are assuming that we are using AD rather than AADDS.  We are also assuming you have a domain controller in an Azure VNet. 

 

 2. Networking infrastructure

 

We will create a new VNet for our session hosts and peer it to our AD VNet.  we’ve also included an NSG here with a sample rule – I’d strongly suggest modifying them to meet your own security requirements.

 

Components we will deploy here:

  • Session Host Virtual Network
  • Session Host Subnet
  • NSG
  • NSG – Subnet association
  • VNet Peering to Active Directory VNet

 

The full template can be found in networking.tf

 

The new concept we have here is using data to retrieve the properties of our existing Active Directory (Hub) VNet.  We can then pass the ID to new peering we are creating.

 

data "azurerm_virtual_network" "ad_vnet_data" {

  name = var.ad_vnet

  resource_group_name = var.ad_rg

}

 

resource "azurerm_virtual_network_peering" "peer1" {

  name                      = "peer_avd_ad"

  resource_group_name       = azurerm_resource_group.rg.name

  virtual_network_name      = azurerm_virtual_network.vnet.name

  remote_virtual_network_id = data.azurerm_virtual_network. ad_vnet_data.id

}

 

resource "azurerm_virtual_network_peering" "peer2" {

  name                      = "peer_avd_ad"

  resource_group_name       = var.ad_rg

  virtual_network_name      = var.ad_vnet

  remote_virtual_network_id = azurerm_virtual_network.vnet.id

}

 

Again, we can see that we have referenced several variables, so you’ll need to add the following to your variables.tf file:

 

  • ad_vnet  – the name of the VNet containing our Domain Controllers
  • ad_rg  - resource group containing DCs
  • dns_servers – custom DNS servers that we’re using for our new VNet
  • vnet_range – Address range for our new VNet
  • subnet_range - Address range for our new subnet

 

 

Now we should have all our basic infrastructure in place, we can move onto the session hosts.

 

3. Session Hosts

 

Here we are deploying and configuring our session hosts.  In this example, we will create a new Terraform config file, host.tf to do this.  Full code is here. We will also add our variables to the variables.tf file.

 

Components to deploy in this section:

  • NIC for each session host
  • Session Host VM(s)
  • Domain-join VM extension
  • Dsc VM extension to register session host
  • Random strong for local vm password
  • Local variable for registration token

 

This part is slightly more complex than the infrastructure deployment.   The new concepts in this section are covered below.

 

We firstly need to create a local variable for our registration_info token to allow us to register the VM to the host pool.  This is later passed as a protected setting to the dsc extension resource.

 

locals {

  registration_token = azurerm_virtual_desktop_host_pool.hostpool.registration_info[0].token

}

 

We’re also creating a random local password – which needs to meet the AVD requirements:

 

resource "random_string" "avd_local_password" {

  count            = "${var.rdsh_count}"

  length           = 16

  special          = true

  min_special      = 2

  override_special = "*!@#?"

}

 

In the password section you will see us referencing rdshcount.  This allows us to deploy a variable number of VMs to our host pool.  Using this counter will be used for the VM, the NICs, local passwords and the extensions.  We are also using the count meta-argument to refer to specific instances:

 

resource "azurerm_windows_virtual_machine" "avd_vm" {

  count                 = "${var.rdsh_count}"

  name                  = "${var.prefix}-${count.index + 1}"

  resource_group_name   = var.rg_name

  location              = var.deploy_location

  size                  = var.vm_size

  network_interface_ids = ["${azurerm_network_interface.AVD_vm_nic.*.id[count.index]}"]

  provision_vm_agent    = true

    admin_username = "${var.local_admin_username}"

    admin_password = "${random_string.AVD-local-password.*.result[count.index]}"

 

  os_disk {

    name                 = "${lower(var.prefix)}-${count.index +1}"

    caching              = "ReadWrite"

    storage_account_type = "Standard_LRS"

  }

 

  source_image_reference {

    publisher = "MicrosoftWindowsDesktop"

    offer     = "Windows-10"

    sku       = "20h2-evd"                                

    version   = "latest"

  }

depends_on = [azurerm_resource_group.rg, azurerm_network_interface.AVD_vm_nic]

}

 

The VM resource is also where we specific the source image for the build. If you need a different market place image you can get the image SKU details using:

 

Get-AzVMImageSku -Location <location> -PublisherName MicrosoftWindowsDesktop -Offer windows-10

 

(or -Offer office-365 if you want the image including M365 apps).

 

Deploying a custom image with the shared image gallery is a topic for a follow up article.

 

The additional variables we need to specify now are:

 

  • rdsh_count
  • domain_name
  • domain_user_upn
  • domain_password
  • vm_size
  • ou_path
  • local_admin_username

 

 

4. Profile Storage

 

For this example we’ll deploy our profile storage using Azure Files.   Step 6 has the steps to configure NetApp Files if you prefer this option. 

 

To do this we’ll need to deploy the following resources:

  • A dedicated resource group for our Storage account
  • Azure File Storage account
  • Azure Storage Share
  • Assign AAD group to the Storage (Storage File Data SMB Share Contributor)

We will deploy a new resource group.   We are using a random string to generate a globally unique name for our Storage account.

 

We are creating a file called afstorage.tf for this (and the full code is included here).

 

We are appending a random string to the storage account name to ensure uniqueness – as such we also use the output command so that we can see the name of our new storage account.  We can use the outputs.tf file to define our outputs.

 

output "storage_account_name" {

  value = azurerm_storage_account.storage.name

 }

 

Further configuration will be needed to enable AD authentication if you choose that direction and to configure NTFS permissions of SMB

 

 

5. RBAC

 

Now that we have all our infrastructure deployed, let us give our users access.  Again, we will create a new config file for this – rbac.tf.

 

This can also be modified to assign users to custom roles, or to the other desktop virtualization roles that are already built in: Built-in roles Azure Virtual Desktop - Azure | Microsoft Docs

 

The components we’re creating here are:

  • Azure Active Directory Group
  • AAD group member
  • AAD role assignment

 

 

Before we start, we’ll need to add the azuread provider to our list of required providers in our provider.tf as we need to use this for some of the AAD resources.

 

terraform {

  required_providers {

    azurerm = {

      source = "hashicorp/azurerm"

      version = "~>2.0"

    }

    azuread = {

      source = "hashicorp/azuread"

    }

  }

}

 

To assign the RBAC permissions we need to pass a list of existing AAD Users and then add these to a new AAD group that we are creating.

 

We will use the AzureAD_user and azurerm_role_definition datasources to retrieve information about our users and the role we’re assigning (in this case the builtin Desktop Virtualization user).

 

 

data "azuread_user" "aad_user" {

  for_each            = toset(var.avd_users)

  user_principal_name = format("%s", each.key)

}

 

data "azurerm_role_definition" "role_def" {

  name = "Desktop Virtualization User"

}

 

We’re also going to use for_each to loop through that list of users (both when getting the UPN from AAD and when adding to the group).

 

resource "azuread_group_member" "aad_group_member" {

  for_each         = data.azuread_user.aad_user

  group_object_id  = azuread_group.aad_group.id

  member_object_id = each.value["id"]

}

 

Lastly we’ll scope the role assignment to the application group we created at the start and apply it to the group containing our users.

 

resource "azurerm_role_assignment" "role" {

  scope              = azurerm_virtual_desktop_application_group.dag.id

  role_definition_id = data.azurerm_role_definition.role_def.id

  principal_id       = azuread_group.aad_group.id

}

 

 

We also need to add the 2 new variables:

  • aad_group_name
  • avd_users

 

avd_users will be an array to allow us to pass multiple users.  Up to now we have either specified default values for our variables or will pass them during deployment.  To make things simpler we will create an env.tfvars file to pass our environment specific variables.   You can add as many (or few) pre-configured variables here, but keep security in mind if you are putting confidential data in there.

 

A sample might look like:

 

deploy_location = "west europe"

rg_name         = "avd-resources-rg"

 

vnet_range =  ["10.1.0.0/16"]

subnet_range = ["10.1.0.0/24"]

 

prefix = "avd"

 

avd_users = [

  "user1@<domain>.com",

  "user2@<domain>.com"

]

dns_servers = ["10.0.0.4", "168.63.129.16"]

 

 

 

6. NetApp Storage

 

As an alternate to Azure Files you also have the option to deploy NetApp Storage for Azure Virtual Desktop profiles. To use NetApp Files you need to request access Register for Azure NetApp Files | Microsoft Docs.

 

 

To deploy the storage we’ll need to deploy the following resources:

  • A dedicated subnet for NetApp
  • NetApp storage Account
  • NetApp storage Pool
  • NetApp storage Volume

 

For simplicity we’ll deploy our subnet to the same Vnet we created earlier, and will use the same resource group and location variables.   You may want separate resource groups and/or more complex networking in a production deployment.

 

We are creating a file called netappstorage.tf for this and the full code can be found in the folder options/netapp.

 

We also need to add some new variables (and you’ll probably want to update the default values as well):

 

  • NetApp_acct_name
  • NetApp_pool_name
  • NetApp_volume_name
  • NetApp_smb_name
  • NetApp_volume_path
  • NetApp_subnet_name
  • NetApp_Address

 

 

 

Now we should have created 9 Files:

  • Main.tf
  • Networking.tf
  • Host.tf
  • afstorage.tf (or netappstorage.tf)
  • Rbac.tf
  • Variables.tf
  • defaults.tfvars
  • Outputs.tf
  • Providers.tf

 

 

7. Variables

 

All of the variables that we have referenced so far are described here (they are also in variables.tf)

 

Name

Description

Default

rg_name

Name of the Resource Group in which to deploy these resources

AVD-TF

deploy_location

 

West Europe

hostpool

Name of the Azure Virtual Desktop host pool

AVD-TF-HP

ad_vnet

Name of domain controller VNet

-

dns_servers

Custom DNS configuration

-

vnet_range

Address range for deployment VNet

-

subnet_range

Address range for session host subnet

-

avd_users

The resource group for AD VM

[]

aad_group_name

Azure Active Directory Group for AVD users

-

rdsh_count

Number of AVD machines to deploy

2

prefix

Prefix of the name of the AVD machine(s)

-

domain_name

Name of the domain to join

-

domain_user_upn

Username for domain join (do not include domain name as this is appended

-

domain_password

Password of the user to authenticate with the domain

-

vm_size

Size of the machine to deploy

Standard_DS2_v2

ou_path

The ou path for AD

""

local_admin_username

The local admin username for the VM

-

netapp_acct_name

The NetApp account name

AVD_NetApp

netapp_pool_name

The NetApp pool name

AVD_NetApp_pool

netappvolumename

The NetApp volume name

AVD_NetApp_volume

netapp_smb_name

The NetApp smb name

AVDNetApp

netapp_volume_path

The NetApp volume path

AVDNetAppVolume

netapp_subnet_name

The NetApp subnet name

NetAppSubnet

netapp_address

The Address range for NetApp Subnet

-

 

Note: Variables in italic are optional and only needed if you are deploying NetApp Files, these are included only in the variables template in the netapp folder.

 

8. Deploy!

 

The templates can be downloaded from github if you now want to deploy this yourself.  There are also some additional configuration files for other functionality that we hope to cover in further articles soon.

 

 

EmilyMclaren_3-1628763750433.png

 

 

 

Once Terraform is setup and you have created your Terraform templates, the first step is to initialize Terraform. This step ensures that Terraform has all the prerequisites to build your template in Azure.

 

terraform init

 

The next step is to have Terraform review and validate the template. This step compares the requested resources to the state information saved by Terraform and then outputs the planned execution. The Azure resources aren't created at this point. An execution plan is generated and stored in the file specified by the -out parameter.

 

We also need to pass our variable definitions file during the plan.   We can either load it automatically by renaming env.tfvars as terraform.tfvars OR env.auto.tfvars. We then use the following to create the execution plan:

 

terraform plan -out terraform_azure.tfplan

 

If you don’t rename your variable file, use:

 

terraform plan -var-file defaults.tfvars -out terraform_azure.tfplan

 

Note: When you're ready to build the infrastructure in Azure, apply the execution plan - this will deploy the resources:

 

terraform apply terraform_azure.tfplan

 

If you update the templates after you have deployed, you will need to rerun the plan and apply steps for them to reflect in Azure.  

 

Troubleshooting Terraform deployment

 

Terraform deployment can fail in three main categories:

  1. Issues with Terraform code
  2. Issues with Desired State Configuration (DSC)
  3. Conflict with existing resources

 

Issues with Terraform code

 

While it is rare to have issues with the Terraform code it is still possible, however most often errors are due to bad input in variables.tf.

  • If there are errors in the Terraform code, please file a GitHub issue.
  • If there are warning in the Terraform code feel free to ignore or address for your own instance of that code.
  • Using Terraform error messages it's a good starting point towards identifying issues with input variables

Issues with DSC

 

To troubleshoot this type of issue, navigate to the Azure portal and if needed reset the password on the VM that failed DSC. Once you are able to log in to the VM review the log files following the guidance here: Troubleshooting DSC - PowerShell | Microsoft Docs

 

Conflict with Existing resources

 

If you have previously deployed resources with the same name, you may see a deployment failure.  Deployment will stop if any failures occur.  You can use:

Terraform destroy

To clean up resources that were created by the Terraform Apply command.  You can pass it the same options as the apply command.

 

The destroy command may fail trying to delete the subnet if associated resources have not been deleted first.  In this case you may need to manually delete resources associated with the subnet before running destroy, or you can delete the whole resource group manually.

 

 

 

9. Final Configuration

 

You’ll notice we didn’t configure the session hosts to use our profile storage at any point.  There is an assumption that we are using GPO to manage FSLogix across our host pools as documented here: Use FSLogix Group Policy Template Files - FSLogix | Microsoft Docs.  At a minimum you’ll need to configure the registry keys to enable FSLogix and configure the VHD Location to the NetApp Share URI: Profile Container registry configuration settings - FSLogix | Microsoft Docs

 

If not using GPO, the registry keys could be manually added as part of the build to the session host.

 

Please comment below if you have any questions or feedback!

0 Replies