diff --git a/lang/funcs/filesystem.go b/lang/funcs/filesystem.go index eb4921de1..1f00b5086 100644 --- a/lang/funcs/filesystem.go +++ b/lang/funcs/filesystem.go @@ -32,6 +32,7 @@ func MakeFileFunc(baseDir string, encBase64 bool) function.Function { path := args[0].AsString() src, err := readFileBytes(baseDir, path) if err != nil { + err = function.NewArgError(0, err) return cty.UnknownVal(cty.String), err } @@ -369,7 +370,7 @@ func readFileBytes(baseDir, path string) ([]byte, error) { // ReadFile does not return Terraform-user-friendly error // messages, so we'll provide our own. if os.IsNotExist(err) { - return nil, fmt.Errorf("no file exists at %s", path) + return nil, fmt.Errorf("no file exists at %s; 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", path) } return nil, fmt.Errorf("failed to read %s", path) } diff --git a/lang/funcs/filesystem_test.go b/lang/funcs/filesystem_test.go index 15839f228..b91b52b1e 100644 --- a/lang/funcs/filesystem_test.go +++ b/lang/funcs/filesystem_test.go @@ -77,7 +77,7 @@ func TestTemplateFile(t *testing.T) { cty.StringVal("testdata/missing"), cty.EmptyObjectVal, cty.NilVal, - `no file exists at testdata/missing`, + `no file exists at testdata/missing; 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`, }, { cty.StringVal("testdata/hello.tmpl"),