diff --git a/config/loader_hcl.go b/config/loader_hcl.go index 264c4ccb1..f8c9b2578 100644 --- a/config/loader_hcl.go +++ b/config/loader_hcl.go @@ -324,7 +324,8 @@ func loadModulesHcl(list *ast.ObjectList) ([]*Module, error) { func loadOutputsHcl(list *ast.ObjectList) ([]*Output, error) { list = list.Children() if len(list.Items) == 0 { - return nil, nil + return nil, fmt.Errorf( + "'output' must be followed by exactly one string: a name") } // Go through each object and turn it into an actual result. diff --git a/config/loader_test.go b/config/loader_test.go index a5f0401e8..68a462e71 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -565,6 +565,18 @@ func TestLoadFile_provisioners(t *testing.T) { } } +func TestLoadFile_unnamedOutput(t *testing.T) { + _, err := LoadFile(filepath.Join(fixtureDir, "output-unnamed.tf")) + if err == nil { + t.Fatalf("bad: expected error") + } + + errorStr := err.Error() + if !strings.Contains(errorStr, "'output' must be followed") { + t.Fatalf("bad: expected error has wrong text: %s", errorStr) + } +} + func TestLoadFile_connections(t *testing.T) { c, err := LoadFile(filepath.Join(fixtureDir, "connection.tf")) if err != nil { diff --git a/config/test-fixtures/output-unnamed.tf b/config/test-fixtures/output-unnamed.tf new file mode 100644 index 000000000..7e7529153 --- /dev/null +++ b/config/test-fixtures/output-unnamed.tf @@ -0,0 +1,3 @@ +output { + value = "foo" +}