From b23d85327ceb56707bc2a62cf3ce8dc488484c31 Mon Sep 17 00:00:00 2001 From: Parkreiner Date: Mon, 1 Jul 2024 20:11:40 +0000 Subject: [PATCH] refactor: try extracting main script into separate template file --- windows-rdp/main.tf | 9 +++++++-- windows-rdp/windows-installation.tftpl | 11 ++++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/windows-rdp/main.tf b/windows-rdp/main.tf index 06f2c17..f47e94e 100644 --- a/windows-rdp/main.tf +++ b/windows-rdp/main.tf @@ -34,9 +34,14 @@ resource "coder_script" "windows-rdp" { agent_id = var.agent_id display_name = "windows-rdp" icon = "https://svgur.com/i/158F.svg" # TODO: add to Coder icons + script = templatefile("${path.module}/windows-installation.tftpl", { - CODER_USERNAME = var.admin_username, - CODER_PASSWORD = var.admin_password, + admin_username = var.admin_username + admin_password = var.admin_password + patch_file_contents = templatefile("${path.module}/devolutions-patch.js", { + CODER_USERNAME = var.admin_username + CODER_PASSWORD = var.admin_password + }) }) run_on_start = true diff --git a/windows-rdp/windows-installation.tftpl b/windows-rdp/windows-installation.tftpl index fc0404a..1b7ab48 100644 --- a/windows-rdp/windows-installation.tftpl +++ b/windows-rdp/windows-installation.tftpl @@ -3,9 +3,9 @@ function Set-AdminPassword { [string]$adminPassword ) # Set admin password - Get-LocalUser -Name "${var.admin_username}" | Set-LocalUser -Password (ConvertTo-SecureString -AsPlainText $adminPassword -Force) + Get-LocalUser -Name "${admin_username}" | Set-LocalUser -Password (ConvertTo-SecureString -AsPlainText $adminPassword -Force) # Enable admin user - Get-LocalUser -Name "${var.admin_username}" | Enable-LocalUser + Get-LocalUser -Name "${admin_username}" | Enable-LocalUser } function Configure-RDP { @@ -69,10 +69,7 @@ $patch = '' # Always copy the file in case we change it. @' -${templatefile("${path.module}/devolutions-patch.js", { -CODER_USERNAME : var.admin_username, -CODER_PASSWORD : var.admin_password, -})} +${patch_file_contents} '@ | Set-Content "$root\coder.js" # Only inject the src if we have not before. @@ -82,7 +79,7 @@ if ($isPatched -eq $null) { } } -Set-AdminPassword -adminPassword "${var.admin_password}" +Set-AdminPassword -adminPassword "${admin_password}" Configure-RDP Install-DevolutionsGateway Patch-Devolutions-HTML