Hi, I wonder if you can help with this example -----
resource “aws_key_pair” “auth” {
key_name = “key1”
public_key = file(“key.pub”) #file in terraform folder Or
}
resource “aws_instance” “terraform_instance” {
ami = “ami-062dbd29edfdac661”
instance_type = “t2.micro”
key_name = aws_key_pair.key1.public_key Or
key_name = aws_key_pair.key1.auth.public_key Or
key_name = “key1” Or
key_name = file(“id_rsa.pub”) #public key Or
key_name = file(“id_rsa”) #private key #None allows ssh access
vpc_security_group_ids = [aws_security_group.allow_ssh.id]
subnet_id = aws_subnet.my_subnet.id
associate_public_ip_address = true
source_dest_check = false
tags = {
Name = “tf_instance”
}
}
The EC2 instance builds and answers SSH, but provides access denied. E.g.
ssh -i publickey user@ip-address Or
ssh -i privatekey user@ip-address Or
ssh -i publickey ip-address Or
ssh -i privatekey ip-address #As above no access is allowed.
Can you advise, where I’m going wrong? Thanks.