“路径”参数值无效:不存在文件

2024-04-22

正如提到的Terraform 资源:执行应用时出现连接错误 https://stackoverflow.com/questions/63613944/terraform-resource-connection-error-while-executing-apply

我将代码更改为以下内容

provisioner "remote-exec" {
    connection {
      type        = "ssh"
      host        = aws_eip.nat-eip.public_ip
      user        = "ubuntu"
      private_key = file("/id_rsa.pem")
    }
    inline = [
      "chmod +x /tmp/start_node.sh",
      "sudo sed -i -e 's/\r$//' /tmp/start_node.sh", # Remove the spurious CR characters.
      "sudo /tmp/start_node.sh",
    ]
  }

但我仍然遇到同样的错误

Error: Invalid function argument

  on explorer.tf line 60, in resource "aws_instance" "explorer":
  60:       private_key = file("/id_rsa.pem")

Invalid value for "path" parameter: no file exists at /id_rsa.pem;

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.

ls -la ooutput

total 156
drwxr-xr-x  10 CORP\mayuresh CORP\domain users  4096 Jan 12 14:29 .
drwxr-xr-x  16 CORP\mayuresh CORP\domain users  4096 Jan 10 13:10 ..
drwxr-xr-x  12 CORP\mayuresh CORP\domain users  4096 Jan 12 09:49 byoc-terraform
drwxr-xr-x   2 CORP\mayuresh CORP\domain users  4096 Jan 11 11:57 controllers
-rw-r--r--   1 CORP\mayuresh CORP\domain users   188 Jan 10 13:27 .env
-rw-r--r--   1 CORP\mayuresh CORP\domain users  1582 Jan 10 17:12 fetchUserData.js
drwxr-xr-x   9 CORP\mayuresh CORP\domain users  4096 Jan 12 13:14 .git
-rw-r--r--   1 CORP\mayuresh CORP\domain users   629 Jan 10 13:27 .gitignore
-rw-r--r--   1 CORP\mayuresh CORP\domain users   107 Dec 30 06:49 .gitmodules
-rw-r--r--   1 CORP\mayuresh CORP\domain users  1765 Jan 12 13:21 id_rsa.pem
-rw-r--r--   1 CORP\mayuresh CORP\domain users  1488 Jan 10 13:27 index.js
drwxr-xr-x   3 CORP\mayuresh CORP\domain users  4096 Jan 10 13:27 models
drwxr-xr-x 221 CORP\mayuresh CORP\domain users 12288 Jan 10 13:30 node_modules
-rw-r--r--   1 CORP\mayuresh CORP\domain users  1058 Jan 10 13:27 package.json
-rw-r--r--   1 CORP\mayuresh CORP\domain users 78791 Jan 10 13:27 package-lock.json
drwxr-xr-x   2 CORP\mayuresh CORP\domain users  4096 Jan 10 13:27 routes
drwxr-xr-x   2 CORP\mayuresh CORP\domain users  4096 Jan 10 17:01 utils
drwxr-xr-x   2 CORP\mayuresh CORP\domain users  4096 Jan 10 13:27 VMCreationFiles```

您是否尝试过使用完整路径?如果您使用模块,则特别有用。 IE:

private_key = file("${path.module}/id_rsa.pem")

或者我认为这也行

private_key = file("./id_rsa.pem")

我相信您现有的代码正在文件系统的根目录中查找该文件。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

“路径”参数值无效:不存在文件 的相关文章

随机推荐