resource "aws_instance" "chef-workflow-environment-node" {
ami = "${var.ec2_ami_id}"
instance_type = "${var.ec2_instance_type}"
tags {
Name = "${var.aws_resource_prefix}-${var.chef_cookbook}-${var.chef_environment}",
UAI = "${var.ec2_uai_tag}"
}
key_name = "${var.ec2_keypair_name}"
vpc_security_group_ids = "${var.vpc_security_groups}"
subnet_id = "${var.vpc_subnet}"
provisioner "chef" {
environment = "${var.chef_environment}"
run_list = ["delivery-base::default"]
node_name = "${var.chef_cookbook}-${var.chef_environment}"
server_url = "${var.chef_server_url}"
fetch_chef_certificates = true
recreate_client = true
user_name = "${var.chef_user_name}"
user_key = "${file("chef_user_key.pem")}"
connection {
type = "${var.ec2_connection_type}"
user = "${var.ec2_login_user}"
private_key = "${file("aws_ssh_key.pem")}"
timeout = "3600s"
}
}
provisioner "local-exec" {
command = "knife vault refresh ge_acl acl_user -M client"
}
provisioner "remote-exec" {
inline = [
"${var.tf_remote_exec}chef-client -r 'recipe[delivery-base::default],recipe[${var.chef_cookbook}::default']"
]
connection {
type = "${var.ec2_connection_type}"
user = "${var.ec2_login_user}"
private_key = "${file("aws_ssh_key.pem")}"
}
}
}
However trying to spin up a windows with the same plans fails. It does not connect for the provisioner. It appears as if terraform does not have the ability pull the Windows Admin password and also cannot use the private_key, like test kitchen ec2 driver.
So I've been attempting to submit user_data to create a new user and still have had no success.
data "template_file" "init" {
template = "${file("user_data.ps1")}"
vars {
ec2_login_user_winrm = "${var.ec2_login_user_winrm}"
ec2_login_user_pw_winrm = "${var.ec2_login_user_pw_winrm}"
}
}
user_data = "${data.template_file.init.rendered}"
provisioner "chef" {
environment = "${var.chef_environment}"
run_list = ["delivery-base::default"]
node_name = "${var.chef_cookbook}-${var.chef_environment}"
server_url = "${var.chef_server_url}"
fetch_chef_certificates = true
recreate_client = true
user_name = "${var.chef_user_name}"
user_key = "${file("chef_user_key.pem")}"
os_type = "windows"
connection {
type = "${var.ec2_connection_type}"
user = "${var.ec2_login_user_winrm}"
password = "${var.ec2_login_user_pw_winrm}"
timeout = "3600s"
}
user_data.ps1:
<powershell>
net user ${ec2_login_user_winrm} ${ec2_login_user_pw_winrm} /add
net localgroup administrators ${ec2_login_user_winrm} /add
net localgroup WinRMRemoteWMIUsers__ ${ec2_login_user_winrm} /add
</powershell>
I've also tried adding these lines to test which I saw in other posts in this group:
winrm quickconfig -q
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
winrm set winrm/config '@{MaxTimeoutms="3600000"}'
winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/service/auth '@{Basic="true"}'
winrm set winrm/config/client/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
Any help/assistance would be greatly appreciated!
Thanks,
--Aaron