core: Tolerate the prior state being nil in EvalDiff

This happens legitimately in situations where we'll be creating an object
for this resource instance for the first time.
pull/19086/head
Martin Atkins 8 years ago
parent 7d760c09fb
commit ec11efc50a

@ -97,9 +97,6 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) {
var diags tfdiags.Diagnostics
absAddr := n.Addr.Absolute(ctx.Path())
priorVal := state.Value
// Evaluate the configuration
schema := providerSchema.ResourceTypes[n.Addr.Resource.Type]
if schema == nil {
@ -113,6 +110,16 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) {
return nil, diags.Err()
}
absAddr := n.Addr.Absolute(ctx.Path())
var priorVal cty.Value
var priorPrivate []byte
if state != nil {
priorVal = state.Value
priorPrivate = state.Private
} else {
priorVal = cty.NullVal(schema.ImpliedType())
}
proposedNewVal := objchange.ProposedNewObject(schema, priorVal, configVal)
// Call pre-diff hook
@ -132,7 +139,7 @@ func (n *EvalDiff) Eval(ctx EvalContext) (interface{}, error) {
Config: configVal,
PriorState: priorVal,
ProposedNewState: proposedNewVal,
PriorPrivate: state.Private,
PriorPrivate: priorPrivate,
})
diags = diags.Append(resp.Diagnostics.InConfigBody(config.Config))
if diags.HasErrors() {

Loading…
Cancel
Save