Remote-Exec Unable to Connect via WinRM

While create an EC2 Windows Instance, while trying to connect via WinRM Terraform doesn’t seem to be able to Connect:

aws_instance.Windows_Server (remote-exec): Host:
aws_instance.Windows_Server (remote-exec): Port: 5985
aws_instance.Windows_Server (remote-exec): User: administrator
aws_instance.Windows_Server (remote-exec): Password: true
aws_instance.Windows_Server (remote-exec): HTTPS: false
aws_instance.Windows_Server (remote-exec): Insecure: true
aws_instance.Windows_Server (remote-exec): NTLM: false
aws_instance.Windows_Server (remote-exec): CACert: false
aws_instance.Windows_Server: Still creating… (2m10s elapsed)
aws_instance.Windows_Server: Still creating… (2m20s elapsed)
aws_instance.Windows_Server (remote-exec): Connecting to remote host via WinRM…
aws_instance.Windows_Server (remote-exec): Host:
aws_instance.Windows_Server (remote-exec): Port: 5985
aws_instance.Windows_Server (remote-exec): User: administrator
aws_instance.Windows_Server (remote-exec): Password: true
aws_instance.Windows_Server (remote-exec): HTTPS: false
aws_instance.Windows_Server (remote-exec): Insecure: true
aws_instance.Windows_Server (remote-exec): NTLM: false
aws_instance.Windows_Server (remote-exec): CACert: false
aws_instance.Windows_Server: Still creating… (2m30s elapsed)
aws_instance.Windows_Server: Still creating… (2m40s elapsed)
aws_instance.Windows_Server (remote-exec): Connecting to remote host via WinRM…
aws_instance.Windows_Server (remote-exec): Host:
aws_instance.Windows_Server (remote-exec): Port: 5985
aws_instance.Windows_Server (remote-exec): User: administrator
aws_instance.Windows_Server (remote-exec): Password: true
aws_instance.Windows_Server (remote-exec): HTTPS: false
aws_instance.Windows_Server (remote-exec): Insecure: true
aws_instance.Windows_Server (remote-exec): NTLM: false
aws_instance.Windows_Server (remote-exec): CACert: false
aws_instance.Windows_Server: Still creating… (2m50s elapsed)
aws_instance.Windows_Server: Still creating… (3m0s elapsed)
aws_instance.Windows_Server (remote-exec): Connecting to remote host via WinRM…
aws_instance.Windows_Server (remote-exec): Host:
aws_instance.Windows_Server (remote-exec): Port: 5985
aws_instance.Windows_Server (remote-exec): User: administrator
aws_instance.Windows_Server (remote-exec): Password: true
aws_instance.Windows_Server (remote-exec): HTTPS: false
aws_instance.Windows_Server (remote-exec): Insecure: true
aws_instance.Windows_Server (remote-exec): NTLM: false
aws_instance.Windows_Server (remote-exec): CACert: false
aws_instance.Windows_Server: Still creating… (3m10s elapsed)
aws_instance.Windows_Server: Still creating… (3m20s elapsed)
aws_instance.Windows_Server (remote-exec): Connecting to remote host via WinRM…
aws_instance.Windows_Server (remote-exec): Host:
aws_instance.Windows_Server (remote-exec): Port: 5985
aws_instance.Windows_Server (remote-exec): User: administrator
aws_instance.Windows_Server (remote-exec): Password: true
aws_instance.Windows_Server (remote-exec): HTTPS: false
aws_instance.Windows_Server (remote-exec): Insecure: true
aws_instance.Windows_Server (remote-exec): NTLM: false
aws_instance.Windows_Server (remote-exec): CACert: false
aws_instance.Windows_Server: Still creating… (3m30s elapsed)
aws_instance.Windows_Server: Still creating… (3m40s elapsed)
aws_instance.Windows_Server (remote-exec): Connecting to remote host via WinRM…
aws_instance.Windows_Server (remote-exec): Host:
aws_instance.Windows_Server (remote-exec): Port: 5985
aws_instance.Windows_Server (remote-exec): User: administrator
aws_instance.Windows_Server (remote-exec): Password: true
aws_instance.Windows_Server (remote-exec): HTTPS: false
aws_instance.Windows_Server (remote-exec): Insecure: true
aws_instance.Windows_Server (remote-exec): NTLM: false
aws_instance.Windows_Server (remote-exec): CACert: false
aws_instance.Windows_Server: Still creating… (3m50s elapsed)
Interrupt received.
Please wait for Terraform to exit or data loss may occur.
Gracefully shutting down…
stopping operation…

Trying to run the following Command:

provisioner "remote-exec"{
    connection {
    type = "winrm"
    timeout = "10m"
    insecure = "true"
    agent    = "false"
    user = "${var.Administrator}"
    password = "${var.admin_password}"
  }

  inline = [
          "choco install -y git.install",
          "choco install -y install firefox",
          "choco install -y googlechrome",
          "choco install -y winscp",
          "choco install -y notepadplusplus.install",
          "choco install -y visionapp --version 9.0.5222"
     ]
}

I think WinRM is not enabled by default and before you can use the remote provisioner you need to configure it. On Azure this is typically done through VM extensions which are post provisioning steps to execute a powershell script.

I have not tried this in AWS but the process should be similar but by setting UserData. You will also need to ensure that the routing and firewall rules are set after WinRM has been enabled.

This link seems to have some good info on how you do this with Packer, maybe the powershell script to enable WinRM can also be used in the UserData.

Also this example looks pretty good, it has a good example of using UserData and also the network configuration.

Good blog, but the “quickconfig” setting sometimes fails. The following documentation explains why:

This looks like a typical issue with WinRM. Are you sure WinRM is configured properly on 5985?
Also, in the Connection section, could you please try specifying few more things:

  1. Remove double quotes from boolean values. It works either ways. Just want to make sure
  2. Add Port = “5985”
  3. Add https = false
  4. Add ntlm = false
  5. Add host =

Also, please run winrm enumerate winrm/config/listener on your image to ensure it’s pre-configured or add it in the first time run to ensure the listener is configured.