diff --git a/config/import_tree.go b/config/import_tree.go index ecd748799..cc1bd6800 100644 --- a/config/import_tree.go +++ b/config/import_tree.go @@ -2,6 +2,7 @@ package config import ( "fmt" + "path/filepath" ) // configurable is an interface that must be implemented by any configuration @@ -30,7 +31,17 @@ type fileLoaderFunc func(path string) (configurable, []string, error) // file. This function detects what kind of configuration file it is an // executes the proper fileLoaderFunc. func loadTree(root string) (*importTree, error) { - c, imps, err := loadFileLibucl(root) + var f fileLoaderFunc + switch filepath.Ext(root) { + case ".tf": + f = loadFileLibucl + default: + return nil, fmt.Errorf( + "%s: uknown configuration format. Use '.tf' or '.tf.rb' extension", + root) + } + + c, imps, err := f(root) if err != nil { return nil, err } diff --git a/config/loader_test.go b/config/loader_test.go index 1eb4b3d09..426bb2098 100644 --- a/config/loader_test.go +++ b/config/loader_test.go @@ -7,6 +7,13 @@ import ( "testing" ) +func TestLoad_badType(t *testing.T) { + _, err := Load(filepath.Join(fixtureDir, "bad_type.tf.nope")) + if err == nil { + t.Fatal("should have error") + } +} + func TestLoadBasic(t *testing.T) { c, err := Load(filepath.Join(fixtureDir, "basic.tf")) if err != nil { diff --git a/config/test-fixtures/bad_type.tf.nope b/config/test-fixtures/bad_type.tf.nope new file mode 100644 index 000000000..289e728ba --- /dev/null +++ b/config/test-fixtures/bad_type.tf.nope @@ -0,0 +1 @@ +variable "foo" {}