Terraform level 1 challenge 1 create key/pair

Hello,

I made this file :

resource "tls_private_key" "devops_kp" {
  algorithm = "RSA"
  rsa_bits  = 4096
}

resource "local_file" "private_key" {
  content  = tls_private_key.devops_kp.private_key_pem
  filename = "/home/bob/devops-kp.pem"
  file_permission = "0600"
}

resource "aws_key_pair" "devops_kp" {
  key_name   = "devops-kp"
  public_key = tls_private_key.devops_kp.public_key_openssh
}

and did then these steps :

terraform init 
terraform validate
terraplan plan

But the challenge failed with

 Resources have not been created using 'terraform'.

Hi @rwobben could you please check this Create a keypair with terraform

@rwobben But everything thing really looks similar i can’t really figure out what is wrong maybe if i redo the task i can find the mistake

Any luck

The only difference I can see is I do terraform plan and you do terraform apply --auto-approve

@rwobben
terraform apply --auto-approve means we are actually applyingthe changes to create the keys right? so if you didn’t apply the changes then the task won’t be complete, so after your tf plan did you apply the changes?

Thanks

The appy --auto-approve did the job.
First challenge solved.

@rwobben okay glad it could help

That means you didn’t apply, as you’ve now discovered.
apply/create means the same thing in terraform, well more specifically it means create them if they don’t exist, update them if they do and any change is detected.
Bottom line, the grader is looking for the resources to exist.