From 8fc8d77dcee0e5084749def76772f0181ed8f2ac Mon Sep 17 00:00:00 2001 From: Tamir Kamara <26870601+tamirkamara@users.noreply.github.com> Date: Sun, 28 May 2023 16:34:21 +0300 Subject: [PATCH] Use host in windows mount script (#3519) * use host in windows mount script * Update templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/porter.yaml --- .../guacamole-azure-windowsvm/porter.yaml | 4 +- .../terraform/.terraform.lock.hcl | 74 +++++++------------ .../terraform/data.tf | 11 +++ .../terraform/main.tf | 8 +- .../terraform/vm_config.ps1 | 8 +- .../terraform/windowsvm.tf | 36 +++------ 6 files changed, 59 insertions(+), 82 deletions(-) diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/porter.yaml b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/porter.yaml index bf44e0ea06..db889ca8bb 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/porter.yaml +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/porter.yaml @@ -1,7 +1,7 @@ --- schemaVersion: 1.0.0 name: tre-service-guacamole-windowsvm -version: 0.7.4 +version: 0.7.5 description: "An Azure TRE User Resource Template for Guacamole (Windows 10)" dockerfile: Dockerfile.tmpl registry: azuretre @@ -125,7 +125,7 @@ outputs: mixins: - exec - terraform: - clientVersion: 1.3.6 + clientVersion: 1.4.6 - az: clientVersion: 2.37.0 diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/.terraform.lock.hcl b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/.terraform.lock.hcl index c0fa94cf6c..1306331e37 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/.terraform.lock.hcl +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/.terraform.lock.hcl @@ -2,59 +2,41 @@ # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/azurerm" { - version = "3.41.0" - constraints = "3.41.0" + version = "3.57.0" + constraints = "3.57.0" hashes = [ - "h1:Kn7sqPk/YpsvORFEd/zHXa8U7KkVB551DXUMwvqiU0s=", - "zh:123838b581a27499d0a1e3a9804a6f57304969f58c4ea7fbd938ae2a795b2a19", - "zh:761a7bff3872a192202411aa62e3e6aedc3046f0df86967a1f9ed5a74207f451", - "zh:83092681a9e14d5e548edccece5086d822f86de6ff8227bb78706b41f0041697", - "zh:95fd6be4a3b995dc8ad40054646e2261e01365af7e8f8ebe0e62133cee8250cd", - "zh:995c3eb0aa23fc6948f45e68173034facc4bd92f4865abc3bba4bd305596fc86", - "zh:9f7b158d39f3e9fbc01ee27e6a63600838e34b7364715ebeea7d62717e48cb56", - "zh:b23193883592a4889942e82e73782e70dfbb517561a4f24b09f8ab6cbdc46866", - "zh:c4884d654d03a0546ec78f348563e32220ae35a2c76f22cb3c960f989dc6be48", - "zh:dda1c6720c6cef052db2fb4886a9cd46dee849e4367d6d66b45ad9d5bb607b94", - "zh:f0bc878d67785343bfc36a7d14ec58a67fa436f5b8b497221aea3931e3dccefd", + "h1:SOBKU/ioGnpuQpAx6dgaD0EzfAM2W+uS9e6p59viSxs=", + "zh:028202b0ae01f1262dac076b383cb68b5dd624977669b6db833418c215eb8401", + "zh:26fcf9e9b73cb3bbf87a048361a89050d2e52bdc91190a305e624a62be26a3f4", + "zh:2f381103953e4513068eee62089a0ec8c60a18ecef2235138b6c29a45920d6a2", + "zh:376f016f4b449b2cf38f75e27e7a9157fdcfc925f28198124a30e316abb54f3d", + "zh:7d491bab94d5aba91cd9c307dbd4b655dcdc0a6212541e7800b9a902be98befe", + "zh:85fa7d8339efd15494f947cda02e9ed127eafa32652e568f54261b2e97d2b3ee", + "zh:950e079e55a7e321adbd2f6a0639a4b3b0fac47d2e4bb3a12791e0817b694238", + "zh:975260e09379c5c97cad3171327db2f0b4914909861d4c24ab784b0ecd79c54a", + "zh:a26bb67ab2d2f20e5fee4d41110584af17357f4b4266d80f9debfad61fa0a4fd", + "zh:da0e5d1ec301c69b6fae684e55059fc5e1b91699ed3696229f599d558401556b", + "zh:ea11e62ce53caec240cb3a1da25d248805387fa246314001ed3e07e9105f6e12", "zh:f569b65999264a9416862bca5cd2a6177d94ccb0424f3a4ef424428912b9cb3c", - "zh:f6aa3c25f7106619cc6760e1d34b29b0956c50f285994f009939890a85e7b058", ] } provider "registry.terraform.io/hashicorp/random" { - version = "3.4.3" - constraints = "3.4.3" + version = "3.5.1" + constraints = "3.5.1" hashes = [ - "h1:xZGZf18JjMS06pFa4NErzANI98qi59SEcBsOcS2P2yQ=", - "zh:41c53ba47085d8261590990f8633c8906696fa0a3c4b384ff6a7ecbf84339752", - "zh:59d98081c4475f2ad77d881c4412c5129c56214892f490adf11c7e7a5a47de9b", - "zh:686ad1ee40b812b9e016317e7f34c0d63ef837e084dea4a1f578f64a6314ad53", + "h1:VSnd9ZIPyfKHOObuQCaKfnjIHRtR7qTw19Rz8tJxm+k=", + "zh:04e3fbd610cb52c1017d282531364b9c53ef72b6bc533acb2a90671957324a64", + "zh:119197103301ebaf7efb91df8f0b6e0dd31e6ff943d231af35ee1831c599188d", + "zh:4d2b219d09abf3b1bb4df93d399ed156cadd61f44ad3baf5cf2954df2fba0831", + "zh:6130bdde527587bbe2dcaa7150363e96dbc5250ea20154176d82bc69df5d4ce3", + "zh:6cc326cd4000f724d3086ee05587e7710f032f94fc9af35e96a386a1c6f2214f", "zh:78d5eefdd9e494defcb3c68d282b8f96630502cac21d1ea161f53cfe9bb483b3", - "zh:84103eae7251384c0d995f5a257c72b0096605048f757b749b7b62107a5dccb3", - "zh:8ee974b110adb78c7cd18aae82b2729e5124d8f115d484215fd5199451053de5", - "zh:9dd4561e3c847e45de603f17fa0c01ae14cae8c4b7b4e6423c9ef3904b308dda", - "zh:bb07bb3c2c0296beba0beec629ebc6474c70732387477a65966483b5efabdbc6", - "zh:e891339e96c9e5a888727b45b2e1bb3fcbdfe0fd7c5b4396e4695459b38c8cb1", - "zh:ea4739860c24dfeaac6c100b2a2e357106a89d18751f7693f3c31ecf6a996f8d", - "zh:f0c76ac303fd0ab59146c39bc121c5d7d86f878e9a69294e29444d4c653786f8", - "zh:f143a9a5af42b38fed328a161279906759ff39ac428ebcfe55606e05e1518b93", - ] -} - -provider "registry.terraform.io/hashicorp/template" { - version = "2.2.0" - constraints = "2.2.0" - hashes = [ - "h1:94qn780bi1qjrbC3uQtjJh3Wkfwd5+tTtJHOb7KTg9w=", - "zh:01702196f0a0492ec07917db7aaa595843d8f171dc195f4c988d2ffca2a06386", - "zh:09aae3da826ba3d7df69efeb25d146a1de0d03e951d35019a0f80e4f58c89b53", - "zh:09ba83c0625b6fe0a954da6fbd0c355ac0b7f07f86c91a2a97849140fea49603", - "zh:0e3a6c8e16f17f19010accd0844187d524580d9fdb0731f675ffcf4afba03d16", - "zh:45f2c594b6f2f34ea663704cc72048b212fe7d16fb4cfd959365fa997228a776", - "zh:77ea3e5a0446784d77114b5e851c970a3dde1e08fa6de38210b8385d7605d451", - "zh:8a154388f3708e3df5a69122a23bdfaf760a523788a5081976b3d5616f7d30ae", - "zh:992843002f2db5a11e626b3fc23dc0c87ad3729b3b3cff08e32ffb3df97edbde", - "zh:ad906f4cebd3ec5e43d5cd6dc8f4c5c9cc3b33d2243c89c5fc18f97f7277b51d", - "zh:c979425ddb256511137ecd093e23283234da0154b7fa8b21c2687182d9aea8b2", + "zh:b6d88e1d28cf2dfa24e9fdcc3efc77adcdc1c3c3b5c7ce503a423efbdd6de57b", + "zh:ba74c592622ecbcef9dc2a4d81ed321c4e44cddf7da799faa324da9bf52a22b2", + "zh:c7c5cde98fe4ef1143bd1b3ec5dc04baf0d4cc3ca2c5c7d40d17c0e9b2076865", + "zh:dac4bad52c940cd0dfc27893507c1e92393846b024c5a9db159a93c534a3da03", + "zh:de8febe2a2acd9ac454b844a4106ed295ae9520ef54dc8ed2faf29f12716b602", + "zh:eab0d0495e7e711cca367f7d4df6e322e6c562fc52151ec931176115b83ed014", ] } diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/data.tf b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/data.tf index 8bd597fffd..b8f4239143 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/data.tf +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/data.tf @@ -31,3 +31,14 @@ data "azurerm_public_ip" "app_gateway_ip" { name = "pip-agw-${var.tre_id}" resource_group_name = data.azurerm_resource_group.core.name } + +data "azurerm_storage_account" "stg" { + name = local.storage_name + resource_group_name = data.azurerm_resource_group.ws.name +} + +data "azurerm_storage_share" "shared_storage" { + count = var.shared_storage_access ? 1 : 0 + name = var.shared_storage_name + storage_account_name = data.azurerm_storage_account.stg.name +} diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/main.tf b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/main.tf index 3644542804..54e5baef02 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/main.tf +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/main.tf @@ -3,15 +3,11 @@ terraform { required_providers { azurerm = { source = "hashicorp/azurerm" - version = "=3.41.0" + version = "=3.57.0" } random = { source = "hashicorp/random" - version = "=3.4.3" - } - template = { - source = "hashicorp/template" - version = "=2.2.0" + version = "=3.5.1" } } backend "azurerm" { diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/vm_config.ps1 b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/vm_config.ps1 index f1c6ab6556..f2604f7a3b 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/vm_config.ps1 +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/vm_config.ps1 @@ -1,8 +1,10 @@ +Remove-Item -LiteralPath "C:\AzureData" -Force -Recurse +$ErrorActionPreference = "Stop" + if( ${SharedStorageAccess} -eq 1 ) { - $Command = "net use z: \\${StorageAccountFileEndpoint}\${FileShareName} /u:AZURE\${StorageAccountName} ${StorageAccountKey}" - $Command | Out-File "C:\ProgramData\Start Menu\Programs\StartUp\attatch_storage.cmd" -encoding ascii - Remove-Item -LiteralPath "C:\AzureData" -Force -Recurse + $Command = "net use z: \\${StorageAccountFileHost}\${FileShareName} /u:AZURE\${StorageAccountName} ${StorageAccountKey}" + $Command | Out-File "C:\ProgramData\Start Menu\Programs\StartUp\attach_storage.cmd" -encoding ascii } $PipConfigFolderPath = "C:\ProgramData\pip\" diff --git a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/windowsvm.tf b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/windowsvm.tf index 5b97ff5a33..699f92487e 100644 --- a/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/windowsvm.tf +++ b/templates/workspace_services/guacamole/user_resources/guacamole-azure-windowsvm/terraform/windowsvm.tf @@ -44,7 +44,17 @@ resource "azurerm_windows_virtual_machine" "windowsvm" { admin_username = random_string.username.result admin_password = random_password.password.result - custom_data = base64encode(data.template_file.vm_config.rendered) + custom_data = base64encode(templatefile( + "${path.module}/vm_config.ps1", { + nexus_proxy_url = local.nexus_proxy_url + SharedStorageAccess = var.shared_storage_access ? 1 : 0 + StorageAccountName = data.azurerm_storage_account.stg.name + StorageAccountKey = data.azurerm_storage_account.stg.primary_access_key + StorageAccountFileHost = data.azurerm_storage_account.stg.primary_file_host + FileShareName = var.shared_storage_access ? data.azurerm_storage_share.shared_storage[0].name : "" + CondaConfig = local.selected_image.conda_config ? 1 : 0 + } + )) # set source_image_id/reference depending on the config for the selected image source_image_id = local.selected_image_source_id @@ -92,27 +102,3 @@ resource "azurerm_key_vault_secret" "windowsvm_password" { key_vault_id = data.azurerm_key_vault.ws.id tags = local.tre_user_resources_tags } - -data "template_file" "vm_config" { - template = file("${path.module}/vm_config.ps1") - vars = { - nexus_proxy_url = local.nexus_proxy_url - SharedStorageAccess = var.shared_storage_access ? 1 : 0 - StorageAccountName = data.azurerm_storage_account.stg.name - StorageAccountKey = data.azurerm_storage_account.stg.primary_access_key - StorageAccountFileEndpoint = data.azurerm_storage_account.stg.primary_file_endpoint - FileShareName = var.shared_storage_access ? data.azurerm_storage_share.shared_storage[0].name : "" - CondaConfig = local.selected_image.conda_config ? 1 : 0 - } -} - -data "azurerm_storage_account" "stg" { - name = local.storage_name - resource_group_name = data.azurerm_resource_group.ws.name -} - -data "azurerm_storage_share" "shared_storage" { - count = var.shared_storage_access ? 1 : 0 - name = var.shared_storage_name - storage_account_name = data.azurerm_storage_account.stg.name -}