Skip to content

Commit 592df71

Browse files
committed
Merge pull request hashicorp#2478 from hashicorp/b-invalid-var-should-error
terraform: error if resource not found in module [hashicorpGH-1997]
2 parents bd17fa5 + fcc710c commit 592df71

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎terraform/context_test.go‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6615,6 +6615,23 @@ func TestContext2Apply_unknownAttribute(t *testing.T) {
66156615
}
66166616
}
66176617

6618+
func TestContext2Apply_unknownAttributeInterpolate(t *testing.T) {
6619+
m := testModule(t, "apply-unknown-interpolate")
6620+
p := testProvider("aws")
6621+
p.ApplyFn = testApplyFn
6622+
p.DiffFn = testDiffFn
6623+
ctx := testContext2(t, &ContextOpts{
6624+
Module: m,
6625+
Providers: map[string]ResourceProviderFactory{
6626+
"aws": testProviderFuncFixed(p),
6627+
},
6628+
})
6629+
6630+
if _, err := ctx.Plan(); err == nil {
6631+
t.Fatal("should error")
6632+
}
6633+
}
6634+
66186635
func TestContext2Apply_vars(t *testing.T) {
66196636
m := testModule(t, "apply-vars")
66206637
p := testProvider("aws")

‎terraform/interpolate.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ MISSING:
362362
// Validation for missing interpolations should happen at a higher
363363
// semantic level. If we reached this point and don't have variables,
364364
// just return the computed value.
365-
if scope == nil || scope.Resource == nil {
365+
if scope == nil && scope.Resource == nil {
366366
return config.UnknownVariableValue, nil
367367
}
368368

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
variable "value" {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
resource "aws_instance" "foo" {}
2+
3+
module "child" {
4+
source = "./child"
5+
value = "${aws_instance.foo.nope}"
6+
}

0 commit comments

Comments
 (0)