Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit b23d853

Browse files
committed
refactor: try extracting main script into separate template file
1 parent a8580fe commit b23d853

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

windows-rdp/main.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ resource "coder_script" "windows-rdp" {
3434
agent_id = var.agent_id
3535
display_name = "windows-rdp"
3636
icon = "https://svgur.com/i/158F.svg" # TODO: add to Coder icons
37+
3738
script = templatefile("${path.module}/windows-installation.tftpl", {
38-
CODER_USERNAME = var.admin_username,
39-
CODER_PASSWORD = var.admin_password,
39+
admin_username = var.admin_username
40+
admin_password = var.admin_password
41+
patch_file_contents = templatefile("${path.module}/devolutions-patch.js", {
42+
CODER_USERNAME = var.admin_username
43+
CODER_PASSWORD = var.admin_password
44+
})
4045
})
4146

4247
run_on_start = true

windows-rdp/windows-installation.tftpl

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ function Set-AdminPassword {
33
[string]$adminPassword
44
)
55
# Set admin password
6-
Get-LocalUser -Name "${var.admin_username}" | Set-LocalUser -Password (ConvertTo-SecureString -AsPlainText $adminPassword -Force)
6+
Get-LocalUser -Name "${admin_username}" | Set-LocalUser -Password (ConvertTo-SecureString -AsPlainText $adminPassword -Force)
77
# Enable admin user
8-
Get-LocalUser -Name "${var.admin_username}" | Enable-LocalUser
8+
Get-LocalUser -Name "${admin_username}" | Enable-LocalUser
99
}
1010

1111
function Configure-RDP {
@@ -69,10 +69,7 @@ $patch = '<script defer id="coder-patch" src="coder.js"></script>'
6969

7070
# Always copy the file in case we change it.
7171
@'
72-
${templatefile("${path.module}/devolutions-patch.js", {
73-
CODER_USERNAME : var.admin_username,
74-
CODER_PASSWORD : var.admin_password,
75-
})}
72+
${patch_file_contents}
7673
'@ | Set-Content "$root\coder.js"
7774

7875
# Only inject the src if we have not before.
@@ -82,7 +79,7 @@ if ($isPatched -eq $null) {
8279
}
8380
}
8481

85-
Set-AdminPassword -adminPassword "${var.admin_password}"
82+
Set-AdminPassword -adminPassword "${admin_password}"
8683
Configure-RDP
8784
Install-DevolutionsGateway
8885
Patch-Devolutions-HTML

0 commit comments

Comments
 (0)