Closed kiransharma2016 closed 4 years ago
Here is debug log
2020-11-23T09:05:57.188-0500 [DEBUG] plugin.terraform.exe: file-provisioner (internal) 2020/11/23 09:05:57 using private key for authentication 2020/11/23 09:05:57 [WARN] Errors while provisioning aws_instance.example with "file", so aborting 2020/11/23 09:05:57 [ERROR] eval: *terraform.EvalApplyPost, err: 1 error occurred:
2020/11/23 09:05:57 [ERROR] eval: *terraform.EvalSequence, err: Failed to read ssh private key: no key found 2020-11-23T09:05:57.247-0500 [WARN] plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing" 2020-11-23T09:05:57.247-0500 [WARN] plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing" 2020-11-23T09:05:57.247-0500 [WARN] plugin.stdio: received EOF, stopping recv loop: err="rpc error: code = Unavailable desc = transport is closing" 2020-11-23T09:05:57.277-0500 [DEBUG] plugin: plugin process exited: path=.terraform/plugins/registry.terraform.io/hashicorp/aws/3.16.0/windows_amd64/terraform-provider-aws_v3.16.0_x5.exe pid=20596 2020-11-23T09:05:57.277-0500 [DEBUG] plugin: plugin exited 2020-11-23T09:05:57.287-0500 [DEBUG] plugin: plugin process exited: path="C:\Program Files\Amazon\AWSCLI\bin\terraform.exe" pid=8060 2020-11-23T09:05:57.287-0500 [DEBUG] plugin: plugin exited 2020-11-23T09:05:57.288-0500 [DEBUG] plugin: plugin process exited: path="C:\Program Files\Amazon\AWSCLI\bin\terraform.exe" pid=9192 2020-11-23T09:05:57.288-0500 [DEBUG] plugin: plugin exited [31m [1m[31mError: [0m[0m[1mFailed to read ssh private key: no key found[0m
You'll need the SSH key in "OpenSSH format", not PPK format. You can use puttygen to convert from PPK to OpenSSH format.
To fix the deprecation warning you can change:
private_key = "${file(var.PATH_TO_PRIVATE_KEY)}"
to
private_key = file(var.PATH_TO_PRIVATE_KEY)
Thanks. That worked.
I used this command openssl rsa -in bt_mykeypair.pem -out private.key
Also this worked ${file(var.PATH_TO_PRIVATE_KEY)}"
Thansk
I am getting Warning: Interpolation-only expressions are deprecated issue whle implementing the demp-2. It sounds it provisioned the ec2, but can not login. it complaint not finding the private key file.
This is what is in vars file
variable "PATH_TO_PRIVATE_KEY" { default = "mykey" }
There is a file called mykey in the same folder
in instance config file, connection { host = coalesce(self.public_ip, self.private_ip) type = "ssh" user = var.INSTANCE_USERNAME private_key =file(var.PATH_TO_PRIVATE_KEY) }
I also tried connection { host = coalesce(self.public_ip, self.private_ip) type = "ssh" user = var.INSTANCE_USERNAME private_key = "${file(var.PATH_TO_PRIVATE_KEY)}" }
But when I use same ppk and login from putty, it works. so not ppk issue. not sure why it does not find the file.