Hi i have a problems with connecting with ssh and the new private_key This is not working
connection {
user = "centos"
private_key = "${"file(/users/danny/.ssh/xxxxx")"
}
If you look at the output you see Private key: false
aws_instance.management-master (remote-exec): Private key: false
When i use key_file i don't have the problem
connection {
user = "centos"
key_file = "/users/danny/.ssh/xxx"
}
aws_instance.management-master (remote-exec): Private key: true
Hi @dverbeek84, not sure if this a transcription typo, but this:
private_key = "${"file(/users/danny/.ssh/xxxxx")"
is missing a closing set of braces - it should read:
private_key = "${file("/users/danny/.ssh/xxxxx")}"
If you change this does it resolve your problem? I am also trying to verify whether this is the case independently.
I'm trying to reproduce this using the configuration below, but it seems OK to me. I suspect that if you correct the file interpolation syntax as detailed in the previous message this will resolve the issue, since I _can_ replicate it in that case. I'll close this issue in anticipation of this resolving your issue - if it doesn't please feel free to reopen it!
provider "aws" {
region = "us-west-2"
}
resource "aws_key_pair" "test_keypair" {
key_name = "test_keypair"
public_key = "${file("${path.module}/keys/id_rsa.pub")}"
}
resource "aws_instance" "test_instance" {
ami = "ami-f0091d91"
instance_type = "t2.micro"
key_name = "${aws_key_pair.test_keypair.key_name}"
connection {
user = "ec2-user"
private_key = "${file("${path.module}/keys/id_rsa")}"
}
provisioner "remote-exec" {
inline = [
"touch ~/provisioned"
]
}
tags {
Name = "Terraform provisioner test instance"
}
}
output "public_ip" {
value = "${aws_instance.test_instance.public_ip}"
}
It was a typo in github not in the file itself.
But it is not working if you have version 0.6.6 of course :smile:. But after installing terraform 0.6.7 terraform just hangs for a long time...... :(
reverting to key_file has worked for me to resolve a similar (but possibly different) issue with private_key not working in my setup.
I saw it is closed but just a last comment here in case somebody else find this page as I did while google(ing)
this is working fine for me, using Openstack as provider and it has retry and timeout
resource "openstack_compute_instance_v2" "1_Windows2012R2" {
count = "1"
name = "Windows 2012 R2"
image_name = "win-2012-r2"
flavor_name = "m1.large"
network { name = "public" }
floating_ip = "${openstack_compute_floatingip_v2.1_Windows2012R2_ip.address}"
key_pair = "id_rsa"
security_groups = ["default"]
connection {
user = "Admin"
host = "${openstack_compute_floatingip_v2.1_Windows2012R2_ip.address}"
private_key = "/home/ecerquei/.ssh/id_rsa"
timeout = "10m"
}
provisioner "remote-exec" {
inline = [
"dir"
]
}
}
resource "openstack_compute_floatingip_v2" "1_Windows2012R2_ip" {
region = ""
pool = "10.8.172.0/22"
}
I don't understand how the private_key = "/home/ecerquei/.ssh/id_rsa" would work, when the value is supposed to be the contents of the file read for example with the file()
private_key - The contents of an SSH key to use for the connection. These can be loaded from a file on disk using the file() interpolation function. This takes preference over the password if provided.
@eduardocerqueira ?
The openstack_compute_instance_v2 docs suggest private_key can be a file path, which I assume is not true.
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.
Most helpful comment
I don't understand how the
private_key = "/home/ecerquei/.ssh/id_rsa"would work, when the value is supposed to be the contents of the file read for example with thefile()@eduardocerqueira ?