跳至主要内容

fileexists 函数

fileexists 确定文件是否存在于给定路径。

代码块
fileexists(path)

函数在配置解析期间而不是在应用时进行评估,因此此函数只能用于 OpenTofu 执行任何操作之前已存在于磁盘上的文件。

此函数仅适用于普通文件。如果与目录、FIFO 或其他特殊模式一起使用,它将返回错误。

示例

代码块
> fileexists("${path.module}/hello.txt")
true
代码块
fileexists("custom-section.sh") ? file("custom-section.sh") : local.default_content
  • file 读取给定路径下文件的內容