mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
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:
parent
55583baa7e
commit
fc4ac52014
@ -569,3 +569,26 @@ func TestContext2Input_varPartiallyComputed(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -291,6 +291,7 @@ func (ctx *BuiltinEvalContext) Interpolate(
|
||||
Path: ctx.Path(),
|
||||
Resource: r,
|
||||
}
|
||||
|
||||
vs, err := ctx.Interpolater.Values(scope, cfg.Variables)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1,8 +1,6 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/terraform/config"
|
||||
)
|
||||
import "github.com/hashicorp/terraform/config"
|
||||
|
||||
// EvalInterpolate is an EvalNode implementation that takes a raw
|
||||
// configuration and interpolates it.
|
||||
|
@ -44,7 +44,7 @@ func (n *GraphNodeConfigOutput) DependentOn() []string {
|
||||
// GraphNodeEvalable impl.
|
||||
func (n *GraphNodeConfigOutput) EvalTree() EvalNode {
|
||||
return &EvalOpFilter{
|
||||
Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy},
|
||||
Ops: []walkOperation{walkRefresh, walkPlan, walkApply, walkDestroy, walkInput},
|
||||
Node: &EvalSequence{
|
||||
Nodes: []EvalNode{
|
||||
&EvalWriteOutput{
|
||||
|
@ -129,6 +129,7 @@ func (i *Interpolater) valueModuleVar(
|
||||
n string,
|
||||
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 {
|
||||
|
@ -0,0 +1,5 @@
|
||||
variable "list" { }
|
||||
resource "template_file" "temp" {
|
||||
count = "${length(split(",", var.list))}"
|
||||
template = "foo"
|
||||
}
|
7
terraform/test-fixtures/input-interpolate-var/main.tf
Normal file
7
terraform/test-fixtures/input-interpolate-var/main.tf
Normal file
@ -0,0 +1,7 @@
|
||||
module "source" {
|
||||
source = "./source"
|
||||
}
|
||||
module "child" {
|
||||
source = "./child"
|
||||
list = "${module.source.list}"
|
||||
}
|
@ -0,0 +1 @@
|
||||
output "list" { value = "foo,bar,baz" }
|
Loading…
Reference in New Issue
Block a user