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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With