Please let me ask how to declare ssh key pairs on TerraForm cloud

I have declared key_pairs on terraform cloud, I uploaded my key_pair to a folder in project on gitlab, in vars.tf I have created a variable to map key_pair as follows:

variable “key_pair_path” {
type = map(string)
default = {
public_key_path = “key_pairs/id_rsa.pub”,
private_key_path = “key_pairs/id_rsa.pem”,
}
On instance.tf I specify the public and private keys as follows:
resource “aws_key_pair” “hoangviet88vn” {
key_name = “hoangviet88vn”
public_key = “{file("{var.key_pair_path[“public_key_path”]}”)}"
}
resource “aws_instance” “lab01” {
ami = var.amis[var.aws_region]
instance_type = “t2.micro”
availability_zone = “ap-southeast-1a”
subnet_id = aws_subnet.mysubnet01.id
vpc_security_group_ids = [aws_security_group.mysg01.id]
key_name = aws_key_pair.hoangviet88vn.key_name
root_block_device {
volume_type = “gp2”
volume_size = “8”
delete_on_termination = true
}
tags = {
name = “lab01”
}

provisioner “remote-exec”{
inline = [<<EOF
sudo yum update -y
sudo yum install python3 -y
EOF
]
connection {
host = self.public_ip
type = “ssh”
user = “ec2-user”
private_key = “{file("{var.key_pair_path[“private_key_path”]}”)}"
}
}
when applying project on terraform cloud, I saw that the public key was created successfully, but when the provisioner needed to ssh to execute the command, terraform could not connect with the given private key, which step was wrong. above ? , I tried ssh from my computer to the instance created and connected successfully but I do not understand why terraform cannot connect.