Create Key Pair Using Terraform
Tasks:
Steps
1
Create main.tf file
resource "tls_private_key" "ssh_key" {
algorithm = "RSA"
rsa_bits = 4096
}
resource "aws_key_pair" "xfusion_key" {
key_name = "xfusion-kp"
public_key = tls_private_key.ssh_key.public_key_openssh
}
resource "local_file" "private_key" {
content = tls_private_key.ssh_key.private_key_pem
filename = "/home/bob/xfusion-kp.pem"
}terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.91.0"
}
}
}
provider "aws" {
region = "us-east-1"
skip_credentials_validation = true
skip_requesting_account_id = true
s3_use_path_style = true
endpoints {
ec2 = "http://aws:4566"
apigateway = "http://aws:4566"
cloudformation = "http://aws:4566"
cloudwatch = "http://aws:4566"
dynamodb = "http://aws:4566"
es = "http://aws:4566"
firehose = "http://aws:4566"
iam = "http://aws:4566"
kinesis = "http://aws:4566"
lambda = "http://aws:4566"
route53 = "http://aws:4566"
redshift = "http://aws:4566"
s3 = "http://aws:4566"
secretsmanager = "http://aws:4566"
ses = "http://aws:4566"
sns = "http://aws:4566"
sqs = "http://aws:4566"
ssm = "http://aws:4566"
stepfunctions = "http://aws:4566"
sts = "http://aws:4566"
rds = "http://aws:4566"
}
}
5
chmod 400 /home/bob/xfusion-kp.pemLast updated


