0

While running terraform script, it shows the following error

Error: Error launching source instance: InvalidKeyPair.NotFound: The key pair 'oregonkeypair' does not exist
    status code: 400, request id: 921dcb14-796f-4d80-9d41-295dd2fffde7

  on instances.tf line 5, in resource "aws_instance" "rest":
   5: resource "aws_instance" "rest" {



Error: Error launching source instance: InvalidKeyPair.NotFound: The key pair 'oregonkeypair' does not exist
    status code: 400, request id: f35fc4f3-994c-4e32-9120-03ef02de952f

  on instances.tf line 19, in resource "aws_instance" "connect":
  19: resource "aws_instance" "connect" {



Error: Error launching source instance: InvalidKeyPair.NotFound: The key pair 'oregonkeypair' does not exist
    status code: 400, request id: 5127a96f-e64b-4a34-bea8-cb848b8b82f8

  on instances.tf line 33, in resource "aws_instance" "ksql":
  33: resource "aws_instance" "ksql" {



Error: Error launching source instance: InvalidKeyPair.NotFound: The key pair 'oregonkeypair' does not exist
    status code: 400, request id: 72dd21a3-62b6-4e65-bf17-c68dafd885fa

  on instances.tf line 46, in resource "aws_instance" "control_center":
  46: resource "aws_instance" "control_center" {



Error: Error launching source instance: InvalidKeyPair.NotFound: The key pair 'oregonkeypair' does not exist
    status code: 400, request id: 06d12048-f2ee-44a9-9bc4-0b69619040c6

  on instances.tf line 60, in resource "aws_instance" "schema":
  60: resource "aws_instance" "schema" {

Error: Error launching source instance: InvalidKeyPair.NotFound: The key pair 'oregonkeypair' does not exist status code: 400, request id: 9c49141d-7b47-490f-96d8-364399567244

But the same key is in the same folder and also provided chmod 400 permission 

2 Answers 2

1

Have you defined the key as a separate resource as stated in the documentation.

key_name - (Optional) Key name of the Key Pair to use for the instance; which can be managed using the aws_key_pair resource.

As far as I understand it, you will need to define it in your template, see documentation

Example:

resource "aws_key_pair" "deployer" {
   key_name   = "deployer-key"
   public_key = "ssh-rsa AAAAB3NzaC1y...and-so-on...1 [email protected]"
}
Sign up to request clarification or add additional context in comments.

Comments

1

This keypair oregonkeypair should already exist in AWS or create one using terraform as mentioned by @Ben

A quick fix would be to create one manually in AWS Console https://console.aws.amazon.com/ec2/v2/home

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.