aws-cloudformation / cloudformation-coverage-roadmap

The AWS CloudFormation Public Coverage Roadmap
https://aws.amazon.com/cloudformation/
Creative Commons Attribution Share Alike 4.0 International
1.11k stars 54 forks source link

[New resource] Import Public Key Material into Key Pair #891

Open sbwrege2z opened 3 years ago

sbwrege2z commented 3 years ago

It would be nice to be able to import a key pair into a region using Cloud Formation.

It is already possible to do this in the AWS console, and you can do this using the AWS CLI:

aws ec2 import-key-pair --key-name default-bastion-key --public-key-material "<base 64 encoded public key here>"

I know it is possible to reference key pair names that already exist in cloud formation template parameters like this:

BastionKey:
    Description: Name of an key pair for SSH access to the Bastion Host
    Type: "AWS::EC2::KeyPair::KeyName"
    Default: default-bastion-key

... and then use the KeyName in the property of an instance.

It would be great if importing the public key was possible using CloudFormation templates.

benbridts commented 3 years ago

Here is an example Private Resource Type (Resource Provider) that does that: https://github.com/WeAreCloudar/cloudformation-samples/tree/main/resource_providers/cloudar_ec2_keypair