Skip to content

feat: add windows 10 machines for testing #58

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
39 changes: 37 additions & 2 deletions test_code/AZURE_MACHINES/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ locals {
compute_instances = { for key, value in var.AZURE_MACHINE_CONFIGS :
key => value if contains(var.AZURE_COMPUTE_FILTER, key) || length(var.AZURE_COMPUTE_FILTER) == 0 }

win_instances = { for key, value in var.AZURE_WIN_MACHINE_CONFIGS :
key => value if contains(var.AZURE_COMPUTE_FILTER, key) || length(var.AZURE_COMPUTE_FILTER) == 0 }

combined_instances = merge(local.compute_instances, local.win_instances)

additional_custom_data = "Add-Content -Path c:\\users\\test-user\\.ssh\\authorized_keys -Value \"${(var.CI) ? var.PUBLIC_KEY : file(var.public_key_path)}\""

}


resource "azurerm_resource_group" "linux_host_test" {
name = format(var.name_format, "linux-host-test-resources")
location = var.location
Expand Down Expand Up @@ -47,8 +55,35 @@ resource "azurerm_linux_virtual_machine" "linux_host_test" {
custom_data = filebase64(each.value.user_data)
}

resource "azurerm_windows_virtual_machine" "windows_host_test" {
# https://azapril.dev/2020/05/12/terraform-depends_on/
depends_on = [
azurerm_network_interface_security_group_association.linux_host_test
]
for_each = local.win_instances
name = replace(format(var.name_format, "${each.key}-vm"), local.str_f, local.str_r)
computer_name = each.value.computer_name
resource_group_name = azurerm_resource_group.linux_host_test.name
location = azurerm_resource_group.linux_host_test.location
size = each.value.machine_type
admin_username = each.value.default_user
admin_password = each.value.default_password
network_interface_ids = [
azurerm_network_interface.linux_host_test[each.key].id,
]

os_disk {
caching = "ReadWrite"
storage_account_type = "Standard_LRS"
}

source_image_reference {
publisher = each.value.source_image_reference.publisher
offer = each.value.source_image_reference.offer
sku = each.value.source_image_reference.sku
version = each.value.source_image_reference.version
}



# custom_data = filebase64("${each.value.user_data}\n${local.additional_custom_data}")
custom_data = base64encode("${file("${path.module}/../user_data/windows_azure.ps")}\n</powershell>\n<persist>true</persist>\n${local.additional_custom_data}")
}
17 changes: 16 additions & 1 deletion test_code/AZURE_MACHINES/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
output "fab_hosts" {
value = { for key, value in azurerm_linux_virtual_machine.linux_host_test :
value = merge({
for key, value in azurerm_linux_virtual_machine.linux_host_test :
"AZURE_${key}" => {
"host" = value.public_ip_address
"name" = value.name
Expand All @@ -10,5 +11,19 @@ output "fab_hosts" {
"public_ssh_link" = "ssh -i ${var.PRIVATE_KEY_PATH} ${var.AZURE_MACHINE_CONFIGS[key].default_user}@${value.public_ip_address}"
"sleep" : var.AZURE_MACHINE_CONFIGS[key].sleep
}
},
{
for key, value in azurerm_windows_virtual_machine.windows_host_test :
"AZURE_${key}" => {
"host" = value.public_ip_address
"name" = value.name
"user" = var.AZURE_WIN_MACHINE_CONFIGS[key].default_user
"connect_kwargs" = {
"key_filename" : var.PRIVATE_KEY_PATH
}
"public_ssh_link" = "ssh -i ${var.PRIVATE_KEY_PATH} ${var.AZURE_WIN_MACHINE_CONFIGS[key].default_user}@${value.public_ip_address}"
"sleep" : var.AZURE_WIN_MACHINE_CONFIGS[key].sleep
}
}
)
}
17 changes: 14 additions & 3 deletions test_code/AZURE_MACHINES/security_group.tf
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Create public IPs
resource "azurerm_public_ip" "linux_host_test" {
for_each = local.compute_instances
for_each = local.combined_instances
name = format(var.name_format, "${each.key}_PublicIP")
location = azurerm_resource_group.linux_host_test.location
resource_group_name = azurerm_resource_group.linux_host_test.name
allocation_method = "Dynamic"
}

resource "azurerm_network_interface" "linux_host_test" {
for_each = local.compute_instances
for_each = local.combined_instances
name = format(var.name_format, "${each.key}_nic")
location = azurerm_resource_group.linux_host_test.location
resource_group_name = azurerm_resource_group.linux_host_test.name
Expand Down Expand Up @@ -38,11 +38,22 @@ resource "azurerm_network_security_group" "linux_host_test" {
source_address_prefix = "*"
destination_address_prefix = "*"
}
security_rule {
name = "RDP"
priority = 1002
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = "3389"
source_address_prefix = "*"
destination_address_prefix = "*"
}
}

# Connect the security group to the network interface
resource "azurerm_network_interface_security_group_association" "linux_host_test" {
for_each = local.compute_instances
for_each = local.combined_instances
network_interface_id = azurerm_network_interface.linux_host_test[each.key].id
network_security_group_id = azurerm_network_security_group.linux_host_test.id
}
30 changes: 28 additions & 2 deletions test_code/AZURE_MACHINES/variables.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# tflint-ignore: terraform_naming_convention
variable "AZURE_MACHINE_CONFIGS" {
description = "variable for what compute instances to create"
description = "variable for what linux compute instances to create"
type = map(any)
default = {
# https://az-vm-image.info/
Expand Down Expand Up @@ -90,11 +90,37 @@ variable "AZURE_MACHINE_CONFIGS" {
}
}

# tflint-ignore: terraform_naming_convention
variable "AZURE_WIN_MACHINE_CONFIGS" {
description = "variable for what linux compute instances to create"
type = map(any)
default = {
# az vm image list --output table --all --publisher MicrosoftWindowsDesktop --sku win10-21h2-ent
W10_ENT_21H2 = {
recreate = "changethistorecreate"
machine_type = "Standard_DS1_v2"
description = "Windows 10 Enterprise 21H2"
default_user = "test-user"
default_password = "km$3MWPf&i6r4o@I"
computer_name = "W10ENT21H2"
wait = "120"
user_data = "user_data/windows.ps"
source_image_reference = {
publisher = "MicrosoftWindowsDesktop"
offer = "Windows-10"
sku = "win10-21h2-ent-g2"
version = "19044.3086.230609"
}
sleep = 120
}
}
}

# tflint-ignore: terraform_naming_convention
variable "AZURE_COMPUTE_FILTER" {
type = list(any)
description = "list of compute instances to filter"
default = ["UBUNTU_20_04_LTS"]
default = ["UBUNTU_20_04_LTS", "W10_ENT_21H2"]
# default = ["UBUNTU_18_04_LTS", "UBUNTU_20_04_LTS", "RHEL_8"]
}

Expand Down
56 changes: 28 additions & 28 deletions test_code/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@ locals {
name_format = var.CI == true ? "gha-lht-${var.WORKFLOW_MATRIX_VALUE}-%s" : var.name_format
}

module "aws_machines" {
source = "./AWS_MACHINES"
PUBLIC_KEY_PATH = var.PUBLIC_KEY_PATH
PRIVATE_KEY_PATH = var.PRIVATE_KEY_PATH
# REGION = "us-west-2"
name_format = local.name_format
AWS_MACHINE_FILTER = ["AMAZON_LINUX_2", "UBUNTU_18_04_LTS", "UBUNTU_20_04_LTS", "RHEL_8_4_0", "CENT_OS_7", "AMAZON_LINUX_2023"]
CI = var.CI
PUBLIC_KEY = var.PUBLIC_KEY
# module "aws_machines" {
# source = "./AWS_MACHINES"
# PUBLIC_KEY_PATH = var.PUBLIC_KEY_PATH
# PRIVATE_KEY_PATH = var.PRIVATE_KEY_PATH
# # REGION = "us-west-2"
# name_format = local.name_format
# AWS_MACHINE_FILTER = ["AMAZON_LINUX_2", "UBUNTU_18_04_LTS", "UBUNTU_20_04_LTS", "RHEL_8_4_0", "CENT_OS_7", "AMAZON_LINUX_2023"]
# CI = var.CI
# PUBLIC_KEY = var.PUBLIC_KEY

providers = {
aws = aws
}
}
# providers = {
# aws = aws
# }
# }

module "gcp_machines" {
source = "./GCP_MACHINES"
public_key_path = var.PUBLIC_KEY_PATH
PRIVATE_KEY_PATH = var.PRIVATE_KEY_PATH
region = "us-west1"
zone = "a"
name_format = local.name_format
GCP_COMPUTE_FILTER = ["UBUNTU_18_04_LTS", "UBUNTU_20_04_LTS", "UBUNTU_22_04_LTS", "RHEL_8", "CENTOS_8"]
CI = var.CI
PUBLIC_KEY = var.PUBLIC_KEY
# module "gcp_machines" {
# source = "./GCP_MACHINES"
# public_key_path = var.PUBLIC_KEY_PATH
# PRIVATE_KEY_PATH = var.PRIVATE_KEY_PATH
# region = "us-west1"
# zone = "a"
# name_format = local.name_format
# GCP_COMPUTE_FILTER = ["UBUNTU_18_04_LTS", "UBUNTU_20_04_LTS", "UBUNTU_22_04_LTS", "RHEL_8", "CENTOS_8"]
# CI = var.CI
# PUBLIC_KEY = var.PUBLIC_KEY

providers = {
google = google
}
}
# providers = {
# google = google
# }
# }

module "azure_machines" {
source = "./AZURE_MACHINES"
public_key_path = var.PUBLIC_KEY_PATH
PRIVATE_KEY_PATH = var.PRIVATE_KEY_PATH
location = "West US 3"
name_format = local.name_format
AZURE_COMPUTE_FILTER = ["UBUNTU_18_04_LTS", "UBUNTU_20_04_LTS", "UBUNTU_22_04_LTS", "RHEL_8", "CENTOS_8"]
AZURE_COMPUTE_FILTER = ["UBUNTU_18_04_LTS", "UBUNTU_20_04_LTS", "UBUNTU_22_04_LTS", "RHEL_8", "CENTOS_8", "W10_ENT_21H2"]
CI = var.CI
PUBLIC_KEY = var.PUBLIC_KEY
providers = {
Expand Down
Binary file added test_code/user_data/windows_azure.ps
Binary file not shown.