From ed042ab0675ff539bafcfb3cb783825087c292bf Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 23 May 2016 12:46:06 -0400 Subject: [PATCH] Interpolation also skipped during Validate phase Adding walkValidate to the EvalTree operations, and removing the walkValidate guard from the Interpolater.valueModuleVar allows the values to be interpolated for Validate. --- terraform/context_validate_test.go | 27 +++++++++++++++++++++++++++ terraform/graph_config_node_output.go | 3 ++- terraform/interpolate.go | 10 ---------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/terraform/context_validate_test.go b/terraform/context_validate_test.go index af8d7d3c4..3258c093a 100644 --- a/terraform/context_validate_test.go +++ b/terraform/context_validate_test.go @@ -749,3 +749,30 @@ func TestContext2Validate_varRefFilled(t *testing.T) { t.Fatalf("bad: %#v", value) } } + +// Module variables weren't being interpolated during Validate phase. +// related to https://github.com/hashicorp/terraform/issues/5322 +func TestContext2Validate_interpolateVar(t *testing.T) { + input := new(MockUIInput) + + m := testModule(t, "input-interpolate-var") + p := testProvider("null") + p.ApplyFn = testApplyFn + p.DiffFn = testDiffFn + + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "template": testProviderFuncFixed(p), + }, + UIInput: input, + }) + + w, e := ctx.Validate() + if w != nil { + t.Log("warnings:", w) + } + if e != nil { + t.Fatal("err:", e) + } +} diff --git a/terraform/graph_config_node_output.go b/terraform/graph_config_node_output.go index ac364a308..0704a0cb7 100644 --- a/terraform/graph_config_node_output.go +++ b/terraform/graph_config_node_output.go @@ -44,7 +44,8 @@ func (n *GraphNodeConfigOutput) DependentOn() []string { // GraphNodeEvalable impl. func (n *GraphNodeConfigOutput) EvalTree() EvalNode { return &EvalOpFilter{ - Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy, walkInput}, + Ops: []walkOperation{walkRefresh, walkPlan, walkApply, + walkDestroy, walkInput, walkValidate}, Node: &EvalSequence{ Nodes: []EvalNode{ &EvalWriteOutput{ diff --git a/terraform/interpolate.go b/terraform/interpolate.go index 8ed74490d..2d3c57c5b 100644 --- a/terraform/interpolate.go +++ b/terraform/interpolate.go @@ -130,16 +130,6 @@ func (i *Interpolater) valueModuleVar( v *config.ModuleVariable, result map[string]ast.Variable) error { - // If we're computing all dynamic fields, then module vars count - // and we mark it as computed. - if i.Operation == walkValidate { - result[n] = ast.Variable{ - Value: config.UnknownVariableValue, - Type: ast.TypeString, - } - return nil - } - // Build the path to the child module we want path := make([]string, len(scope.Path), len(scope.Path)+1) copy(path, scope.Path)