Skip to content

Commit 20f5c5e

Browse files
committed
validation: don't strip marks from variables during validation
1 parent 5534e3d commit 20f5c5e

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: 'variable validation: keep sensitive and ephemeral metadata when evaluating variable conditions.'
3+
time: 2025-09-11T14:20:38.411183+02:00
4+
custom:
5+
Issue: "37595"

internal/terraform/eval_variable.go

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -281,31 +281,33 @@ func evalVariableValidations(addr addrs.AbsInputVariableInstance, ctx EvalContex
281281
// Although that behavior was accidental, it makes simple validation rules
282282
// more useful and is protected by compatibility promises, and so we'll
283283
// fake it here by overwriting the unknown value that scope.EvalContext
284-
// will have inserted with a possibly-more-known value using the same
285-
// strategy our special code used to use.
286-
ourVal := ctx.NamedValues().GetInputVariableValue(addr)
287-
if ourVal != cty.NilVal {
288-
// (it would be weird for ourVal to be nil here, but we'll tolerate it
289-
// because it was scope.EvalContext's responsibility to check for the
290-
// absent final value, and even if it didn't we'll just get an
291-
// evaluation error when evaluating the expressions below anyway.)
292-
293-
// Our goal here is to make sure that a reference to the variable
294-
// we're checking will evaluate to ourVal, regardless of what else
295-
// scope.EvalContext might have put in the variables table.
296-
if hclCtx.Variables == nil {
297-
hclCtx.Variables = make(map[string]cty.Value)
298-
}
299-
if varsVal, ok := hclCtx.Variables["var"]; ok {
300-
// Unfortunately we need to unpack and repack the object here,
301-
// because cty values are immutable.
302-
attrs := varsVal.AsValueMap()
303-
attrs[addr.Variable.Name] = ourVal
304-
hclCtx.Variables["var"] = cty.ObjectVal(attrs)
305-
} else {
306-
hclCtx.Variables["var"] = cty.ObjectVal(map[string]cty.Value{
307-
addr.Variable.Name: ourVal,
308-
})
284+
// will have inserted during validate walks with a possibly-more-known value
285+
// using the same strategy our special code used to use.
286+
if validateWalk {
287+
ourVal := ctx.NamedValues().GetInputVariableValue(addr)
288+
if ourVal != cty.NilVal {
289+
// (it would be weird for ourVal to be nil here, but we'll tolerate it
290+
// because it was scope.EvalContext's responsibility to check for the
291+
// absent final value, and even if it didn't we'll just get an
292+
// evaluation error when evaluating the expressions below anyway.)
293+
294+
// Our goal here is to make sure that a reference to the variable
295+
// we're checking will evaluate to ourVal, regardless of what else
296+
// scope.EvalContext might have put in the variables table.
297+
if hclCtx.Variables == nil {
298+
hclCtx.Variables = make(map[string]cty.Value)
299+
}
300+
if varsVal, ok := hclCtx.Variables["var"]; ok {
301+
// Unfortunately we need to unpack and repack the object here,
302+
// because cty values are immutable.
303+
attrs := varsVal.AsValueMap()
304+
attrs[addr.Variable.Name] = ourVal
305+
hclCtx.Variables["var"] = cty.ObjectVal(attrs)
306+
} else {
307+
hclCtx.Variables["var"] = cty.ObjectVal(map[string]cty.Value{
308+
addr.Variable.Name: ourVal,
309+
})
310+
}
309311
}
310312
}
311313

0 commit comments

Comments
 (0)