config: imports are relative to tf
This commit is contained in:
parent
88bb42b5a4
commit
2ffee2a142
|
@ -2,6 +2,7 @@ package config
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/mitchellh/go-libucl"
|
||||
)
|
||||
|
@ -96,6 +97,12 @@ func loadTreeLibucl(root string) (*libuclImportTree, error) {
|
|||
// Load them all
|
||||
result.Children = make([]*libuclImportTree, len(importPaths))
|
||||
for i, path := range importPaths {
|
||||
if !filepath.IsAbs(path) {
|
||||
// Relative paths are relative to the Terraform file itself
|
||||
dir := filepath.Dir(root)
|
||||
path = filepath.Join(dir, path)
|
||||
}
|
||||
|
||||
imp, err := loadTreeLibucl(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -28,6 +28,29 @@ func TestLoadBasic(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestLoadBasic_import(t *testing.T) {
|
||||
c, err := Load(filepath.Join(fixtureDir, "import.tf"))
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if c == nil {
|
||||
t.Fatal("config should not be nil")
|
||||
}
|
||||
|
||||
actual := variablesStr(c.Variables)
|
||||
if actual != strings.TrimSpace(importVariablesStr) {
|
||||
t.Fatalf("bad:\n%s", actual)
|
||||
}
|
||||
|
||||
/*
|
||||
actual = resourcesStr(c.Resources)
|
||||
if actual != strings.TrimSpace(basicResourcesStr) {
|
||||
t.Fatalf("bad:\n%s", actual)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// This helper turns a resources field into a deterministic
|
||||
// string value for comparison in tests.
|
||||
func resourcesStr(rs []Resource) string {
|
||||
|
@ -73,3 +96,10 @@ foo
|
|||
bar
|
||||
bar
|
||||
`
|
||||
|
||||
const importVariablesStr = `
|
||||
foo
|
||||
bar
|
||||
bar
|
||||
bar
|
||||
`
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
import "import/one.tf";
|
||||
|
||||
variable "foo" {
|
||||
default = "bar";
|
||||
description = "bar";
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
variable "bar" {}
|
Loading…
Reference in New Issue