i have created an ec2 instance using terraform (do not have .pem keys). Can i establish ssh connection between my local system and ec2 instance?
To access a private Git repository, Terraform either needs login credentials (for HTTPS access) or an SSH key. Terraform Cloud can store private SSH keys centrally, and you can easily use them in any workspace that clones modules from a Git server.
Assuming you provisioned an instance using Terraform v0.12.+
with this structure:
resource "aws_instance" "instance" {
ami = "${var.ami}"
instance_type = "t2.micro"
count = 1
associate_public_ip_address = true
}
You can make some additional settings:
output
:output "instance_ip" {
description = "The public ip for ssh access"
value = aws_instance.instance.public_ip
}
aws_key_pair
with an existing ssh public key or create a new one
Ex:resource "aws_key_pair" "ssh-key" {
key_name = "ssh-key"
public_key = "ssh-rsa AAAAB3Nza............"
}
key_name
in instance
resource just like this:resource "aws_instance" "instance" {
ami = var.ami
instance_type = "t2.micro"
count = 1
associate_public_ip_address = true
key_name = "ssh-key"
}
Now you need to apply running terraform apply
and terraform output
to return the public IP
Get your public IP and run:
ssh <PUBLIC IP>
OR with a public key path
ssh -i "~/.ssh/id_rsa.pub" <PUBLIC IP>
Sources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With