Module variables not being interpolated

Variables weren't being interpolated during the Input phase, causing a
syntax error on the interpolation string. Adding `walkInput` to the
EvalTree operations prevents skipping the interpolation step.
This commit is contained in:
James Bardin 2016-05-19 10:46:51 -07:00
parent 55583baa7e
commit fc4ac52014
8 changed files with 40 additions and 4 deletions

View File

@ -569,3 +569,26 @@ func TestContext2Input_varPartiallyComputed(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
} }
// Module variables weren't being interpolated during the Input walk.
// https://github.com/hashicorp/terraform/issues/5322
func TestContext2Input_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,
})
if err := ctx.Input(InputModeStd); err != nil {
t.Fatalf("err: %s", err)
}
}

View File

@ -291,6 +291,7 @@ func (ctx *BuiltinEvalContext) Interpolate(
Path: ctx.Path(), Path: ctx.Path(),
Resource: r, Resource: r,
} }
vs, err := ctx.Interpolater.Values(scope, cfg.Variables) vs, err := ctx.Interpolater.Values(scope, cfg.Variables)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -1,8 +1,6 @@
package terraform package terraform
import ( import "github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/config"
)
// EvalInterpolate is an EvalNode implementation that takes a raw // EvalInterpolate is an EvalNode implementation that takes a raw
// configuration and interpolates it. // configuration and interpolates it.

View File

@ -44,7 +44,7 @@ func (n *GraphNodeConfigOutput) DependentOn() []string {
// GraphNodeEvalable impl. // GraphNodeEvalable impl.
func (n *GraphNodeConfigOutput) EvalTree() EvalNode { func (n *GraphNodeConfigOutput) EvalTree() EvalNode {
return &EvalOpFilter{ return &EvalOpFilter{
Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy}, Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy, walkInput},
Node: &EvalSequence{ Node: &EvalSequence{
Nodes: []EvalNode{ Nodes: []EvalNode{
&EvalWriteOutput{ &EvalWriteOutput{

View File

@ -129,6 +129,7 @@ func (i *Interpolater) valueModuleVar(
n string, n string,
v *config.ModuleVariable, v *config.ModuleVariable,
result map[string]ast.Variable) error { result map[string]ast.Variable) error {
// If we're computing all dynamic fields, then module vars count // If we're computing all dynamic fields, then module vars count
// and we mark it as computed. // and we mark it as computed.
if i.Operation == walkValidate { if i.Operation == walkValidate {

View File

@ -0,0 +1,5 @@
variable "list" { }
resource "template_file" "temp" {
count = "${length(split(",", var.list))}"
template = "foo"
}

View File

@ -0,0 +1,7 @@
module "source" {
source = "./source"
}
module "child" {
source = "./child"
list = "${module.source.list}"
}

View File

@ -0,0 +1 @@
output "list" { value = "foo,bar,baz" }