I think there’s an issue with the validation of the exercise.
This is my main.tf:
resource "aws_key_pair" "mykeypair" {
key_name = "nautilus-kp"
public_key = file("../nautilus-kp.pub")
}
And the command I use to generate the keypair
pwd
/home/bob/terraform
ssh-keygen -t rsa -b 4096 -f ../nautilus-kp
I’m not exactly sure what the full validation is, but there’s a good chance that it looks at your main.tf file. Please take a look at the soution Santosh supplied; it generates the key pair as part of the main.tf, and then registers it with AWS. You do not.
I think there’s an issue with the validation of the exercise.
This is my main.tf:
resource "aws_key_pair" "mykeypair" {
key_name = "nautilus-kp"
public_key = file("../nautilus-kp.pub")
}
And the command I use to generate the keypair
pwd
/home/bob/terraform
ssh-keygen -t rsa -b 4096 -f …/nautilus-kp
One reason I see the lab is failing could be due to the way the keys are generated and stored in Terraform.
You are pre-generating the key-pair and Terraform just uploads the public key to AWS. Here, the private key is not stored in the Terraform state.
Though this could be a secure way of managing keys. But for this lab, the validator might be looking at the TF state file.
Try not to pre-generate the keys on the client, and do it the other way by
resource "tls_private_key" "sshkey" {
algorithm = "RSA"
}
resource "aws_key_pair" "nautilus-kp" {
key_name = "nautilus-kp"
public_key = tls_private_key.sshkey.public_key_openssh
}