core: EvalWriteOutput discard unknown values before writing state

The state only deals in wholly-known values, so here we null out any
unknowns for storage in state. This is okay because we subsequently write
the original, possibly-unknown value into the plan and the expression
evaluator will prefer to use this if present, allowing the unknown values
to properly propagate into other expressions in the calling module.
This commit is contained in:
Martin Atkins 2018-09-13 13:24:29 -07:00
parent a709b9f07a
commit ace46e9669

View File

@ -68,7 +68,11 @@ func (n *EvalWriteOutput) Eval(ctx EvalContext) (interface{}, error) {
}
if val.IsKnown() && !val.IsNull() {
state.SetOutputValue(addr, val, n.Sensitive)
// The state itself doesn't represent unknown values, so we null them
// out here and then we'll save the real unknown value in the planned
// changeset below, if we have one on this graph walk.
stateVal := cty.UnknownAsNull(val)
state.SetOutputValue(addr, stateVal, n.Sensitive)
} else {
state.RemoveOutputValue(addr)
}