mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Add a special error for each.value
This commit is contained in:
parent
d7bce857cf
commit
13ff341447
@ -2079,7 +2079,7 @@ func TestContext2Apply_provisionerDestroyForEach(t *testing.T) {
|
|||||||
if diags == nil {
|
if diags == nil {
|
||||||
t.Fatal("should error")
|
t.Fatal("should error")
|
||||||
}
|
}
|
||||||
if !strings.Contains(diags.Err().Error(), `Reference to "each" in context without for_each`) {
|
if !strings.Contains(diags.Err().Error(), "each.value is unknown and cannot be used in this context") {
|
||||||
t.Fatal("unexpected error:", diags.Err())
|
t.Fatal("unexpected error:", diags.Err())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -185,6 +185,16 @@ func (d *evaluationStateData) GetForEachAttr(addr addrs.ForEachAttr, rng tfdiags
|
|||||||
returnVal = d.InstanceKeyData.EachKey
|
returnVal = d.InstanceKeyData.EachKey
|
||||||
case "value":
|
case "value":
|
||||||
returnVal = d.InstanceKeyData.EachValue
|
returnVal = d.InstanceKeyData.EachValue
|
||||||
|
|
||||||
|
if returnVal == cty.NilVal {
|
||||||
|
diags = diags.Append(&hcl.Diagnostic{
|
||||||
|
Severity: hcl.DiagError,
|
||||||
|
Summary: `each.value is unknown and cannot be used in this context`,
|
||||||
|
Detail: fmt.Sprintf(`A reference to "each.value" has been used in a context in which it unavailable, such as after the config no longer contains the value in its "for_each" expression. Remove this reference to each.value in your config to work around this error.`),
|
||||||
|
Subject: rng.ToHCL().Ptr(),
|
||||||
|
})
|
||||||
|
return cty.UnknownVal(cty.DynamicPseudoType), diags
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
diags = diags.Append(&hcl.Diagnostic{
|
diags = diags.Append(&hcl.Diagnostic{
|
||||||
Severity: hcl.DiagError,
|
Severity: hcl.DiagError,
|
||||||
|
Loading…
Reference in New Issue
Block a user