terraform: Add test case reproducing #7241

The reproduction of issue #7421 involves a list of maps being passed to
a module, where one or more of the maps has a value which is computed
(for example, from another resource). There is a failure at the point of
use (via lookup interpolation) of the computed value of the form:

```
lookup: lookup failed to find 'elb' in:
${lookup(var.services[count.index], "elb")}
```

Where 'elb' is the key of the map.
This commit is contained in:
James Nugent 2016-07-07 19:14:33 +01:00
parent 1401a52a5c
commit 088feb933f
4 changed files with 79 additions and 0 deletions

View File

@ -2325,3 +2325,43 @@ func TestContext2Plan_moduleMapLiteral(t *testing.T) {
t.Fatalf("err: %s", err) t.Fatalf("err: %s", err)
} }
} }
func TestContext2Plan_computedValueInMap(t *testing.T) {
m := testModule(t, "plan-computed-value-in-map")
p := testProvider("aws")
p.DiffFn = func(info *InstanceInfo, state *InstanceState, c *ResourceConfig) (*InstanceDiff, error) {
switch info.Type {
case "aws_computed_source":
return &InstanceDiff{
Attributes: map[string]*ResourceAttrDiff{
"computed_read_only": &ResourceAttrDiff{
NewComputed: true,
},
},
}, nil
}
return testDiffFn(info, state, c)
}
ctx := testContext2(t, &ContextOpts{
Module: m,
Providers: map[string]ResourceProviderFactory{
"aws": testProviderFuncFixed(p),
},
})
if _, err := ctx.Plan(); err != nil {
t.Fatalf("err: %s", err)
}
plan, err := ctx.Plan()
if err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(plan.String())
expected := strings.TrimSpace(testTerraformPlanComputedValueInMap)
if actual != expected {
t.Fatalf("bad:\n%s\n\nexpected\n\n%s", actual, expected)
}
}

View File

@ -1355,3 +1355,19 @@ aws_instance.foo:
ID = bar ID = bar
ami = ami-abcd1234 ami = ami-abcd1234
` `
const testTerraformPlanComputedValueInMap = `
DIFF:
CREATE: aws_computed_source.intermediates
computed_read_only: "" => "<computed>"
module.test_mod:
CREATE: aws_instance.inner2
looked_up: "" => "<computed>"
type: "" => "aws_instance"
STATE:
<no state>
`

View File

@ -0,0 +1,15 @@
resource "aws_computed_source" "intermediates" {}
module "test_mod" {
source = "./mod"
services {
"exists" = "true"
"elb" = "${aws_computed_source.intermediates.computed_read_only}"
}
services {
"otherexists" = " true"
"elb" = "${aws_computed_source.intermediates.computed_read_only}"
}
}

View File

@ -0,0 +1,8 @@
variable "services" {
type = "list"
}
resource "aws_instance" "inner2" {
looked_up = "${lookup(var.services[0], "elb")}"
}