0

我正在尝试在另一个文件夹的代码中访问或调用 CSV 文件,但是当我在 terraform 中设置显示错误的路径时

以下是 terraform 代码,其中设置文件模块的路径是文件夹,其中 a 是另一个文件夹,之后文件名为 test.CSV

locals {
   group_names    = csvdecode(file("/modules/a/test.csv"))
}

显示以下错误

Error: Error in function call

  on VPN_Gateway\VPN_Gateway.tf line 7, in locals:
   7:   group_names =   csvdecode(file("modules/a/test.csv"))

Call to function "file" failed: no file exists at modules\a\test.csv
4

1 回答 1

0

当 CSV 文件位于具有多个目录级别的另一个文件夹中时,我建议您使用绝对路径。当您在 CSV 文件的文件夹中并使用命令(我假设您使用 Linux 操作系统)时,您可以获得该路径pwd。您收到错误的可能原因是您使用了错误的相对路径。您的 CSV 文件似乎位于 Terraform 模块目录中。如果你的目录树是这样的:

.
├── main.tf
├── modules
│   └── a
│       └── test.csv

然后将 CSV 文件加载到文件的根路径中main.tf,那么代码应该是这样的:

locals {
   group_names    = csvdecode(file("modules/a/test.csv"))
}

再次建议,绝对路径更合适。

于 2020-05-08T01:32:44.437 回答