简体   繁体   中英

Unable to make connection to AWS Ubuntu instance created by terraform

I am using terraform 0.9.6

 provisioner "file" {
    source      = "conf/test.txt"
    destination = "/etc/test.txt"
    connection {
    user = "ubuntu"
    private_key = "${file("test.ppk")}"
    agent = "false" 
    timeout = "30s"
    }
  }

This block continuosuly gives me No key file found test.ppk error. Though the file is there in the same folder where my .tf file is there. I also tried to give absolute path C:\\test.ppk but still the issue remain the same. I am running terraform on windows. Any idea why the ppk file is not being read? Also this ppk file is passphrase protected how can I pass the passphrase for the ppk file in connection object?

I think your private key format is a problem. ppk is Putty private key format. Try to use pem private key format for your provisioner.

Your first problem is that the private keys need to be PEM encoded, you can use PuTTYGen

CLI puttygen privatekey.ppk -O private-openssh -o privatekey.pem

GUI Start PuTTYgen. Load your private key in .ppk format. Then go to Menu > Conversions > Export > OpenSSH. This creates a key in .pem format.

You're next problem is terraform $file trying to find the file itself. The path is interpreted relative to the working directory.

file(path) - Reads the contents of a file into the string. Variables in this file are not interpolated. The contents of the file are read as-is. The path is interpreted relative to the working directory. Path variables can be used to reference paths relative to other base locations. For example, when using file() from inside a module, you generally want to make the path relative to the module base, like this: file("${path.module}/file").

https://www.terraform.io/docs/configuration/interpolation.html#file_path_

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM