dial tcp :22: connectex: No connection could be made because the target machine actively refused it.

2,754 views
Skip to first unread message

Steve Button

unread,
Jan 26, 2018, 9:43:14 AM1/26/18
to Terraform
Hi,

I have tried switching on debug during a terraform apply, and I can see a whole bunch of :-

dial tcp :22: connectex: No connection could be made because the target machine actively refused it.

specifically ...

2018-01-26T09:56:34.043Z [DEBUG] plugin.terraform.exe: file-provisioner (internal) 2018/01/26 09:56:34 Retryable error: dial tcp :22: connectex: No connection could be made because the target machine actively refused it.


error messages during the run while it's still saying "Still creating..." for the VM. 

If I try to ssh to the VM as the correct user during this run, it works fine (even at the same time these errors are put into the logs) so I suspect the file-provisioner is not using the correct ssh keys, or something similar. Here's my os_profile_config

os_profile_linux_config {
    disable_password_authentication = true
    ssh_keys {
      path     = "/home/adminusername/.ssh/authorized_keys"
      key_data = "${var.ssh_key}"
    }
}

I have tried scouring the docs, and googling for the error message and searching through these forums but nothing comes up. 

Here's the provisioner that's failing. 

provisioner "file" {
    source  = "setup_elasticsearch.sh"
    destination = "/home/adminuser/setup_elasticsearch.sh"

    connection {
      type        = "ssh"
      host        = "${azurerm_public_ip.elastic_uk.ip_address}"
      user        = "adminuser"
      private_key = "${file("~/.ssh/id_rsa")}"
      agent       = "false"
      timeout     = "1m"
    }
  }


The ssh key looks OK, permissions are 700 for the .ssh directory and 600 for the authorized_keys file and like I said above, I can ssh on myself using the same key.

Have I come across a bug in the Azurerm provisioner?

Can anyone suggest something more to try?

Many thanks,

Steve Button

rahul kumar

unread,
Feb 26, 2020, 4:10:04 AM2/26/20
to Terraform
This error is a network-related error occurred while establishing a connection to the Server. It means that the error is occurring because there is no server listening at the hostname and port you assigned. It happens that something is preventing a connection to the port or hostname. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that specific port. This may be because it is not running at all or because it is listening on a different port. So, no connection can be established. The solution to this problem is that connect to the same end point your server is listening on.


Reply all
Reply to author
Forward
0 new messages