mirror of
https://github.com/farcasclaudiu/terraform-course.git
synced 2026-06-22 09:01:59 +03:00
41 lines
1.2 KiB
Terraform
41 lines
1.2 KiB
Terraform
resource "aws_key_pair" "mykey" {
|
|
key_name = "mykey"
|
|
public_key = "${file("${var.PATH_TO_PUBLIC_KEY}")}"
|
|
}
|
|
|
|
resource "aws_instance" "win-example" {
|
|
ami = "${lookup(var.WIN_AMIS, var.AWS_REGION)}"
|
|
instance_type = "t2.micro"
|
|
key_name = "${aws_key_pair.mykey.key_name}"
|
|
user_data = <<EOF
|
|
<powershell>
|
|
net user ${var.INSTANCE_USERNAME} '${var.INSTANCE_PASSWORD}' /add /y
|
|
net localgroup administrators ${var.INSTANCE_USERNAME} /add
|
|
|
|
winrm quickconfig -q
|
|
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
|
|
winrm set winrm/config '@{MaxTimeoutms="1800000"}'
|
|
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
|
|
winrm set winrm/config/service/auth '@{Basic="true"}'
|
|
|
|
netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allow
|
|
netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow
|
|
|
|
net stop winrm
|
|
sc.exe config winrm start=auto
|
|
net start winrm
|
|
</powershell>
|
|
EOF
|
|
|
|
provisioner "file" {
|
|
source = "test.txt"
|
|
destination = "C:/test.txt"
|
|
}
|
|
connection {
|
|
type = "winrm"
|
|
timeout = "10m"
|
|
user = "${var.INSTANCE_USERNAME}"
|
|
password = "${var.INSTANCE_PASSWORD}"
|
|
}
|
|
}
|