【发布时间】:2022-01-21 14:39:34
【问题描述】:
resource "aws_api_gateway_rest_api" "api" {
body = "${file("apigateway/json-resolved/swagger.json")}"
name = "api"
}
---------------------------------------------------------------------------------
Invalid value for "path" parameter: no file exists at apigateway/json-resolved/swagger.json;
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.
当我尝试通过提供 API JSON 的实际路径来部署我的 API 时,这就是它所抛出的。即使文件在那里,即使我尝试了不同的路径,从相对路径到绝对路径等。当我将整个 JSON 粘贴到正文中时它可以工作,但当我提供文件时它不能工作。这是为什么呢?
【问题讨论】:
-
您需要一个前导
./,或者如果文件位于与您运行代码的位置相比的子目录中,您可以使用path.cwd,例如,${file("${ path.cwd}/apigateway/json-resolved/swagger.json")}" -
@MarkoE ".." 为我工作,谢谢!
-
@MarkoE 建议转换为答案。
标签: json terraform aws-api-gateway