config: validate that outputs have a name

This commit is contained in:
Mitchell Hashimoto 2016-11-02 16:56:20 -07:00
parent 1658055bfd
commit ef3148bbfa
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
3 changed files with 17 additions and 1 deletions

View File

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

View File

@ -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 {

View File

@ -0,0 +1,3 @@
output {
value = "foo"
}