Skip to content

Commit 9dcd803

Browse files
committed
fix: update terraform to create windows machines
1 parent 68b8119 commit 9dcd803

File tree

3 files changed

+46
-7
lines changed

3 files changed

+46
-7
lines changed

Diff for: test_code/AZURE_MACHINES/main.tf

+32-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ locals {
55
compute_instances = { for key, value in var.AZURE_MACHINE_CONFIGS :
66
key => value if contains(var.AZURE_COMPUTE_FILTER, key) || length(var.AZURE_COMPUTE_FILTER) == 0 }
77

8+
win_instances = { for key, value in var.AZURE_WIN_MACHINE_CONFIGS :
9+
key => value if contains(var.AZURE_COMPUTE_FILTER, key) || length(var.AZURE_COMPUTE_FILTER) == 0 }
10+
11+
combined_instances = merge(local.compute_instances, local.win_instances)
12+
813
}
914

1015
resource "azurerm_resource_group" "linux_host_test" {
@@ -47,8 +52,33 @@ resource "azurerm_linux_virtual_machine" "linux_host_test" {
4752
custom_data = filebase64(each.value.user_data)
4853
}
4954

55+
resource "azurerm_windows_virtual_machine" "linux_host_test" {
56+
# https://azapril.dev/2020/05/12/terraform-depends_on/
57+
depends_on = [
58+
azurerm_network_interface_security_group_association.linux_host_test
59+
]
60+
for_each = local.win_instances
61+
name = replace(format(var.name_format, "${each.key}-machine"), local.str_f, local.str_r)
62+
resource_group_name = azurerm_resource_group.linux_host_test.name
63+
location = azurerm_resource_group.linux_host_test.location
64+
size = each.value.machine_type
65+
admin_username = each.value.default_user
66+
admin_password = each.value.default_password
67+
network_interface_ids = [
68+
azurerm_network_interface.linux_host_test[each.key].id,
69+
]
5070

71+
os_disk {
72+
caching = "ReadWrite"
73+
storage_account_type = "Standard_LRS"
74+
}
5175

76+
source_image_reference {
77+
publisher = each.value.source_image_reference.publisher
78+
offer = each.value.source_image_reference.offer
79+
sku = each.value.source_image_reference.sku
80+
version = each.value.source_image_reference.version
81+
}
5282

53-
54-
83+
custom_data = filebase64(each.value.user_data)
84+
}

Diff for: test_code/AZURE_MACHINES/security_group.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Create public IPs
22
resource "azurerm_public_ip" "linux_host_test" {
3-
for_each = local.compute_instances
3+
for_each = local.combined_instances
44
name = format(var.name_format, "${each.key}_PublicIP")
55
location = azurerm_resource_group.linux_host_test.location
66
resource_group_name = azurerm_resource_group.linux_host_test.name
77
allocation_method = "Dynamic"
88
}
99

1010
resource "azurerm_network_interface" "linux_host_test" {
11-
for_each = local.compute_instances
11+
for_each = local.combined_instances
1212
name = format(var.name_format, "${each.key}_nic")
1313
location = azurerm_resource_group.linux_host_test.location
1414
resource_group_name = azurerm_resource_group.linux_host_test.name
@@ -42,7 +42,7 @@ resource "azurerm_network_security_group" "linux_host_test" {
4242

4343
# Connect the security group to the network interface
4444
resource "azurerm_network_interface_security_group_association" "linux_host_test" {
45-
for_each = local.compute_instances
45+
for_each = local.combined_instances
4646
network_interface_id = azurerm_network_interface.linux_host_test[each.key].id
4747
network_security_group_id = azurerm_network_security_group.linux_host_test.id
4848
}

Diff for: test_code/AZURE_MACHINES/variables.tf

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# tflint-ignore: terraform_naming_convention
22
variable "AZURE_MACHINE_CONFIGS" {
3-
description = "variable for what compute instances to create"
3+
description = "variable for what linux compute instances to create"
44
type = map(any)
55
default = {
66
# https://az-vm-image.info/
@@ -87,11 +87,21 @@ variable "AZURE_MACHINE_CONFIGS" {
8787
sleep = 120
8888

8989
}
90+
}
91+
}
92+
93+
# tflint-ignore: terraform_naming_convention
94+
variable "AZURE_WIN_MACHINE_CONFIGS" {
95+
description = "variable for what linux compute instances to create"
96+
type = map(any)
97+
default = {
98+
# az vm image list --output table --all --publisher MicrosoftWindowsDesktop --sku win10-21h2-ent
9099
WIN_10_ENT_21H2 = {
91100
recreate = "changethistorecreate1"
92101
machine_type = "Standard_DS1_v2"
93102
description = "Windows 10 Enterprise 21H2"
94103
default_user = "test-user"
104+
default_password = "km$3MWPf&i6r4o@I"
95105
wait = "120"
96106
user_data = "user_data/windows.ps"
97107
source_image_reference = {
@@ -101,7 +111,6 @@ variable "AZURE_MACHINE_CONFIGS" {
101111
version = "19044.3086.230609"
102112
}
103113
sleep = 120
104-
105114
}
106115
}
107116
}

0 commit comments

Comments
 (0)