Terraform: Failed to read key for aws_instance ssh provisioner

Created on 12 Jul 2018  ยท  4Comments  ยท  Source: hashicorp/terraform

Terraform Version

Terraform v0.11.7
+ provider.aws v1.27.0

Terraform Configuration Files

 connection {
    user        = "centos"
    private_key = "/Users/myid/.ssh/aws-dev.pem"
 }

Code below is not working either.

  connection {
    user        = "centos"
    private_key = "${file("${var.key_path}/${var.key_name}.pem")}"
  }

Debug Output


[DEBUG] plugin.terraform: file-provisioner (internal) 2018/07/12 13:45:51 [ERROR] connection error: dial tcp 54.167.179.168:22: i/o timeout
[DEBUG] plugin.terraform: file-provisioner (internal) 2018/07/12 13:45:51 [WARN] retryable error: dial tcp 54.167.179.168:22: i/o timeout

[ERROR] root.cloudera: eval: *terraform.EvalApplyProvisioners, err: Failed to read key "/Users/myid/.ssh/aws-dev.pem": no key found
[ERROR] root.cloudera: eval: *terraform.EvalSequence, err: Failed to read key "/Users/myid/.ssh/aws-dev.pem": no key found

Error: Error applying plan:

1 error(s) occurred:

  • module.cloudera.aws_instance.cdh_server: Failed to read key "/Users/myid/.ssh/aws-dev.pem": no key found

Crash Output

Expected Behavior


My script used to work. It creates AWS instances. But, somehow it is no longer working today. It complains no key found. I googled this issue. The problem was discussed in #9308. It says use private_key. I am using private key. But, I still got "no key found".

ls -alF ~/.ssh/aws-dev.pem
-rwx------ 1 myid staff 1692 Jan 21 09:15 /Users/myid/.ssh/aws-dev.pem*

Actual Behavior

Steps to Reproduce

Additional Context

References

Most helpful comment

What was the solution ? I have the same error

All 4 comments

What was the solution ? I have the same error

I had this problem too. Turns out, you must use, e.g.,:

${file(/path/to/keyfile.pem)}

syntax, which worked for me!

hi i am facing issue while using private_key..
My syntax is
provisioner "file" {
source = "../../provisioner/install.sh"
destination = "/tmp/install.sh"

connection {
type ="ssh"
user = "${var.INSTANCE_USERNAME}"
private_key = "${var.key}"
host = "${element(module.ec2_vm.public_ip,count.index )}"

agent = true

timeout  = "2m"

}
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/install.sh",
"sudo /tmp/install.sh"
]
}

but i am getting below error.

* aws_instance.ec2_vm: Error launching source instance: InvalidParameterValue: Invalid value '-----BEGIN RSA PRIVATE KEY----


-----END RSA PRIVATE KEY-----
' for keyPairNames. Text is not in valid ISO 8859-1 (Latin 1) encoding
status code: 400, request id: 4438d3ef-6f4f-407a-ad80-fc4c31c45866


Any solution for the above error????

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings