diff --git a/test_code/AZURE_MACHINES/main.tf b/test_code/AZURE_MACHINES/main.tf index f9646009..e2c20dee 100644 --- a/test_code/AZURE_MACHINES/main.tf +++ b/test_code/AZURE_MACHINES/main.tf @@ -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 @@ -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\ntrue\n${local.additional_custom_data}") +} diff --git a/test_code/AZURE_MACHINES/outputs.tf b/test_code/AZURE_MACHINES/outputs.tf index ac01e54f..7c1fa804 100644 --- a/test_code/AZURE_MACHINES/outputs.tf +++ b/test_code/AZURE_MACHINES/outputs.tf @@ -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 @@ -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 + } } + ) } diff --git a/test_code/AZURE_MACHINES/security_group.tf b/test_code/AZURE_MACHINES/security_group.tf index 60eec45a..d5387826 100644 --- a/test_code/AZURE_MACHINES/security_group.tf +++ b/test_code/AZURE_MACHINES/security_group.tf @@ -1,6 +1,6 @@ # 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 @@ -8,7 +8,7 @@ resource "azurerm_public_ip" "linux_host_test" { } 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 @@ -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 } diff --git a/test_code/AZURE_MACHINES/variables.tf b/test_code/AZURE_MACHINES/variables.tf index c02362e8..6ab964be 100644 --- a/test_code/AZURE_MACHINES/variables.tf +++ b/test_code/AZURE_MACHINES/variables.tf @@ -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/ @@ -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"] } diff --git a/test_code/main.tf b/test_code/main.tf index 20172e7a..9bfdae36 100644 --- a/test_code/main.tf +++ b/test_code/main.tf @@ -2,36 +2,36 @@ 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" @@ -39,7 +39,7 @@ module "azure_machines" { 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 = { diff --git a/test_code/user_data/windows_azure.ps b/test_code/user_data/windows_azure.ps new file mode 100644 index 00000000..a76bd5f9 Binary files /dev/null and b/test_code/user_data/windows_azure.ps differ