resource "aws_instance" "win-example" {
ami = "${lookup(var.WIN_AMIS, var.AWS_REGION)}"
instance_type = "t2.medium"
count="${var.count}"
vpc_security_group_ids = ["${var.security_group_id}"]
key_name = "${aws_key_pair.mykey.key_name}"
user_data = <<EOF
<powershell>
net user ${var.username} '${var.password}' /add /y
net localgroup administrators ${var.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.username}"
password = "${var.password}"
}
tags {
Name="${format("${var.username}-%01d",count.index+1)}"
}
}
If i run code above more than once-specifying other value for var.username, instance got recreated, is it possible to use same tf file multiple times, to create new machines with different user name ?