Terraform apply fails with "Failed to read ssh private key: no key found"

I am using following terraform configuration on windows-10 Terraform v1.0.4 on windows_amd64

  • provider registry.terraform.io/hashicorp/aws v3.55.0
    I am trying to install some packages on ec2 instance using provisioner “remote-exec”. In this when i supply private_key in th connection block, i am getting following error message

       Failed to read ssh private key: no key found 
    

here is the terraform file i am using

terraform {
required_providers {
aws = {
source = “hashicorp/aws”
version = “~> 3.0”
}
}
}
resource “aws_instance” sandbox {
ami = “ami-0ff338189efb7ed37”
instance_type = “t3.micro”
tags = {
Name = “sandbox”
Description = “sandbox server”
}
provisioner “remote-exec” {
inline = [ “sudo apt update”,
“sudo apt install ansible -y”
]
}
connection {
type = “ssh”
host = self.public_ip
user = “ubuntu”
private_key = file(“C:\Users\asdfsd\Downloads\asdfsd-ubuntu.pem”)
}
key_name = aws_key_pair.sandbox_key.id
vpc_security_group_ids = [aws_security_group.ssh_access.id]
}
resource “aws_key_pair” “sandbox_key” {
public_key = file(“C:\Users\asdfsd\Downloads\asdfsd-ubuntu-public.pem”)
}