Skip to content

Commit c644dcd

Browse files
authored
Merge pull request microsoft#88 from jensheerin/AVD
refactor code
2 parents 64aa77f + a2399f9 commit c644dcd

17 files changed

Lines changed: 214 additions & 103 deletions

File tree

quickstart/101-azure-virtual-desktop-anf/host.tf

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
registration_token = azurerm_virtual_desktop_host_pool.hostpool.registration_info[0].token
2+
registration_token = azurerm_virtual_desktop_host_pool_registration_info.registrationinfo.token
33
}
44

55
resource "random_string" "AVD_local_password" {
@@ -10,11 +10,16 @@ resource "random_string" "AVD_local_password" {
1010
override_special = "*!@#?"
1111
}
1212

13+
resource "azurerm_resource_group" "rg" {
14+
name = var.rg
15+
location = var.resource_group_location
16+
}
17+
1318
resource "azurerm_network_interface" "avd_vm_nic" {
1419
count = var.rdsh_count
1520
name = "${var.prefix}-${count.index + 1}-nic"
16-
resource_group_name = var.rg_name
17-
location = var.deploy_location
21+
resource_group_name = azurerm_resource_group.rg.name
22+
location = azurerm_resource_group.rg.location
1823

1924
ip_configuration {
2025
name = "nic${count.index + 1}_config"
@@ -30,8 +35,8 @@ resource "azurerm_network_interface" "avd_vm_nic" {
3035
resource "azurerm_windows_virtual_machine" "avd_vm" {
3136
count = var.rdsh_count
3237
name = "${var.prefix}-${count.index + 1}"
33-
resource_group_name = var.rg_name
34-
location = var.deploy_location
38+
resource_group_name = azurerm_resource_group.rg.name
39+
location = azurerm_resource_group.rg.location
3540
size = var.vm_size
3641
network_interface_ids = ["${azurerm_network_interface.avd_vm_nic.*.id[count.index]}"]
3742
provision_vm_agent = true

quickstart/101-azure-virtual-desktop-anf/loganalytics.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
resource "azurerm_resource_group" "log" {
2-
name = "${var.shared}-resources"
2+
name = var.rg_shared_name
33
location = var.deploy_location
44
}
55

quickstart/101-azure-virtual-desktop-anf/main.tf

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
# Create AVD Resource Group
2-
resource "azurerm_resource_group" "rg" {
1+
# Resource group name is output when execution plan is applied.
2+
resource "azurerm_resource_group" "sh" {
33
name = var.rg_name
4-
location = var.deploy_location
4+
location = var.resource_group_location
55
}
66

77
# Create AVD workspace
88
resource "azurerm_virtual_desktop_workspace" "workspace" {
99
name = var.workspace
10-
resource_group_name = azurerm_resource_group.rg.name
11-
location = var.deploy_location
10+
resource_group_name = azurerm_resource_group.sh.name
11+
location = azurerm_resource_group.sh.location
1212
friendly_name = "${var.prefix} Workspace"
1313
description = "${var.prefix} Workspace"
1414
}
1515

16-
resource "time_rotating" "avd_token" {
17-
rotation_days = 30
18-
}
19-
2016
# Create AVD host pool
2117
resource "azurerm_virtual_desktop_host_pool" "hostpool" {
22-
resource_group_name = azurerm_resource_group.rg.name
23-
location = var.deploy_location
18+
resource_group_name = azurerm_resource_group.sh.name
19+
location = azurerm_resource_group.sh.location
2420
name = var.hostpool
2521
friendly_name = var.hostpool
2622
validate_environment = true
@@ -29,17 +25,18 @@ resource "azurerm_virtual_desktop_host_pool" "hostpool" {
2925
type = "Pooled"
3026
maximum_sessions_allowed = 16
3127
load_balancer_type = "DepthFirst" #[BreadthFirst DepthFirst]
28+
}
3229

33-
registration_info {
34-
expiration_date = time_rotating.avd_token.rotation_rfc3339
35-
}
30+
resource "azurerm_virtual_desktop_host_pool_registration_info" "registrationinfo" {
31+
hostpool_id = azurerm_virtual_desktop_host_pool.hostpool.id
32+
expiration_date = var.rfc3339
3633
}
3734

3835
# Create AVD DAG
3936
resource "azurerm_virtual_desktop_application_group" "dag" {
40-
resource_group_name = azurerm_resource_group.rg.name
37+
resource_group_name = azurerm_resource_group.sh.name
4138
host_pool_id = azurerm_virtual_desktop_host_pool.hostpool.id
42-
location = var.deploy_location
39+
location = azurerm_resource_group.sh.location
4340
type = "Desktop"
4441
name = "${var.prefix}-dag"
4542
friendly_name = "Desktop AppGroup"

quickstart/101-azure-virtual-desktop-anf/netappstorage.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# 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
33
resource "azurerm_subnet" "netapp_subnet" {
44
name = var.netapp_subnet_name
5-
resource_group_name = var.rg_name
5+
resource_group_name = var.rg_stor
66
virtual_network_name = azurerm_virtual_network.vnet.name
77
address_prefixes = var.netapp_address
88

@@ -17,7 +17,7 @@ resource "azurerm_subnet" "netapp_subnet" {
1717

1818
resource "azurerm_netapp_account" "netapp_acct" {
1919
name = var.netapp_acct_name
20-
resource_group_name = var.rg_name
20+
resource_group_name = var.rg_stor
2121
location = var.deploy_location
2222

2323
active_directory {
@@ -37,7 +37,7 @@ resource "azurerm_netapp_account" "netapp_acct" {
3737
resource "azurerm_netapp_pool" "netapp_pool" {
3838
name = var.netapp_pool_name
3939
location = var.deploy_location
40-
resource_group_name = var.rg_name
40+
resource_group_name = var.rg_stor
4141
account_name = var.netapp_acct_name
4242
service_level = "Standard"
4343
size_in_tb = 4
@@ -54,7 +54,7 @@ resource "azurerm_netapp_volume" "NetApp_Vol" {
5454

5555
name = var.netapp_volume_name
5656
location = var.deploy_location
57-
resource_group_name = var.rg_name
57+
resource_group_name = var.rg_stor
5858
account_name = var.netapp_acct_name
5959
pool_name = var.netapp_pool_name
6060
volume_path = var.netapp_volume_path
Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,39 @@
1-
output "resource_group_name" {
2-
description = "Name of the Resource group created"
1+
output "azure_virtual_desktop_compute_resource_group" {
2+
description = "Name of the Resource group in which to deploy session host"
33
value = azurerm_resource_group.rg.name
44
}
55

6+
output "azure_virtual_desktop_host_pool" {
7+
description = "Name of the Azure Virtual Desktop host pool"
8+
value = azurerm_virtual_desktop_host_pool.hostpool.name
9+
}
10+
11+
output "azurerm_virtual_desktop_application_group" {
12+
description = "Name of the Azure Virtual Desktop DAG"
13+
value = azurerm_virtual_desktop_application_group.dag.name
14+
}
15+
16+
output "azurerm_virtual_desktop_workspace" {
17+
description = "Name of the Azure Virtual Desktop workspace"
18+
value = azurerm_virtual_desktop_workspace.workspace.name
19+
}
20+
621
output "location" {
722
description = "The Azure region"
823
value = azurerm_resource_group.rg.location
924
}
1025

26+
output "storage_account" {
27+
description = "Storage account for Profiles"
28+
value = azurerm_storage_account.storage.name
29+
}
30+
1131
output "storage_account_share" {
1232
description = "Name of the Azure File Share created for FSLogix"
1333
value = azurerm_storage_share.FSShare.name
1434
}
1535

16-
output "rdshcount" {
36+
output "session_host_count" {
1737
description = "The number of VMs created"
1838
value = var.rdsh_count
1939
}
@@ -26,14 +46,9 @@ output "dnsservers" {
2646
output "vnetrange" {
2747
description = "Address range for deployment vnet"
2848
value = azurerm_virtual_network.vnet.address_space
29-
30-
}
31-
output "avdusers" {
32-
description = "AVD users"
33-
value = azuread_group.aad_group.members
3449
}
3550

36-
output "aadgroupname" {
51+
output "AVD_user_groupname" {
3752
description = "Azure Active Directory Group for AVD users"
3853
value = azuread_group.aad_group.display_name
3954
}

quickstart/101-azure-virtual-desktop-anf/rbac.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ data "azurerm_role_definition" "role" { # access an existing built-in role
88
}
99

1010
resource "azuread_group" "aad_group" {
11-
display_name = var.aad_group_name
11+
display_name = var.aad_group_name
1212
security_enabled = true
1313
}
1414

quickstart/101-azure-virtual-desktop-anf/sig.tf

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
resource "azurerm_resource_group" "sigrg" {
22
location = var.deploy_location
3-
name = "${var.prefix}-rg"
3+
name = var.rg_shared_name
44
}
55

6+
# generate a random string (consisting of four characters)
7+
# https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string
8+
resource "random_string" "rando" {
9+
length = 4
10+
upper = false
11+
special = false
12+
}
13+
14+
615
# Creates Shared Image Gallery
716
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/shared_image_gallery
817
resource "azurerm_shared_image_gallery" "sig" {
9-
name = "AVDTFsig"
10-
resource_group_name = azurerm_resource_group.rg.name
11-
location = azurerm_resource_group.rg.location
18+
name = "sig${random_string.random.id}"
19+
resource_group_name = azurerm_resource_group.sigrg.name
20+
location = azurerm_resource_group.sigrg.location
1221
description = "Shared images"
1322

1423
tags = {
@@ -22,8 +31,8 @@ resource "azurerm_shared_image_gallery" "sig" {
2231
resource "azurerm_shared_image" "example" {
2332
name = "avd-image"
2433
gallery_name = azurerm_shared_image_gallery.sig.name
25-
resource_group_name = azurerm_resource_group.rg.name
26-
location = azurerm_resource_group.rg.location
34+
resource_group_name = azurerm_resource_group.sigrg.name
35+
location = azurerm_resource_group.sigrg.location
2736
os_type = "Windows"
2837

2938
identifier {

quickstart/101-azure-virtual-desktop-anf/variables.tf

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,35 @@
1+
variable "resource_group_location" {
2+
default = "eastus"
3+
description = "Location of the resource group."
4+
}
5+
6+
variable "rg" {
7+
type = string
8+
default = "rg-avd-compute"
9+
description = "Name of the Resource group in which to deploy session host"
10+
}
11+
112
variable "rg_name" {
213
type = string
3-
default = "avd-resources-rg"
4-
description = "Name of the Resource group in which to deploy these resources"
14+
default = "rg-avd-resources"
15+
description = "Name of the Resource group in which to deploy service objects"
16+
}
17+
18+
variable "rg_stor" {
19+
type = string
20+
default = "rg-avd-storage"
21+
description = "Name of the Resource group in which to deploy storage"
22+
}
23+
24+
variable "rg_shared_name" {
25+
type = string
26+
default = "rg-shared-resources"
27+
description = "Name of the Resource group in which to deploy shared resources"
528
}
629

730
variable "deploy_location" {
831
type = string
9-
default = "east us"
32+
default = "eastus"
1033
description = "The Azure Region in which all resources in this example should be created."
1134
}
1235

@@ -28,6 +51,13 @@ variable "ad_vnet" {
2851
description = "Name of domain controller vnet"
2952
}
3053

54+
variable "rfc3339" {
55+
type = string
56+
default = "2022-03-30T12:43:13Z"
57+
description = "Registration token expiration"
58+
}
59+
60+
3161
variable "dns_servers" {
3262
type = list(string)
3363
default = ["10.0.1.4", "168.63.129.16"]
@@ -36,12 +66,12 @@ variable "dns_servers" {
3666

3767
variable "vnet_range" {
3868
type = list(string)
39-
default = ["10.1.0.0/16"]
69+
default = ["10.2.0.0/16"]
4070
description = "Address range for deployment VNet"
4171
}
4272
variable "subnet_range" {
4373
type = list(string)
44-
default = ["10.1.0.0/24"]
74+
default = ["10.2.0.0/24"]
4575
description = "Address range for session host subnet"
4676
}
4777

@@ -54,8 +84,8 @@ variable "ad_rg" {
5484
variable "avd_users" {
5585
description = "AVD users"
5686
default = [
57-
"avduser01@infra.local",
58-
"avduser01@infra.local"
87+
"avduser01@contoso.net",
88+
"avduser02@contoso.net"
5989
]
6090
}
6191

@@ -84,7 +114,7 @@ variable "domain_name" {
84114

85115
variable "domain_user_upn" {
86116
type = string
87-
default = "admin" # do not include domain name as this is appended
117+
default = "domainjoineruser" # do not include domain name as this is appended
88118
description = "Username for domain join (do not include domain name as this is appended)"
89119
}
90120

@@ -140,8 +170,7 @@ variable "netapp_volume_path" {
140170
variable "netapp_subnet_name" {
141171
default = "NetAppSubnet"
142172
}
143-
144173
variable "netapp_address" {
145-
default = ["10.1.1.0/24"]
174+
default = ["10.1.1.0/24"]
146175
description = "Address range for NetApp Subnet"
147-
}
176+
}

quickstart/101-azure-virtual-desktop/afstorage.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Create a Resource Group for Storage
22
resource "azurerm_resource_group" "rg_storage" {
3-
location = "east us"
4-
name = "af-storage-rg"
3+
location = var.deploy_location
4+
name = var.rg_stor
55
}
66

77
# generate a random string (consisting of four characters)

quickstart/101-azure-virtual-desktop/host.tf

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
locals {
2-
registration_token = azurerm_virtual_desktop_host_pool.hostpool.registration_info[0].token
2+
registration_token = azurerm_virtual_desktop_host_pool_registration_info.registrationinfo.token
33
}
44

55
resource "random_string" "AVD_local_password" {
@@ -10,11 +10,16 @@ resource "random_string" "AVD_local_password" {
1010
override_special = "*!@#?"
1111
}
1212

13+
resource "azurerm_resource_group" "rg" {
14+
name = var.rg
15+
location = var.resource_group_location
16+
}
17+
1318
resource "azurerm_network_interface" "avd_vm_nic" {
1419
count = var.rdsh_count
1520
name = "${var.prefix}-${count.index + 1}-nic"
16-
resource_group_name = var.rg_name
17-
location = var.deploy_location
21+
resource_group_name = azurerm_resource_group.rg.name
22+
location = azurerm_resource_group.rg.location
1823

1924
ip_configuration {
2025
name = "nic${count.index + 1}_config"
@@ -30,8 +35,8 @@ resource "azurerm_network_interface" "avd_vm_nic" {
3035
resource "azurerm_windows_virtual_machine" "avd_vm" {
3136
count = var.rdsh_count
3237
name = "${var.prefix}-${count.index + 1}"
33-
resource_group_name = var.rg_name
34-
location = var.deploy_location
38+
resource_group_name = azurerm_resource_group.rg.name
39+
location = azurerm_resource_group.rg.location
3540
size = var.vm_size
3641
network_interface_ids = ["${azurerm_network_interface.avd_vm_nic.*.id[count.index]}"]
3742
provision_vm_agent = true

0 commit comments

Comments
 (0)