core: if InstanceState has empty id after apply, instance is deleted

Previously we would just retain an empty InstanceState in this case, but
now that we must enumerate all of the available instances during
expression evaluation it's important that we be able to recognize
instances that have been deleted.
This commit is contained in:
Martin Atkins 2018-05-30 15:47:11 -07:00
parent 90893eb3f9
commit cdce0d7e27
2 changed files with 13 additions and 0 deletions

View File

@ -80,6 +80,14 @@ func (n *EvalApply) Eval(ctx EvalContext) (interface{}, error) {
}
}
// If the provider produced an InstanceState with an empty id then
// that really means that there's no state at all.
// FIXME: Change the provider protocol so that the provider itself returns
// a null in this case, and stop treating the ID as special.
if state.ID == "" {
state = nil
}
// Write the final state
if n.Output != nil {
*n.Output = state

View File

@ -141,6 +141,11 @@ type EvalWriteState struct {
func (n *EvalWriteState) Eval(ctx EvalContext) (interface{}, error) {
return writeInstanceToState(ctx, n.Name, n.ResourceType, n.Provider.String(), n.Dependencies,
func(rs *ResourceState) error {
if *n.State != nil {
log.Printf("[TRACE] EvalWriteState: %s has non-nil state", n.Name)
} else {
log.Printf("[TRACE] EvalWriteState: %s has nil state", n.Name)
}
rs.Primary = *n.State
return nil
},