TCP SSH timeout while running remote_exec on AWS instance

Hi @sd999111 ,

Just wanted to clarify that this is not a “crash”, but just an error that Terraform is reporting to you.

It means that Terraform was unable to connect via SSH to the host (in this case 54.192.141.95 at port 22).

This can happen for various reasons, for example:

  • The server is not listening to port 22
  • A firewall is blocking access to the port

Please check if the AWS security group is allowing access to the aws_instance from the IP where you are running Terraform.

Additionally, maybe it takes time for the AWS instance to start serving requests and you need to introduce some wait before you start your provisioning steps.

Also, keep in mind that “provisioners are a last resort” and consider using other options:

  • cloud-init via the user-data attribute of the aws_instance resource
  • using HashiCorp’s Packer to create an AWS AMI that has all of your required software / applications already installed

Hope this helps you with your task.

Regards,
Filip