e012c2b5bf
Includes: * baseline Windows AMI * initial pass at Terraform configurations * OpenSSH for Windows Using OpenSSH is a lot nicer for Nomad developers than winrm would be, plus it lets us avoid passing around the Windows password in the clear. Note that now we're copying up all the provisioning scripts and configs as a zipped bundle because TF's file provisioner dies in the middle of pushing up multiple files (whereas `scp -r` works fine). We're also running all the provisioning scripts inside the userdata by polling for the zip file to show up (gross!). This is because `remote-exec` provisioners are failing on Windows with the same symptoms as: https://github.com/hashicorp/terraform/issues/17728 If we can't fix this, it'll prevent us from having multiple Windows clients running until TF supports count interpolation in the `template_file`, which is planned for a later 0.12 release.
54 lines
1.7 KiB
PowerShell
Executable file
54 lines
1.7 KiB
PowerShell
Executable file
Set-StrictMode -Version latest
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$RunningAsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
|
|
if (!$RunningAsAdmin) {
|
|
Write-Error "Must be executed in Administrator level shell."
|
|
exit 1
|
|
}
|
|
|
|
# Force TLS1.2
|
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
|
|
|
Try {
|
|
|
|
# install portable SSH instead of the Windows feature because we
|
|
# need to target 2016
|
|
$repo = "https://github.com/PowerShell/Win32-OpenSSH"
|
|
$version = "v8.0.0.0p1-Beta"
|
|
$url = "${repo}/releases/download/${version}/OpenSSH-Win64.zip"
|
|
|
|
# TODO: check sha!
|
|
Write-Output "Downloading OpenSSH from: $url"
|
|
Invoke-WebRequest -Uri $url -Outfile "OpenSSH-Win64.zip"
|
|
Expand-Archive ".\OpenSSH-Win64.zip" "C:\Program Files"
|
|
Rename-Item -Path "C:\Program Files\OpenSSH-Win64" -NewName "OpenSSH"
|
|
|
|
& "C:\Program Files\OpenSSH\install-sshd.ps1"
|
|
|
|
# Start the service
|
|
Start-Service sshd
|
|
Set-Service -Name sshd -StartupType 'Automatic'
|
|
|
|
Start-Service ssh-agent
|
|
Set-Service -Name ssh-agent -StartupType 'Automatic'
|
|
|
|
# Enable host firewall rule if it doesn't exist
|
|
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' `
|
|
-Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
|
|
|
|
# Set powershell as the OpenSSH login shell
|
|
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" `
|
|
-Name DefaultShell `
|
|
-Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" `
|
|
-PropertyType String -Force
|
|
|
|
|
|
} Catch {
|
|
Write-Error "Failed to install OpenSSH."
|
|
$host.SetShouldExit(-1)
|
|
throw
|
|
}
|
|
|
|
Write-Output "Installed OpenSSH."
|