Skip to content

Commit

Permalink
Merge pull request #6298 from hashicorp/b-type-check-unset
Browse files Browse the repository at this point in the history
core: Do not type check unset variables
  • Loading branch information
jen20 committed Apr 22, 2016
2 parents d85df63 + 31cc2d2 commit 13c1838
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
17 changes: 17 additions & 0 deletions terraform/context_plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 6 additions & 1 deletion terraform/eval_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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" {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
resource "null_resource" "noop" {}

module "test" {
source = "./inner"

im_a_string = "hello"
}

0 comments on commit 13c1838

Please sign in to comment.