Code
==================================
provider "aws" {
region = "ap-south-1"
access_key = ""
secret_key = ""
}
resource "aws_key_pair" "terraform-demo" {
key_name = "terraform-demo"
public_key = "file(/home/ec2-user/.ssh/authorized_keys)"
}
Code language: JavaScript (javascript)
Error
Error: Error import KeyPair: InvalidKey.Format: Key is not in valid OpenSSH public key format
status code: 400, request id: fa4b1c85-4372-467a-a228-83a159a5d12b
on check.tf line 7, in resource "aws_key_pair" "terraform-demo":
7: resource "aws_key_pair" "terraform-demo" {Code language: JavaScript (javascript)
Solutions:
Try converting the key to an openssh format using the -f flag.
ssh-keygen -i -f /home/ec2-user/.ssh/authorized_keys > mykey-openssh.pub # NOT WORKING
ssh-keygen -f terraform_ec2_key # NOT WORKING
ssh-keygen -i -f terraform_ec2_key.pub > terraform_ec2_key1.pub # NOT WORKING
WORK IS IN PROGRESSCode language: PHP (php)
I’m Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms.
I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.
Find Trusted Cardiac Hospitals
Compare heart hospitals by city and services — all in one place.
Explore Hospitals