diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index b6f696dd3..58ae89124 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -660,6 +660,23 @@ func TestContext2Plan_moduleVarWrongTypeNested(t *testing.T) { } } +func TestContext2Plan_moduleVarWithDefaultValue(t *testing.T) { + m := testModule(t, "plan-module-var-with-default-value") + p := testProvider("null") + p.DiffFn = testDiffFn + ctx := testContext2(t, &ContextOpts{ + Module: m, + Providers: map[string]ResourceProviderFactory{ + "null": testProviderFuncFixed(p), + }, + }) + + _, err := ctx.Plan() + if err != nil { + t.Fatalf("bad: %s", err) + } +} + func TestContext2Plan_moduleVarComputed(t *testing.T) { m := testModule(t, "plan-module-var-computed") p := testProvider("aws") diff --git a/terraform/eval_variable.go b/terraform/eval_variable.go index 6b2130e20..216efe5b8 100644 --- a/terraform/eval_variable.go +++ b/terraform/eval_variable.go @@ -48,7 +48,12 @@ func (n *EvalTypeCheckVariable) Eval(ctx EvalContext) (interface{}, error) { // that at the current time we are dealing with a type system consisting only // of strings and maps - where the only valid inter-module variable type is // string. - // proposedValue := n.Variables[name] + _, ok := n.Variables[name] + if !ok { + // This means the default value should be used as no overriding value + // has been set. Therefore we should continue as no check is necessary. + continue + } switch declaredType { case config.VariableTypeString: diff --git a/terraform/test-fixtures/plan-module-var-with-default-value/inner/main.tf b/terraform/test-fixtures/plan-module-var-with-default-value/inner/main.tf new file mode 100644 index 000000000..8a089655a --- /dev/null +++ b/terraform/test-fixtures/plan-module-var-with-default-value/inner/main.tf @@ -0,0 +1,12 @@ +variable "im_a_string" { + type = "string" +} + +variable "service_region_ami" { + type = "map" + default = { + us-east-1 = "ami-e4c9db8e" + } +} + +resource "null_resource" "noop" {} diff --git a/terraform/test-fixtures/plan-module-var-with-default-value/main.tf b/terraform/test-fixtures/plan-module-var-with-default-value/main.tf new file mode 100644 index 000000000..96b27418a --- /dev/null +++ b/terraform/test-fixtures/plan-module-var-with-default-value/main.tf @@ -0,0 +1,7 @@ +resource "null_resource" "noop" {} + +module "test" { + source = "./inner" + + im_a_string = "hello" +}