mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
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:
parent
1401a52a5c
commit
088feb933f
@ -2325,3 +2325,43 @@ func TestContext2Plan_moduleMapLiteral(t *testing.T) {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -1355,3 +1355,19 @@ aws_instance.foo:
|
||||
ID = bar
|
||||
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>
|
||||
`
|
||||
|
15
terraform/test-fixtures/plan-computed-value-in-map/main.tf
Normal file
15
terraform/test-fixtures/plan-computed-value-in-map/main.tf
Normal 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}"
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
variable "services" {
|
||||
type = "list"
|
||||
}
|
||||
|
||||
resource "aws_instance" "inner2" {
|
||||
looked_up = "${lookup(var.services[0], "elb")}"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user