-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.tf
173 lines (148 loc) · 6.02 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
##################################################
# locals for tagging
##################################################
locals {
common_tags = {
Owner = "${var.owner}"
Environment = "${var.environment}"
Cost_center = "${var.cost_center}"
Application = "${var.app_name}"
}
}
##################################################
# Azure resource group
##################################################
resource "azurerm_resource_group" "rg" {
name = "${var.environment}-${var.app_name}-rg"
location = "${var.location}"
tags = "${local.common_tags}"
}
##################################################
# Azure Vnet
##################################################
data "azurerm_virtual_network" "vnet" {
name = "${var.vnet_name}"
resource_group_name = "${var.vnet_rg_name}"
}
##################################################
# Azure Subnet
##################################################
data "azurerm_subnet" "subnet" {
name = "${var.subnet_name}"
virtual_network_name = "${data.azurerm_virtual_network.vnet.name}"
resource_group_name = "${data.azurerm_virtual_network.vnet.resource_group_name}"
}
##################################################
# Azure NIC
##################################################
resource "azurerm_network_interface" "avd_nic" {
name = "${var.environment}-${var.app_name}-avd-name"
location = "${var.location}"
resource_group_name = "${azurerm_resource_group.rg.name}"
enable_ip_forwarding = false
ip_configuration {
name = "${var.ipconf_name}"
private_ip_address_allocation = "Dynamic"
subnet_id = "${data.azurerm_subnet.subnet.id}"
}
tags = "${local.common_tags}"
}
##################################################
# Network security group
##################################################
resource "azurerm_network_security_group" "nsg" {
name = "${var.environment}-${var.app_name}-nsg"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${var.location}"
tags = "${local.common_tags}"
}
##################################################
# NSG adding to Subnet
##################################################
resource "azurerm_subnet_network_security_group_association" "nsg_subnet" {
subnet_id = "${data.azurerm_subnet.subnet.id}"
network_security_group_id = "${azurerm_network_security_group.nsg.id}"
}
##############################################
# AZURE Host Pool
##############################################
resource "azurerm_virtual_desktop_host_pool" "pool" {
name = "${var.environment}-${var.app_name}-pool"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${var.location}"
type = "${var.host_pool_type}"
load_balancer_type = "${var.host_pool_load_balancer_type}"
validate_environment = "${var.host_pool_validate_environment}"
maximum_sessions_allowed = "${var.host_pool_max_sessions_allowed}"
registration_info {
expiration_date = timeadd(format("%sT00:00:00Z", formatdate("YYYY-MM-DD", timestamp())), "3600m")
}
tags = "${local.common_tags}"
}
##############################################
# AZURE VIRTUAL DESKTOP Workspace
##############################################
resource "azurerm_virtual_desktop_workspace" "ws" {
name = "${var.environment}-${var.app_name}-ws"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${var.location}"
friendly_name = "${var.app_name}"
description = "A personal playbox workspace avd setup"
tags = "${local.common_tags}"
}
resource "azurerm_virtual_desktop_application_group" "avd" {
name = "${var.environment}-${var.app_name}-avd"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${var.location}"
host_pool_id = "${azurerm_virtual_desktop_host_pool.pool.id}"
type = "${var.desktop_app_group_type}"
friendly_name = "${var.app_name}"
}
resource "azurerm_virtual_desktop_workspace_application_group_association" "ws_ass" {
workspace_id = "${azurerm_virtual_desktop_workspace.ws.id}"
application_group_id = "${azurerm_virtual_desktop_application_group.avd.id}"
}
##################################################
# Share Image Gallery
##################################################
#@#@#@#@#@#@#@# (Optional) @#@#@#@#@#@#@#@#@#@#@#
resource "azurerm_shared_image_gallery" "img_gallery" {
name = "${var.environment}-${var.app_name}-image-gallery"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${var.location}"
description = "Shared images gallery for storing the images which are to be used across the region"
tags = "${local.common_tags}"
}
resource "azurerm_shared_image" "image" {
name = "${var.sig_image_name}"
gallery_name = "${azurerm_shared_image_gallery.img_gallery.name}"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${var.location}"
os_type = "${var.os_type}"
identifier {
publisher = "${var.publisher}"
offer = "${var.offer}"
sku = "${var.sku}"
}
}
##############################################
# AZURE VIRTUAL DESKTOP
##############################################
resource "azurerm_windows_virtual_machine" "avd_vm" {
name = "${var.environment}-${var.app_name}-avd-vm"
resource_group_name = "${azurerm_resource_group.rg.name}"
location = "${var.location}"
network_interface_ids = ["${azurerm_network_interface.avd_nic.id}"]
size = "${var.os_size}"
admin_username = "${var.username}"
admin_password = "${var.password}"
os_disk {
name = "${var.environment}-${var.app_name}-avd-osdisk"
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}
source_image_id = "${azurerm_shared_image.image.id}"
identity {
type = "SystemAssigned"
}
}