I could create the key pair myKey
to AWS
with Terraform
.
resource "tls_private_key" "pk" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "aws_key_pair" "kp" {
key_name = "myKey" # Create a "myKey" to AWS!!
public_key = tls_private_key.pk.public_key_openssh
}
AWS:
But I couldn't download the myKey.pem
file. Is it possible to download the myKey.pem
file with Terraform
like below?
Feb, 2022 Update:
No, it's not possible to download the
myKey.pem
file withTerraform
. Instead, we can create themyKey.pem
file which has the sameprivate key
as the key pairmyKey
onAWS
. So the createdmyKey
andmyKey.pem
file byTerraform
are the same as those which we manually create and download onAWS
. This is the code below. (I used Terraform v0.15.4)Don't forget to make
myKey.pem
file only readable by you running the code below before ssh to your ec2 instance.Otherwise the error below occurs.