# File not found with "file" function

**URL:** <https://discuss.hashicorp.com/t/file-not-found-with-file-function/54951>\
**Category:** Terraform\
**Created:** [June 13, 2023, 8:47am UTC](https://discuss.hashicorp.com/t/file-not-found-with-file-function/54951 "2023-06-13T08:47:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![priyankagopale2](https://avatars.discourse-cdn.com/v4/letter/p/ecc23a/32.png) [@priyankagopale2](https://discuss.hashicorp.com/u/priyankagopale2)\
**Post date:** [June 13, 2023, 8:47am UTC](https://discuss.hashicorp.com/t/file-not-found-with-file-function/54951/1 "2023-06-13T08:47:30Z")

</div>

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}/id\_rsa.pub”)  
}

error message  
Error: Invalid function argument  
│  
│ on resource.tf line 12, in resource “aws\_key\_pair” “tf-key”:  
│ 12: public\_key = file(“${path.root}/id\_rsa.pub”)  
│ ├────────────────  
│ │ while calling file(path)  
│ │ path.root is “.”  
│  
│ Invalid value for “path” parameter: no file exists at “./id\_rsa.pub”; 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.

---

<div class="post-metadata">

**Author:** ![maxb](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/maxb/32/26655_2.png) [@maxb](https://discuss.hashicorp.com/u/maxb)\
**Post date:** [June 13, 2023, 9:06am UTC](https://discuss.hashicorp.com/t/file-not-found-with-file-function/54951/2 "2023-06-13T09:06:29Z")

</div>

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.
