-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
QA-301214 vdi windows vm instance deployment script
- Loading branch information
1 parent
ee4c8c3
commit 7501a43
Showing
7 changed files
with
242 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ ${join("\n", module.network.public_ip_address)} | |
Bastion Public IP: | ||
${module.bastion.public_ip} | ||
TB | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
resource "azurerm_public_ip" "public_ip" { | ||
name = "${var.prefix}-vdi-public-ip-${var.resource_tag}" | ||
resource_group_name = var.resource_group_name | ||
location = var.resource_group_location | ||
allocation_method = "Static" | ||
sku = "Standard" | ||
sku_tier = "Regional" | ||
} | ||
|
||
resource "azurerm_network_interface" "cca-vdi-network" { | ||
name = "${var.prefix}-vdi-network-${var.resource_tag}" | ||
location = var.resource_group_location | ||
resource_group_name = var.resource_group_name | ||
ip_configuration { | ||
name = "internal" | ||
subnet_id = var.subnet_id | ||
private_ip_address_allocation = "Dynamic" | ||
public_ip_address_id = azurerm_public_ip.public_ip.id | ||
} | ||
} | ||
|
||
# Create virtual machine | ||
resource "azurerm_windows_virtual_machine" "cca-vdi" { | ||
name = "${var.resource_tag}-vdi" | ||
admin_username = var.admin_username | ||
admin_password = var.admin_password | ||
location = var.resource_group_location | ||
resource_group_name = var.resource_group_name | ||
network_interface_ids = [azurerm_network_interface.cca-vdi-network.id] | ||
size = "Standard_D2s_v3" | ||
zone = "1" | ||
os_disk { | ||
caching = "ReadWrite" | ||
storage_account_type = "Standard_LRS" | ||
} | ||
source_image_reference { | ||
publisher = "MicrosoftWindowsDesktop" | ||
offer = "Office-365" | ||
sku = "win10-21h2-avd-m365" | ||
version = "latest" | ||
} | ||
} | ||
|
||
resource "azurerm_route_table" "cca-vdi-routetable" { | ||
name = "${var.prefix}-vdi-route-table-${var.resource_tag}" | ||
location = var.resource_group_location | ||
resource_group_name = var.resource_group_name | ||
|
||
route { | ||
name = "${var.prefix}-vdi-route-${var.resource_tag}" | ||
address_prefix = "185.46.212.80/32" | ||
next_hop_type = "VirtualAppliance" | ||
next_hop_in_ip_address = var.primary_service_ip | ||
} | ||
|
||
tags = { | ||
environment = "cc-vdi" | ||
} | ||
} | ||
|
||
resource "azurerm_subnet_route_table_association" "cca-vdi-routetable-association" { | ||
subnet_id = var.subnet_id | ||
route_table_id = azurerm_route_table.cca-vdi-routetable.id | ||
} | ||
|
||
resource "azurerm_network_security_group" "cca-vdi-nsg" { | ||
name = "${var.prefix}-vdi-nsg-${var.resource_tag}" | ||
location = var.resource_group_location | ||
resource_group_name = var.resource_group_name | ||
|
||
security_rule { | ||
name = "AllowAnyRDPInbound" | ||
priority = 100 | ||
direction = "Inbound" | ||
access = "Allow" | ||
protocol = "Tcp" | ||
source_port_range = "*" | ||
destination_port_range = "3389" | ||
source_address_prefix = "*" | ||
destination_address_prefix = "*" | ||
} | ||
|
||
security_rule { | ||
name = "AllowAnySSHInbound" | ||
priority = 101 | ||
direction = "Inbound" | ||
access = "Allow" | ||
protocol = "Tcp" | ||
source_port_range = "*" | ||
destination_port_range = "22" | ||
source_address_prefix = "*" | ||
destination_address_prefix = "*" | ||
} | ||
tags = { | ||
environment = "cc-vdi" | ||
} | ||
} | ||
|
||
resource "azurerm_network_interface_security_group_association" "cca-vdi-nsg-association" { | ||
network_interface_id = azurerm_network_interface.cca-vdi-network.id | ||
network_security_group_id = azurerm_network_security_group.cca-vdi-nsg.id | ||
} | ||
|
||
|
||
resource "azurerm_virtual_machine_extension" "CustomScriptExtenson" { | ||
count = var.cca_template_url == null && var.cca_token == null ? 1 : 0 | ||
name = "${var.prefix}-CustomScriptExtension-${var.resource_tag}" | ||
virtual_machine_id = azurerm_windows_virtual_machine.cca-vdi.id | ||
publisher = "Microsoft.Compute" | ||
type = "CustomScriptExtension" | ||
type_handler_version = "1.10" | ||
|
||
settings = <<SETTINGS | ||
{ | ||
"commandToExecute": "powershell.exe -Command \"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri 'https://z0luvmca.blob.core.windows.net/zsvdiinstaller/ZSVDIInstaller_1.4.0.5_x64.msi' -OutFile 'C:\\temp\\ZSVDIInstaller_1.4.0.5_x64.msi'\";powershell.exe -Command \"msiexec \"/i C:\\temp\\ZSVDIInstaller_1.4.0.5_x64.msi /qn\"\"" | ||
} | ||
SETTINGS | ||
} | ||
|
||
resource "azurerm_virtual_machine_extension" "CustomScriptExtension" { | ||
count = var.cca_template_url != null && var.cca_token != null ? 1 : 0 | ||
name = "${var.prefix}-CustomScriptExtension-${var.resource_tag}" | ||
virtual_machine_id = azurerm_windows_virtual_machine.cca-vdi.id | ||
publisher = "Microsoft.Compute" | ||
type = "CustomScriptExtension" | ||
type_handler_version = "1.10" | ||
|
||
settings = <<SETTINGS | ||
{ | ||
"commandToExecute": "powershell.exe -Command \"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri 'https://z0luvmca.blob.core.windows.net/zsvdiinstaller/ZSVDIInstaller_1.4.0.5_x64.msi' -OutFile 'C:\\temp\\ZSVDIInstaller_1.4.0.5_x64.msi'\";powershell.exe -Command \"msiexec \"/i C:\\temp\\ZSVDIInstaller_1.4.0.5_x64.msi PROVURL=\"${var.cca_template_url}\" TOKEN=\"${var.cca_token}\" MODE=1 ONBOARD=1 /qn\"\"" | ||
} | ||
SETTINGS | ||
} | ||
|
||
resource "azurerm_virtual_machine_extension" "WindowsOpenSSH" { | ||
name = "${var.prefix}-WindowsOpenSSH-${var.resource_tag}" | ||
virtual_machine_id = azurerm_windows_virtual_machine.cca-vdi.id | ||
publisher = "Microsoft.Azure.OpenSSH" | ||
type = "WindowsOpenSSH" | ||
type_handler_version = "3.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
output "public_ip_address" { | ||
value = azurerm_windows_virtual_machine.cca-vdi.public_ip_address | ||
} | ||
|
||
output "admin_password" { | ||
value = azurerm_windows_virtual_machine.cca-vdi.admin_password | ||
} | ||
|
||
output "admin_username" { | ||
value = azurerm_windows_virtual_machine.cca-vdi.admin_username | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
variable "resource_group_name" { | ||
description = "Main Resource Group Name" | ||
} | ||
|
||
variable "resource_group_location" { | ||
description = "Azure Region" | ||
} | ||
|
||
variable "prefix" { | ||
description = "A prefix to associate to VDI module resources" | ||
type = string | ||
} | ||
|
||
variable "admin_username" { | ||
description = "VDI Admin username for login" | ||
default = "ccvdiuser" | ||
} | ||
|
||
variable "admin_password" { | ||
description = "VDI Admin password for login" | ||
default = "Admin@123456" | ||
} | ||
|
||
variable "subnet_id" { | ||
description = "Subnet ID to associate to VDI Windows Instance" | ||
} | ||
|
||
variable "primary_service_ip" { | ||
description = "Cloud Connector Service Ip to add route to forward traffic from VDI Windows Instance" | ||
} | ||
|
||
variable "resource_tag" { | ||
description = "A tag to associate to VDI module resources" | ||
} | ||
|
||
variable "cca_template_url" { | ||
description = "Create a set of configurations that are applied to the VDI and dictate the VDI's behavior." | ||
} | ||
|
||
variable "cca_token" { | ||
description = "Generated Token for VDI Template URL" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
terraform { | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = ">= 3.46, <= 3.116" | ||
} | ||
} | ||
required_version = ">= 0.13.7, < 2.0.0" | ||
} |