This commit is contained in:
Leon Cieslik 2026-02-03 11:29:27 -05:00 committed by GitHub
commit d053fdcbbe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 4 deletions

View file

@ -0,0 +1,5 @@
kind: BUG FIXES
body: Improve wording of for_each key dependency error when using a set
time: 2025-10-28T10:48:50.112437+00:00
custom:
Issue: ""

View file

@ -221,7 +221,7 @@ func (ev *forEachEvaluator) ensureKnownForResource(forEachVal cty.Value) tfdiags
var diags tfdiags.Diagnostics
ty := forEachVal.Type()
const errInvalidUnknownDetailMap = "The \"for_each\" map includes keys derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys that will identify the instances of this resource.\n\nWhen working with unknown values in for_each, it's better to define the map keys statically in your configuration and place apply-time results only in the map values.\n\nAlternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully converge."
const errInvalidUnknownDetailSet = "The \"for_each\" set includes values derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys that will identify the instances of this resource.\n\nWhen working with unknown values in for_each, it's better to use a map value where the keys are defined statically in your configuration and where only the values contain apply-time results.\n\nAlternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully converge."
const errInvalidUnknownDetailSet = "The \"for_each\" set includes elements derived from resource attributes that cannot be determined until apply, and so Terraform cannot determine the full set of keys that will identify the instances of this resource.\n\nWhen working with unknown values in for_each, it's better to use a map value where the map keys are defined statically in your configuration and only the map values contain apply-time results.\n\nAlternatively, you could use the -target planning option to first apply only the resources that the for_each value depends on, and then apply a second time to fully converge."
if !forEachVal.IsKnown() {
var detailMsg string

View file

@ -136,7 +136,7 @@ func TestEvaluateForEachExpression_errors(t *testing.T) {
"unknown string set": {
hcltest.MockExprLiteral(cty.UnknownVal(cty.Set(cty.String))),
"Invalid for_each argument",
"set includes values derived from resource attributes that cannot be determined until apply",
"set includes elements derived from resource attributes that cannot be determined until apply",
true, false, false,
},
"unknown map": {
@ -178,13 +178,13 @@ func TestEvaluateForEachExpression_errors(t *testing.T) {
"set containing unknown value": {
hcltest.MockExprLiteral(cty.SetVal([]cty.Value{cty.UnknownVal(cty.String)})),
"Invalid for_each argument",
"set includes values derived from resource attributes that cannot be determined until apply",
"set includes elements derived from resource attributes that cannot be determined until apply",
true, false, false,
},
"set containing dynamic unknown value": {
hcltest.MockExprLiteral(cty.SetVal([]cty.Value{cty.UnknownVal(cty.DynamicPseudoType)})),
"Invalid for_each argument",
"set includes values derived from resource attributes that cannot be determined until apply",
"set includes elements derived from resource attributes that cannot be determined until apply",
true, false, false,
},
"set containing sensitive values": {