Terraform aws_s3_bucket_object,调用函数 “filemd5” 失败:打开文件

huangapple go评论63阅读模式
英文:

Terraform aws_s3_bucket_object, Call to function "filemd5" failed: open <file>

问题

My index.html is in the same level of where my terraform resource file is located

terraform
│     └── site
│         ├── index.html
│         ├── s3.tf
│         └── variables.tf

My config looks like this

resource "aws_s3_bucket_object" "index" {
  key    = "index.html"
  acl = "public-read"
  bucket = aws_s3_bucket.my_example_site.id
  source = "index.html"
  etag = filemd5("index.html")
}

When I apply, I get this error

Error: Error in function call

on modules/terraform/site/s3.tf line 15, in resource "aws_s3_bucket_object" "index":
15:   etag = filemd5("index.html")

Call to function "filemd5" failed: open index.html: no such file or directory.
英文:

My index.html is in the same level of where my terraform resource file is located

terraform
│&#160;&#160;     └── site
│&#160;&#160;         ├── index.html
│&#160;&#160;         ├── s3.tf
│&#160;&#160;         └── variables.tf

My config looks like this

resource &quot;aws_s3_bucket_object&quot; &quot;index&quot; {
  key    = &quot;index.html&quot;
  acl = &quot;public-read&quot;
  bucket = aws_s3_bucket.my_example_site.id
  source = &quot;index.html&quot;
  etag = filemd5(&quot;index.html&quot;)
}

When I apply, I get this error

│ Error: Error in function call
│
│   on modules/terraform/site/s3.tf line 15, in resource &quot;aws_s3_bucket_object&quot; &quot;index&quot;:
│   15:   etag = filemd5(&quot;index.html&quot;)
│
│ Call to function &quot;filemd5&quot; failed: open index.html: no such file or directory.

答案1

得分: 1

你需要为你的路径提供适当的引用。你正在在根目录而不是模块中运行 terraform。因此,正如评论中建议的那样,你需要使用 ${path.module} 来正确告诉 terraform 文件的位置。

英文:

You need a proper reference to your path. You're running terraform out of your root, not the module. Thus as the comments suggest, you need to you ${path.module} to properly tell terraform where the file is.

huangapple
  • 本文由 发表于 2023年2月13日 23:33:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/75438001.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定