question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to import ec2.KeyPair

See original GitHub issue

I’m following this document to import an EC2 key pair on my AWS account. However, I failed to import.

The error message I encountered is

 error: aws:ec2/keyPair:KeyPair resource 'my_key_pair' has a problem: Missing required argument: The argument "public_key" is required, but no definition was found.. Examine values at 'KeyPair.PublicKey'.

Steps to reproduce

  1. Run pulumi import aws:ec2/keyPair:KeyPair my_key my_key_pair.

Expected: I expect to see the key pair being imported without any error. Actual: The following error message will be displayed.

Previewing import (my_stack):
     Type                 Name                                    Plan       Info
 +   pulumi:pulumi:Stack  my_infrastructure-my_stack  create      1 error
 =   └─ aws:ec2:KeyPair   my_key                                  import     2 errors

Diagnostics:
  pulumi:pulumi:Stack (my_infrastructure-my_stack):
    error: preview failed

  aws:ec2:KeyPair (my_key):
    error: aws:ec2/keyPair:KeyPair resource 'my_key' has a problem: Missing required argument: The argument "public_key" is required, but no definition was found.. Examine values at 'KeyPair.PublicKey'.
    error: Preview failed: one or more inputs failed to validate

The official document also says

When importing an existing key pair the public key material may be in any format supported by AWS.

But where can I provide the public key while importing?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
stack72commented, Jun 14, 2022

Hi folks

unfortunately, the Go SDK doesn’t return the Key material in the API calls therefore, we are not going to be able to do much here. Maybe you could do something regarding ignoreChanges?

This is actually pointed out in the Terraform provider docs as well in their import:

NOTE:
The AWS API does not include the public key in the response, so terraform apply will attempt to replace the key pair. There is currently no supported workaround for this limitation.

Sorry for this

Paul

0reactions
Frasslecommented, Jun 14, 2022

This looks like it’s probably that the KeyPair Read function isn’t returning the publicKey attribute. That will be a bug in aws, not the engine. Re-open and moving.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Terraform fails to import key pair with Amazon EC2
The error is telling you that the keypair already exists in your AWS account but Terraform has no knowledge of it in its...
Read more >
Cannot import EC2 keypair (Length exceeds maximum) via ...
1 Answer 1 ... You are trying to import the private ssh key file. You should be importing the public ssh key file...
Read more >
Unable to import ec2.KeyPair · Issue #2008 - GitHub
I'm following this document to import an EC2 key pair on my AWS account. However, I failed to import. error: aws:ec2/keyPair:KeyPair resource ' ......
Read more >
import-key-pair — AWS CLI 1.27.27 Command Reference
Generating public/private rsa key pair. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/ec2 ......
Read more >
How To Change AWS EC2 Key Pair - ClayDesk E-Learning Blog
Instructions From AWS EC2 Support · Change pem login · go to your EC2 Console · Under NETWORK & SECURITY, click on Key...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found