diff --git a/terraform/context_old.go b/terraform/context_old.go index ed93bdf39..203446789 100644 --- a/terraform/context_old.go +++ b/terraform/context_old.go @@ -10,7 +10,6 @@ import ( "sync/atomic" "github.com/hashicorp/terraform/config" - "github.com/hashicorp/terraform/config/lang/ast" "github.com/hashicorp/terraform/config/module" "github.com/hashicorp/terraform/depgraph" "github.com/hashicorp/terraform/helper/multierror" @@ -373,34 +372,11 @@ func (c *Context) releaseRun(ch chan<- struct{}) { } func (c *Context) walkContext(op walkOperation, path []string) *walkContext { - // Get the config structure - m := c.module - for _, n := range path[1:] { - cs := m.Children() - m = cs[n] - } - var conf *config.Config - if m != nil { - conf = m.Config() - } - - // Calculate the default variable values - defaultVars := make(map[string]string) - if conf != nil { - for _, v := range conf.Variables { - for k, val := range v.DefaultsMap() { - defaultVars[k] = val - } - } - } - return &walkContext{ Context: c, Operation: op, Path: path, Variables: c.variables, - - defaultVariables: defaultVars, } } @@ -1521,16 +1497,6 @@ func (c *walkContext) computeVars( return err } - // Copy the default variables - for k, v := range c.defaultVariables { - if _, ok := vs[k]; !ok { - vs[k] = ast.Variable{ - Value: v, - Type: ast.TypeString, - } - } - } - // Interpolate the variables return raw.Interpolate(vs) } diff --git a/terraform/context_test.go b/terraform/context_test.go index 49a2ae6f2..1663bf44f 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -148,6 +148,26 @@ func TestContext2Validate_providerConfig_good(t *testing.T) { } } +func TestContext2Validate_requiredVar(t *testing.T) { + m := testModule(t, "validate-required-var") + p := testProvider("aws") + c := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "aws": testProviderFuncFixed(p), + }, + }) + + w, e := c.Validate() + if len(w) > 0 { + t.Fatalf("bad: %#v", w) + } + // TODO: fail + if len(e) == 0 { + t.Fatalf("bad: %s", e) + } +} + /* func TestContextValidate_goodModule(t *testing.T) { p := testProvider("aws") @@ -395,21 +415,6 @@ func TestContextValidate_resourceNameSymbol(t *testing.T) { } } -func TestContextValidate_requiredVar(t *testing.T) { - m := testModule(t, "validate-required-var") - c := testContext(t, &ContextOpts{ - Module: m, - }) - - w, e := c.Validate() - if len(w) > 0 { - t.Fatalf("bad: %#v", w) - } - if len(e) == 0 { - t.Fatalf("bad: %#v", e) - } -} - func TestContextValidate_provisionerConfig_bad(t *testing.T) { m := testModule(t, "validate-bad-prov-conf") p := testProvider("aws") diff --git a/terraform/interpolate.go b/terraform/interpolate.go index 111aed63e..98ca24164 100644 --- a/terraform/interpolate.go +++ b/terraform/interpolate.go @@ -34,6 +34,23 @@ func (i *Interpolater) Values( scope *InterpolationScope, vars map[string]config.InterpolatedVariable) (map[string]ast.Variable, error) { result := make(map[string]ast.Variable, len(vars)) + + // Copy the default variables + if i.Module != nil && scope != nil { + mod := i.Module + if len(scope.Path) > 1 { + mod = i.Module.Child(scope.Path[1:]) + } + for _, v := range mod.Config().Variables { + for k, val := range v.DefaultsMap() { + result[k] = ast.Variable{ + Value: val, + Type: ast.TypeString, + } + } + } + } + for n, rawV := range vars { var err error switch v := rawV.(type) { diff --git a/terraform/test-fixtures/interpolate-path-module/child/main.tf b/terraform/test-fixtures/interpolate-path-module/child/main.tf new file mode 100644 index 000000000..e69de29bb diff --git a/terraform/test-fixtures/interpolate-path-module/main.tf b/terraform/test-fixtures/interpolate-path-module/main.tf new file mode 100644 index 000000000..0f6991c53 --- /dev/null +++ b/terraform/test-fixtures/interpolate-path-module/main.tf @@ -0,0 +1,3 @@ +module "child" { + source = "./child" +}