I'm struggling to get the password from a couple of new ec2 instances when using terraform. Been reading up through a couple of posts and thought i had it but not getting anywhere.
Here's my config:
resource "aws_instance" "example" {
ami = "ami-06f9d25508c9681c3"
count = "2"
instance_type = "t2.small"
key_name = "mykey"
vpc_security_group_ids =["sg-98d190fc","sg-0399f246d12812edb"]
get_password_data = "true"
}
output "public_ip" {
value = "${aws_instance.example.*.public_ip}"
}
output "public_dns" {
value = "${aws_instance.example.*.public_dns}"
}
output "Administrator_Password" {
value = "${rsadecrypt(aws_instance.example.*.password_data,
file("mykey.pem"))}"
}
Managed to clear up all the syntax errors but now when running get the following error:
PS C:\tf> terraform apply
aws_instance.example[0]: Refreshing state... (ID: i-0e087e3610a8ff56d)
aws_instance.example[1]: Refreshing state... (ID: i-09557bc1e0cb09c67)
Error: Error refreshing state: 1 error(s) occurred:
* output.Administrator_Password: At column 3, line 1: rsadecrypt: argument 1
should be type string, got type list in:
${rsadecrypt(aws_instance.example.*.password_data, file("mykey.pem"))}
Administrator_Password
outputs, identifying each on listvalue = "${rsadecrypt(aws_instance.example.*.password_data[0], file("mykey.pem"))}"
– Helder Sepulvedaconfig output "Administrator_Password" { value = "${rsadecrypt(aws_instance.example.password_data,file("C:/TF/mykey.pem"))}" }
but end up with the following response -Error: Error refreshing state: 1 error(s) occurred: * output.Administrator_Password: rsadecrypt: crypto/rsa: decryption error in: ${rsadecrypt(aws_instance.example.password_data,file("C:/TF/mycert.pem"))
– John Foxaws ec2 get-password-data --instance-id i-09557bc1e0cb09c67 --priv-launch-key mykey.pem
Just need to figure out the terraform setup – John Fox