Search code examples
amazon-web-servicesterraformterraform-provider-aws

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.

Solution

  • 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.