refactor code
This commit is contained in:
parent
64aa77f9f8
commit
d0af975d18
@ -1,7 +1,11 @@
|
|||||||
# Create AVD Resource Group
|
# 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" {
|
resource "azurerm_resource_group" "rg" {
|
||||||
name = var.rg_name
|
name = random_pet.rg-name.id
|
||||||
location = var.deploy_location
|
location = var.resource_group_location
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create AVD workspace
|
# Create AVD workspace
|
||||||
@ -13,10 +17,6 @@ resource "azurerm_virtual_desktop_workspace" "workspace" {
|
|||||||
description = "${var.prefix} Workspace"
|
description = "${var.prefix} Workspace"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "time_rotating" "avd_token" {
|
|
||||||
rotation_days = 30
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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.rg.name
|
||||||
@ -30,9 +30,14 @@ resource "azurerm_virtual_desktop_host_pool" "hostpool" {
|
|||||||
maximum_sessions_allowed = 16
|
maximum_sessions_allowed = 16
|
||||||
load_balancer_type = "DepthFirst" #[BreadthFirst DepthFirst]
|
load_balancer_type = "DepthFirst" #[BreadthFirst DepthFirst]
|
||||||
|
|
||||||
registration_info {
|
|
||||||
expiration_date = time_rotating.avd_token.rotation_rfc3339
|
# 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
|
||||||
}
|
}
|
||||||
|
|
||||||
# Create AVD DAG
|
# Create AVD DAG
|
||||||
|
@ -3,6 +3,14 @@ output "resource_group_name" {
|
|||||||
value = azurerm_resource_group.rg.name
|
value = azurerm_resource_group.rg.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "azurerm_virtual_desktop_application_group" {
|
||||||
|
value = azurerm_virtual_desktop_application_group.dag.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "azurerm_virtual_desktop_workspace" {
|
||||||
|
value = azurerm_virtual_desktop_workspace.workspace.name
|
||||||
|
}
|
||||||
|
|
||||||
output "location" {
|
output "location" {
|
||||||
description = "The Azure region"
|
description = "The Azure region"
|
||||||
value = azurerm_resource_group.rg.location
|
value = azurerm_resource_group.rg.location
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
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 "rg_name" {
|
variable "rg_name" {
|
||||||
type = string
|
type = string
|
||||||
default = "avd-resources-rg"
|
default = "avd-resources-rg"
|
||||||
@ -6,7 +15,7 @@ variable "rg_name" {
|
|||||||
|
|
||||||
variable "deploy_location" {
|
variable "deploy_location" {
|
||||||
type = string
|
type = string
|
||||||
default = "east us"
|
default = "eastus"
|
||||||
description = "The Azure Region in which all resources in this example should be created."
|
description = "The Azure Region in which all resources in this example should be created."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
## Create a Resource Group for Storage
|
## Create a Resource Group for Storage
|
||||||
resource "azurerm_resource_group" "rg_storage" {
|
resource "azurerm_resource_group" "rg_storage" {
|
||||||
location = "east us"
|
location = var.deploy_location
|
||||||
name = "af-storage-rg"
|
name = var.rg_stor
|
||||||
}
|
}
|
||||||
|
|
||||||
# generate a random string (consisting of four characters)
|
# generate a random string (consisting of four characters)
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,26 +1,22 @@
|
|||||||
# Create AVD Resource Group
|
# Resource group name is output when execution plan is applied.
|
||||||
resource "azurerm_resource_group" "rg" {
|
resource "azurerm_resource_group" "sh" {
|
||||||
name = var.rg_name
|
name = var.rg_name
|
||||||
location = var.deploy_location
|
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"
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "time_rotating" "avd_token" {
|
|
||||||
rotation_days = 30
|
|
||||||
}
|
|
||||||
|
|
||||||
# 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,17 +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]
|
||||||
|
}
|
||||||
|
|
||||||
registration_info {
|
resource "azurerm_virtual_desktop_host_pool_registration_info" "registrationinfo" {
|
||||||
expiration_date = time_rotating.avd_token.rotation_rfc3339
|
hostpool_id = azurerm_virtual_desktop_host_pool.hostpool.id
|
||||||
}
|
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"
|
||||||
|
@ -44,13 +44,13 @@ data "azurerm_virtual_network" "ad_vnet_data" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resource "azurerm_virtual_network_peering" "peer1" {
|
resource "azurerm_virtual_network_peering" "peer1" {
|
||||||
name = "peer_avd_ad"
|
name = "peer_avdspoke_ad"
|
||||||
resource_group_name = var.rg_name
|
resource_group_name = var.rg_name
|
||||||
virtual_network_name = azurerm_virtual_network.vnet.name
|
virtual_network_name = azurerm_virtual_network.vnet.name
|
||||||
remote_virtual_network_id = data.azurerm_virtual_network.ad_vnet_data.id
|
remote_virtual_network_id = data.azurerm_virtual_network.ad_vnet_data.id
|
||||||
}
|
}
|
||||||
resource "azurerm_virtual_network_peering" "peer2" {
|
resource "azurerm_virtual_network_peering" "peer2" {
|
||||||
name = "peer_ad_avd"
|
name = "peer_ad_avdspoke"
|
||||||
resource_group_name = var.ad_rg
|
resource_group_name = var.ad_rg
|
||||||
virtual_network_name = var.ad_vnet
|
virtual_network_name = var.ad_vnet
|
||||||
remote_virtual_network_id = azurerm_virtual_network.vnet.id
|
remote_virtual_network_id = azurerm_virtual_network.vnet.id
|
||||||
|
@ -1,19 +1,39 @@
|
|||||||
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" {
|
||||||
|
description = "Name of the Azure Virtual Desktop DAG"
|
||||||
|
value = azurerm_virtual_desktop_application_group.dag.name
|
||||||
|
}
|
||||||
|
|
||||||
|
output "azurerm_virtual_desktop_workspace" {
|
||||||
|
description = "Name of the Azure Virtual Desktop workspace"
|
||||||
|
value = azurerm_virtual_desktop_workspace.workspace.name
|
||||||
|
}
|
||||||
|
|
||||||
output "location" {
|
output "location" {
|
||||||
description = "The Azure region"
|
description = "The Azure region"
|
||||||
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
|
||||||
}
|
}
|
||||||
@ -26,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
|
||||||
}
|
}
|
||||||
|
@ -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 {
|
||||||
|
@ -1,12 +1,35 @@
|
|||||||
|
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" {
|
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" {
|
||||||
type = string
|
type = string
|
||||||
default = "east us"
|
default = "eastus"
|
||||||
description = "The Azure Region in which all resources in this example should be created."
|
description = "The Azure Region in which all resources in this example should be created."
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,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"]
|
||||||
@ -36,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"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,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"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,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)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user