File not found with "file" function

Hi @stuart-c I am also facing same error can you please look at it.

resource “aws_key_pair” “tf-key” {
key_name = “tf-keypair”
public_key = file(“${path.root}/”)

error message
Error: Invalid function argument

│ on line 12, in resource “aws_key_pair” “tf-key”:
│ 12: public_key = file(“${path.root}/”)
│ ├────────────────
│ │ while calling file(path)
│ │ path.root is “.”

│ Invalid value for “path” parameter: no file exists at “./”; this
│ function works only with files that are distributed as part of the
│ configuration source code, so if this file will be created by a resource in
│ this configuration you must instead obtain this result from an attribute of
│ that resource.

Hi @priyankagopale2 ,

Welcome to these forums.

You should start a new topic to ask your own questions, not continue one that is 2 years old. Users often incorrectly identify their problems as the same as existing ones. Explaining your own problem clearly without the distractions of other people’s often only slightly related problems is better.

EDIT: The topic has now been split by moderator action.

In your case:

  • You have instructed Terraform to load the contents of a file.
  • The file does not exist.

No more information than this is available in what you have shown us.

You should create the file, or change the configuration so it refers to a file that does exist.