From cdce0d7e274076e4dac286f0e67bba52793890a0 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Wed, 30 May 2018 15:47:11 -0700 Subject: [PATCH] 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. --- terraform/eval_apply.go | 8 ++++++++ terraform/eval_state.go | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/terraform/eval_apply.go b/terraform/eval_apply.go index 69cbbf470..c445e25ab 100644 --- a/terraform/eval_apply.go +++ b/terraform/eval_apply.go @@ -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 diff --git a/terraform/eval_state.go b/terraform/eval_state.go index 36051e1e5..596e5659e 100644 --- a/terraform/eval_state.go +++ b/terraform/eval_state.go @@ -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 },