This commit is contained in:
Jen Sheerin 2022-03-28 22:05:53 -04:00
parent b562c8a2fc
commit a2399f96b5
8 changed files with 96 additions and 63 deletions

View File

@ -1,5 +1,5 @@
locals { locals {
registration_token = azurerm_virtual_desktop_host_pool.hostpool.registration_info[0].token registration_token = azurerm_virtual_desktop_host_pool_registration_info.registrationinfo.token
} }
resource "random_string" "AVD_local_password" { resource "random_string" "AVD_local_password" {
@ -10,11 +10,16 @@ resource "random_string" "AVD_local_password" {
override_special = "*!@#?" override_special = "*!@#?"
} }
resource "azurerm_resource_group" "rg" {
name = var.rg
location = var.resource_group_location
}
resource "azurerm_network_interface" "avd_vm_nic" { resource "azurerm_network_interface" "avd_vm_nic" {
count = var.rdsh_count count = var.rdsh_count
name = "${var.prefix}-${count.index + 1}-nic" name = "${var.prefix}-${count.index + 1}-nic"
resource_group_name = var.rg_name resource_group_name = azurerm_resource_group.rg.name
location = var.deploy_location location = azurerm_resource_group.rg.location
ip_configuration { ip_configuration {
name = "nic${count.index + 1}_config" name = "nic${count.index + 1}_config"
@ -30,8 +35,8 @@ resource "azurerm_network_interface" "avd_vm_nic" {
resource "azurerm_windows_virtual_machine" "avd_vm" { resource "azurerm_windows_virtual_machine" "avd_vm" {
count = var.rdsh_count count = var.rdsh_count
name = "${var.prefix}-${count.index + 1}" name = "${var.prefix}-${count.index + 1}"
resource_group_name = var.rg_name resource_group_name = azurerm_resource_group.rg.name
location = var.deploy_location location = azurerm_resource_group.rg.location
size = var.vm_size size = var.vm_size
network_interface_ids = ["${azurerm_network_interface.avd_vm_nic.*.id[count.index]}"] network_interface_ids = ["${azurerm_network_interface.avd_vm_nic.*.id[count.index]}"]
provision_vm_agent = true provision_vm_agent = true

View File

@ -1,5 +1,5 @@
resource "azurerm_resource_group" "log" { resource "azurerm_resource_group" "log" {
name = "${var.shared}-resources" name = var.rg_shared_name
location = var.deploy_location location = var.deploy_location
} }

View File

@ -1,26 +1,22 @@
# Randomization of resource group name.
# Resource group name is output when execution plan is applied. # Resource group name is output when execution plan is applied.
resource "random_pet" "rg-name" { resource "azurerm_resource_group" "sh" {
prefix = var.resource_group_name_prefix name = var.rg_name
} location = var.resource_group_location
resource "azurerm_resource_group" "rg" {
name = random_pet.rg-name.id
location = var.resource_group_location
} }
# Create AVD workspace # Create AVD workspace
resource "azurerm_virtual_desktop_workspace" "workspace" { resource "azurerm_virtual_desktop_workspace" "workspace" {
name = var.workspace name = var.workspace
resource_group_name = azurerm_resource_group.rg.name resource_group_name = azurerm_resource_group.sh.name
location = var.deploy_location location = azurerm_resource_group.sh.location
friendly_name = "${var.prefix} Workspace" friendly_name = "${var.prefix} Workspace"
description = "${var.prefix} Workspace" description = "${var.prefix} Workspace"
} }
# Create AVD host pool # Create AVD host pool
resource "azurerm_virtual_desktop_host_pool" "hostpool" { resource "azurerm_virtual_desktop_host_pool" "hostpool" {
resource_group_name = azurerm_resource_group.rg.name resource_group_name = azurerm_resource_group.sh.name
location = var.deploy_location location = azurerm_resource_group.sh.location
name = var.hostpool name = var.hostpool
friendly_name = var.hostpool friendly_name = var.hostpool
validate_environment = true validate_environment = true
@ -29,22 +25,18 @@ resource "azurerm_virtual_desktop_host_pool" "hostpool" {
type = "Pooled" type = "Pooled"
maximum_sessions_allowed = 16 maximum_sessions_allowed = 16
load_balancer_type = "DepthFirst" #[BreadthFirst DepthFirst] load_balancer_type = "DepthFirst" #[BreadthFirst DepthFirst]
# Create registration info
resource "time_rotating" "avd_token" {
rotation_days = 30
} }
resource "azurerm_virtual_desktop_host_pool_registration_info" "registrationinfo" { resource "azurerm_virtual_desktop_host_pool_registration_info" "registrationinfo" {
hostpool_id = azurerm_virtual_desktop_host_pool.hostpool.id hostpool_id = azurerm_virtual_desktop_host_pool.hostpool.id
expiration_date = time_rotating.avd_token.rfc3339 expiration_date = var.rfc3339
} }
# Create AVD DAG # Create AVD DAG
resource "azurerm_virtual_desktop_application_group" "dag" { resource "azurerm_virtual_desktop_application_group" "dag" {
resource_group_name = azurerm_resource_group.rg.name resource_group_name = azurerm_resource_group.sh.name
host_pool_id = azurerm_virtual_desktop_host_pool.hostpool.id host_pool_id = azurerm_virtual_desktop_host_pool.hostpool.id
location = var.deploy_location location = azurerm_resource_group.sh.location
type = "Desktop" type = "Desktop"
name = "${var.prefix}-dag" name = "${var.prefix}-dag"
friendly_name = "Desktop AppGroup" friendly_name = "Desktop AppGroup"

View File

@ -2,7 +2,7 @@
# Set up Azure NetApp Files https://docs.microsoft.com/en-us/azure/azure-netapp-files/azure-netapp-files-quickstart-set-up-account-create-volumes?tabs=azure-portal # Set up Azure NetApp Files https://docs.microsoft.com/en-us/azure/azure-netapp-files/azure-netapp-files-quickstart-set-up-account-create-volumes?tabs=azure-portal
resource "azurerm_subnet" "netapp_subnet" { resource "azurerm_subnet" "netapp_subnet" {
name = var.netapp_subnet_name name = var.netapp_subnet_name
resource_group_name = var.rg_name resource_group_name = var.rg_stor
virtual_network_name = azurerm_virtual_network.vnet.name virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = var.netapp_address address_prefixes = var.netapp_address
@ -17,7 +17,7 @@ resource "azurerm_subnet" "netapp_subnet" {
resource "azurerm_netapp_account" "netapp_acct" { resource "azurerm_netapp_account" "netapp_acct" {
name = var.netapp_acct_name name = var.netapp_acct_name
resource_group_name = var.rg_name resource_group_name = var.rg_stor
location = var.deploy_location location = var.deploy_location
active_directory { active_directory {
@ -37,7 +37,7 @@ resource "azurerm_netapp_account" "netapp_acct" {
resource "azurerm_netapp_pool" "netapp_pool" { resource "azurerm_netapp_pool" "netapp_pool" {
name = var.netapp_pool_name name = var.netapp_pool_name
location = var.deploy_location location = var.deploy_location
resource_group_name = var.rg_name resource_group_name = var.rg_stor
account_name = var.netapp_acct_name account_name = var.netapp_acct_name
service_level = "Standard" service_level = "Standard"
size_in_tb = 4 size_in_tb = 4
@ -54,7 +54,7 @@ resource "azurerm_netapp_volume" "NetApp_Vol" {
name = var.netapp_volume_name name = var.netapp_volume_name
location = var.deploy_location location = var.deploy_location
resource_group_name = var.rg_name resource_group_name = var.rg_stor
account_name = var.netapp_acct_name account_name = var.netapp_acct_name
pool_name = var.netapp_pool_name pool_name = var.netapp_pool_name
volume_path = var.netapp_volume_path volume_path = var.netapp_volume_path

View File

@ -1,14 +1,21 @@
output "resource_group_name" { output "azure_virtual_desktop_compute_resource_group" {
description = "Name of the Resource group created" description = "Name of the Resource group in which to deploy session host"
value = azurerm_resource_group.rg.name value = azurerm_resource_group.rg.name
} }
output "azure_virtual_desktop_host_pool" {
description = "Name of the Azure Virtual Desktop host pool"
value = azurerm_virtual_desktop_host_pool.hostpool.name
}
output "azurerm_virtual_desktop_application_group" { output "azurerm_virtual_desktop_application_group" {
value = azurerm_virtual_desktop_application_group.dag.name description = "Name of the Azure Virtual Desktop DAG"
value = azurerm_virtual_desktop_application_group.dag.name
} }
output "azurerm_virtual_desktop_workspace" { output "azurerm_virtual_desktop_workspace" {
value = azurerm_virtual_desktop_workspace.workspace.name description = "Name of the Azure Virtual Desktop workspace"
value = azurerm_virtual_desktop_workspace.workspace.name
} }
output "location" { output "location" {
@ -16,12 +23,17 @@ output "location" {
value = azurerm_resource_group.rg.location value = azurerm_resource_group.rg.location
} }
output "storage_account" {
description = "Storage account for Profiles"
value = azurerm_storage_account.storage.name
}
output "storage_account_share" { output "storage_account_share" {
description = "Name of the Azure File Share created for FSLogix" description = "Name of the Azure File Share created for FSLogix"
value = azurerm_storage_share.FSShare.name value = azurerm_storage_share.FSShare.name
} }
output "rdshcount" { output "session_host_count" {
description = "The number of VMs created" description = "The number of VMs created"
value = var.rdsh_count value = var.rdsh_count
} }
@ -34,14 +46,9 @@ output "dnsservers" {
output "vnetrange" { output "vnetrange" {
description = "Address range for deployment vnet" description = "Address range for deployment vnet"
value = azurerm_virtual_network.vnet.address_space value = azurerm_virtual_network.vnet.address_space
}
output "avdusers" {
description = "AVD users"
value = azuread_group.aad_group.members
} }
output "aadgroupname" { output "AVD_user_groupname" {
description = "Azure Active Directory Group for AVD users" description = "Azure Active Directory Group for AVD users"
value = azuread_group.aad_group.display_name value = azuread_group.aad_group.display_name
} }

View File

@ -8,7 +8,7 @@ data "azurerm_role_definition" "role" { # access an existing built-in role
} }
resource "azuread_group" "aad_group" { resource "azuread_group" "aad_group" {
display_name = var.aad_group_name display_name = var.aad_group_name
security_enabled = true security_enabled = true
} }

View File

@ -1,14 +1,23 @@
resource "azurerm_resource_group" "sigrg" { resource "azurerm_resource_group" "sigrg" {
location = var.deploy_location location = var.deploy_location
name = "${var.prefix}-rg" name = var.rg_shared_name
} }
# generate a random string (consisting of four characters)
# https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string
resource "random_string" "rando" {
length = 4
upper = false
special = false
}
# Creates Shared Image Gallery # Creates Shared Image Gallery
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/shared_image_gallery # https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/shared_image_gallery
resource "azurerm_shared_image_gallery" "sig" { resource "azurerm_shared_image_gallery" "sig" {
name = "AVDTFsig" name = "sig${random_string.random.id}"
resource_group_name = azurerm_resource_group.rg.name resource_group_name = azurerm_resource_group.sigrg.name
location = azurerm_resource_group.rg.location location = azurerm_resource_group.sigrg.location
description = "Shared images" description = "Shared images"
tags = { tags = {
@ -22,8 +31,8 @@ resource "azurerm_shared_image_gallery" "sig" {
resource "azurerm_shared_image" "example" { resource "azurerm_shared_image" "example" {
name = "avd-image" name = "avd-image"
gallery_name = azurerm_shared_image_gallery.sig.name gallery_name = azurerm_shared_image_gallery.sig.name
resource_group_name = azurerm_resource_group.rg.name resource_group_name = azurerm_resource_group.sigrg.name
location = azurerm_resource_group.rg.location location = azurerm_resource_group.sigrg.location
os_type = "Windows" os_type = "Windows"
identifier { identifier {

View File

@ -1,16 +1,30 @@
variable "resource_group_name_prefix" { variable "resource_group_location" {
default = "rg" default = "eastus"
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." description = "Location of the resource group."
} }
variable "resource_group_location" { variable "rg" {
default = "eastus" type = string
description = "Location of the resource group." default = "rg-avd-compute"
description = "Name of the Resource group in which to deploy session host"
} }
variable "rg_name" { variable "rg_name" {
type = string type = string
default = "avd-resources-rg" default = "rg-avd-resources"
description = "Name of the Resource group in which to deploy these resources" description = "Name of the Resource group in which to deploy service objects"
}
variable "rg_stor" {
type = string
default = "rg-avd-storage"
description = "Name of the Resource group in which to deploy storage"
}
variable "rg_shared_name" {
type = string
default = "rg-shared-resources"
description = "Name of the Resource group in which to deploy shared resources"
} }
variable "deploy_location" { variable "deploy_location" {
@ -37,6 +51,13 @@ variable "ad_vnet" {
description = "Name of domain controller vnet" description = "Name of domain controller vnet"
} }
variable "rfc3339" {
type = string
default = "2022-03-30T12:43:13Z"
description = "Registration token expiration"
}
variable "dns_servers" { variable "dns_servers" {
type = list(string) type = list(string)
default = ["10.0.1.4", "168.63.129.16"] default = ["10.0.1.4", "168.63.129.16"]
@ -45,12 +66,12 @@ variable "dns_servers" {
variable "vnet_range" { variable "vnet_range" {
type = list(string) type = list(string)
default = ["10.1.0.0/16"] default = ["10.2.0.0/16"]
description = "Address range for deployment VNet" description = "Address range for deployment VNet"
} }
variable "subnet_range" { variable "subnet_range" {
type = list(string) type = list(string)
default = ["10.1.0.0/24"] default = ["10.2.0.0/24"]
description = "Address range for session host subnet" description = "Address range for session host subnet"
} }
@ -63,8 +84,8 @@ variable "ad_rg" {
variable "avd_users" { variable "avd_users" {
description = "AVD users" description = "AVD users"
default = [ default = [
"avduser01@infra.local", "avduser01@contoso.net",
"avduser01@infra.local" "avduser02@contoso.net"
] ]
} }
@ -93,7 +114,7 @@ variable "domain_name" {
variable "domain_user_upn" { variable "domain_user_upn" {
type = string type = string
default = "admin" # do not include domain name as this is appended default = "domainjoineruser" # do not include domain name as this is appended
description = "Username for domain join (do not include domain name as this is appended)" description = "Username for domain join (do not include domain name as this is appended)"
} }
@ -149,8 +170,7 @@ variable "netapp_volume_path" {
variable "netapp_subnet_name" { variable "netapp_subnet_name" {
default = "NetAppSubnet" default = "NetAppSubnet"
} }
variable "netapp_address" { variable "netapp_address" {
default = ["10.1.1.0/24"] default = ["10.1.1.0/24"]
description = "Address range for NetApp Subnet" description = "Address range for NetApp Subnet"
} }