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 {
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" {
@ -10,11 +10,16 @@ resource "random_string" "AVD_local_password" {
override_special = "*!@#?"
}
resource "azurerm_resource_group" "rg" {
name = var.rg
location = var.resource_group_location
}
resource "azurerm_network_interface" "avd_vm_nic" {
count = var.rdsh_count
name = "${var.prefix}-${count.index + 1}-nic"
resource_group_name = var.rg_name
location = var.deploy_location
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
ip_configuration {
name = "nic${count.index + 1}_config"
@ -30,8 +35,8 @@ resource "azurerm_network_interface" "avd_vm_nic" {
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
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
size = var.vm_size
network_interface_ids = ["${azurerm_network_interface.avd_vm_nic.*.id[count.index]}"]
provision_vm_agent = true

View File

@ -1,5 +1,5 @@
resource "azurerm_resource_group" "log" {
name = "${var.shared}-resources"
name = var.rg_shared_name
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 "random_pet" "rg-name" {
prefix = var.resource_group_name_prefix
}
resource "azurerm_resource_group" "rg" {
name = random_pet.rg-name.id
location = var.resource_group_location
resource "azurerm_resource_group" "sh" {
name = var.rg_name
location = var.resource_group_location
}
# Create AVD workspace
resource "azurerm_virtual_desktop_workspace" "workspace" {
name = var.workspace
resource_group_name = azurerm_resource_group.rg.name
location = var.deploy_location
resource_group_name = azurerm_resource_group.sh.name
location = azurerm_resource_group.sh.location
friendly_name = "${var.prefix} Workspace"
description = "${var.prefix} Workspace"
}
# Create AVD host pool
resource "azurerm_virtual_desktop_host_pool" "hostpool" {
resource_group_name = azurerm_resource_group.rg.name
location = var.deploy_location
resource_group_name = azurerm_resource_group.sh.name
location = azurerm_resource_group.sh.location
name = var.hostpool
friendly_name = var.hostpool
validate_environment = true
@ -29,22 +25,18 @@ resource "azurerm_virtual_desktop_host_pool" "hostpool" {
type = "Pooled"
maximum_sessions_allowed = 16
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" {
hostpool_id = azurerm_virtual_desktop_host_pool.hostpool.id
expiration_date = time_rotating.avd_token.rfc3339
expiration_date = var.rfc3339
}
# Create AVD 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
location = var.deploy_location
location = azurerm_resource_group.sh.location
type = "Desktop"
name = "${var.prefix}-dag"
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
resource "azurerm_subnet" "netapp_subnet" {
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
address_prefixes = var.netapp_address
@ -17,7 +17,7 @@ resource "azurerm_subnet" "netapp_subnet" {
resource "azurerm_netapp_account" "netapp_acct" {
name = var.netapp_acct_name
resource_group_name = var.rg_name
resource_group_name = var.rg_stor
location = var.deploy_location
active_directory {
@ -37,7 +37,7 @@ resource "azurerm_netapp_account" "netapp_acct" {
resource "azurerm_netapp_pool" "netapp_pool" {
name = var.netapp_pool_name
location = var.deploy_location
resource_group_name = var.rg_name
resource_group_name = var.rg_stor
account_name = var.netapp_acct_name
service_level = "Standard"
size_in_tb = 4
@ -54,7 +54,7 @@ resource "azurerm_netapp_volume" "NetApp_Vol" {
name = var.netapp_volume_name
location = var.deploy_location
resource_group_name = var.rg_name
resource_group_name = var.rg_stor
account_name = var.netapp_acct_name
pool_name = var.netapp_pool_name
volume_path = var.netapp_volume_path

View File

@ -1,14 +1,21 @@
output "resource_group_name" {
description = "Name of the Resource group created"
output "azure_virtual_desktop_compute_resource_group" {
description = "Name of the Resource group in which to deploy session host"
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" {
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" {
value = azurerm_virtual_desktop_workspace.workspace.name
description = "Name of the Azure Virtual Desktop workspace"
value = azurerm_virtual_desktop_workspace.workspace.name
}
output "location" {
@ -16,12 +23,17 @@ output "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" {
description = "Name of the Azure File Share created for FSLogix"
value = azurerm_storage_share.FSShare.name
}
output "rdshcount" {
output "session_host_count" {
description = "The number of VMs created"
value = var.rdsh_count
}
@ -34,14 +46,9 @@ output "dnsservers" {
output "vnetrange" {
description = "Address range for deployment vnet"
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"
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" {
display_name = var.aad_group_name
display_name = var.aad_group_name
security_enabled = true
}

View File

@ -1,14 +1,23 @@
resource "azurerm_resource_group" "sigrg" {
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
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/shared_image_gallery
resource "azurerm_shared_image_gallery" "sig" {
name = "AVDTFsig"
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
name = "sig${random_string.random.id}"
resource_group_name = azurerm_resource_group.sigrg.name
location = azurerm_resource_group.sigrg.location
description = "Shared images"
tags = {
@ -22,8 +31,8 @@ resource "azurerm_shared_image_gallery" "sig" {
resource "azurerm_shared_image" "example" {
name = "avd-image"
gallery_name = azurerm_shared_image_gallery.sig.name
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.sigrg.name
location = azurerm_resource_group.sigrg.location
os_type = "Windows"
identifier {

View File

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