@@ -281,31 +281,33 @@ func evalVariableValidations(addr addrs.AbsInputVariableInstance, ctx EvalContex
281
281
// Although that behavior was accidental, it makes simple validation rules
282
282
// more useful and is protected by compatibility promises, and so we'll
283
283
// 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
+ }
309
311
}
310
312
}
311
313
0 commit comments