@@ -70,13 +70,14 @@ resource "aws_instance" "member_server" {
70
70
# Force an immediate time synchronization
71
71
w32tm /resync /force
72
72
73
+ # Set up SSH so we can remotely manage the instance
74
+ # Note: Windows Server 2016 does not support OpenSSH
73
75
%{ if var . server_version != " 2016" ~}
74
76
# set variables for retry loops
75
77
$timeout = 300
76
78
$interval = 30
77
79
78
- # Set up SSH so we can remotely manage the instance
79
- ## Install OpenSSH Server and Client
80
+ # Install OpenSSH Server and Client
80
81
# Loop to make sure that SSH installs correctly
81
82
$elapsed = 0
82
83
do {
@@ -122,25 +123,36 @@ resource "aws_instance" "member_server" {
122
123
}
123
124
} while ($true)
124
125
125
- ## Set PowerShell as the default SSH shell
126
+ # Set PowerShell as the default SSH shell
126
127
New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value (Get-Command powershell.exe).Path -PropertyType String -Force
127
128
128
- ## Configure SSH server to use private key authentication so that scripts don't have to use passwords
129
- ## Save the private key from instance metadata
129
+ # Configure SSH server to use private key authentication so that scripts don't have to use passwords
130
+ # Save the private key from instance metadata
130
131
$ImdsToken = (Invoke-WebRequest -Uri 'http://169.254.169.254/latest/api/token' -Method 'PUT' -Headers @{'X-aws-ec2-metadata-token-ttl-seconds' = 2160} -UseBasicParsing).Content
131
132
$ImdsHeaders = @{'X-aws-ec2-metadata-token' = $ImdsToken}
132
133
$AuthorizedKey = (Invoke-WebRequest -Uri 'http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key' -Headers $ImdsHeaders -UseBasicParsing).Content
133
134
$AuthorizedKeysPath = 'C:\ProgramData\ssh\administrators_authorized_keys'
134
135
New-Item -Path $AuthorizedKeysPath -ItemType File -Value $AuthorizedKey -Force
135
136
136
- ## Ensure the SSH agent pulls in the new key.
137
+ # Ensure the SSH agent pulls in the new key.
137
138
Set-Service -Name ssh-agent -StartupType "Automatic"
138
139
Restart-Service -Name ssh-agent
139
140
140
- ## Open the firewall for SSH connections
141
+ # Open the firewall for SSH connections
141
142
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
142
143
%{ endif ~}
143
144
145
+ # Open firewall ports for RDP functionality
146
+ New-NetFirewallRule -Name kerberostcp -DisplayName 'Kerberos TCP' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 88
147
+ New-NetFirewallRule -Name kerberosudp -DisplayName 'Kerberos UDP' -Enabled True -Direction Inbound -Protocol UDP -Action Allow -LocalPort 88
148
+ New-NetFirewallRule -Name rpctcp -DisplayName 'RPC TCP ' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 135
149
+ New-NetFirewallRule -Name rpcudp -DisplayName 'RPC UDP' -Enabled True -Direction Inbound -Protocol UDP -Action Allow -LocalPort 135
150
+ New-NetFirewallRule -Name ldaptcp -DisplayName 'LDAP TCP ' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 389
151
+ New-NetFirewallRule -Name ldapudp -DisplayName 'LDAP UDP' -Enabled True -Direction Inbound -Protocol UDP -Action Allow -LocalPort 389
152
+ New-NetFirewallRule -Name smbtcp -DisplayName 'SMB TCP ' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 445
153
+ New-NetFirewallRule -Name rdptcp -DisplayName 'RDP TCP ' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 3389
154
+ New-NetFirewallRule -Name rdpudp -DisplayName 'RDP UDP' -Enabled True -Direction Inbound -Protocol UDP -Action Allow -LocalPort 3389
155
+
144
156
# Adds member server to the domain
145
157
[int]$intix = Get-NetAdapter | % { Process { If ( $_.Status -eq "up" ) { $_.ifIndex } }}
146
158
Set-DNSClientServerAddress -interfaceIndex $intix -ServerAddresses ("${ var . domain_controller_ip } ","127.0.0.1")
0 commit comments