Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform provisioner throws key not found error when using private_key

I have a problem using the provisioner from terraform to execute commands after the AWS machine has been deployed. When using the following configuration I see a key not found exception:

...
      provisioner "remote-exec" {
        inline = [
          "wget http://www.eu.apache.org/dist/jmeter/binaries/apache-jmeter-3.2.tgz",
          "tar -xzf apache-jmeter-3.2.tgz",
        ]    
        connection {
                user = "ec2-user"
                private_key = "${path.module}/my-private-key" 
                agent = false 
        }
      }
...

How can I use my private key in terraform to execute my commands after machine creation?

like image 412
andreaspfr Avatar asked Apr 28 '17 07:04

andreaspfr


1 Answers

You have to use file() interpolation function with private_key.

   connection {
      . . .
      private_key = "${file("${path.module}/my-private-key")}"
      . . .
  }

Look at "Additional arguments" section for private_key, where it mentions file() interpolation function to be used with private_key: https://www.terraform.io/docs/provisioners/connection.html

like image 183
gevgev Avatar answered Oct 04 '22 21:10

gevgev