Revert the evaluation change from #29862.
While returning a dynamic value for all expanded resources during
validation is not optimal, trying to work around this using unknown maps
and lists is causing other undesirable behaviors during evaluation.
This commit is contained in:
James Bardin 2021-12-14 17:50:53 -05:00
parent 6530055d18
commit d469e86331
3 changed files with 6 additions and 16 deletions

View File

@ -5308,7 +5308,6 @@ func TestContext2Plan_selfRefMultiAll(t *testing.T) {
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]*configschema.Block{
"aws_instance": { "aws_instance": {
Attributes: map[string]*configschema.Attribute{ Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true},
"foo": {Type: cty.List(cty.String), Optional: true}, "foo": {Type: cty.List(cty.String), Optional: true},
}, },
}, },

View File

@ -696,21 +696,12 @@ func (d *evaluationStateData) GetResource(addr addrs.Resource, rng tfdiags.Sourc
log.Printf("[ERROR] unknown instance %q referenced during %s", addr.Absolute(d.ModulePath), d.Operation) log.Printf("[ERROR] unknown instance %q referenced during %s", addr.Absolute(d.ModulePath), d.Operation)
return cty.DynamicVal, diags return cty.DynamicVal, diags
} }
default:
if d.Operation != walkValidate {
log.Printf("[ERROR] missing state for %q while in %s\n", addr.Absolute(d.ModulePath), d.Operation)
}
// Validation is done with only the configuration, so generate default:
// unknown values of the correct shape for evaluation. // We should only end up here during the validate walk,
switch { // since later walks should have at least partial states populated
case config.Count != nil: // for all resources in the configuration.
return cty.UnknownVal(cty.List(ty)), diags return cty.DynamicVal, diags
case config.ForEach != nil:
return cty.UnknownVal(cty.Map(ty)), diags
default:
return cty.UnknownVal(ty), diags
}
} }
} }

View File

@ -1,4 +1,4 @@
resource "aws_instance" "web" { resource "aws_instance" "web" {
foo = aws_instance.web[*].id foo = "${aws_instance.web.*.foo}"
count = 4 count = 4
} }