core: Extra TRACE logging in the eval_state.go eval nodes.
Tracking when each instance's state is read, written, or removed is often very useful in debugging strange interactions.
This commit is contained in:
parent
a37d5268eb
commit
59175e466e
|
@ -2,6 +2,7 @@ package terraform
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform/addrs"
|
"github.com/hashicorp/terraform/addrs"
|
||||||
"github.com/hashicorp/terraform/providers"
|
"github.com/hashicorp/terraform/providers"
|
||||||
|
@ -35,9 +36,12 @@ func (n *EvalReadState) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
absAddr := n.Addr.Absolute(ctx.Path())
|
absAddr := n.Addr.Absolute(ctx.Path())
|
||||||
|
log.Printf("[TRACE] EvalReadState: reading state for %s", absAddr)
|
||||||
|
|
||||||
src := ctx.State().ResourceInstanceObject(absAddr, states.CurrentGen)
|
src := ctx.State().ResourceInstanceObject(absAddr, states.CurrentGen)
|
||||||
if src == nil {
|
if src == nil {
|
||||||
// Presumably we only have deposed objects, then.
|
// Presumably we only have deposed objects, then.
|
||||||
|
log.Printf("[TRACE] EvalReadState: no state present for %s", absAddr)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,9 +92,12 @@ func (n *EvalReadStateDeposed) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
return nil, fmt.Errorf("EvalReadStateDeposed used with no instance key; this is a bug in Terraform and should be reported")
|
return nil, fmt.Errorf("EvalReadStateDeposed used with no instance key; this is a bug in Terraform and should be reported")
|
||||||
}
|
}
|
||||||
absAddr := n.Addr.Absolute(ctx.Path())
|
absAddr := n.Addr.Absolute(ctx.Path())
|
||||||
|
log.Printf("[TRACE] EvalReadStateDeposed: reading state for %s deposed object %s", absAddr, n.Key)
|
||||||
|
|
||||||
src := ctx.State().ResourceInstanceObject(absAddr, key)
|
src := ctx.State().ResourceInstanceObject(absAddr, key)
|
||||||
if src == nil {
|
if src == nil {
|
||||||
// Presumably we only have deposed objects, then.
|
// Presumably we only have deposed objects, then.
|
||||||
|
log.Printf("[TRACE] EvalReadStateDeposed: no state present for %s deposed object %s", absAddr, n.Key)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +196,7 @@ func (n *EvalWriteState) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
if obj == nil {
|
if obj == nil {
|
||||||
// No need to encode anything: we'll just write it directly.
|
// No need to encode anything: we'll just write it directly.
|
||||||
state.SetResourceInstanceCurrent(absAddr, nil, n.ProviderAddr)
|
state.SetResourceInstanceCurrent(absAddr, nil, n.ProviderAddr)
|
||||||
|
log.Printf("[TRACE] EvalWriteState: removing state object for %s", absAddr)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if n.ProviderSchema == nil || *n.ProviderSchema == nil {
|
if n.ProviderSchema == nil || *n.ProviderSchema == nil {
|
||||||
|
@ -196,6 +204,8 @@ func (n *EvalWriteState) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
panic("EvalWriteState used with pointer to nil ProviderSchema object")
|
panic("EvalWriteState used with pointer to nil ProviderSchema object")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[TRACE] EvalWriteState: writing state object for %s", absAddr)
|
||||||
|
|
||||||
// TODO: Update this to use providers.Schema and populate the real
|
// TODO: Update this to use providers.Schema and populate the real
|
||||||
// schema version in the second argument to Encode below.
|
// schema version in the second argument to Encode below.
|
||||||
schema := (*n.ProviderSchema).SchemaForResourceAddr(n.Addr.ContainingResource())
|
schema := (*n.ProviderSchema).SchemaForResourceAddr(n.Addr.ContainingResource())
|
||||||
|
@ -253,7 +263,8 @@ func (n *EvalWriteStateDeposed) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
obj := *n.State
|
obj := *n.State
|
||||||
if obj == nil {
|
if obj == nil {
|
||||||
// No need to encode anything: we'll just write it directly.
|
// No need to encode anything: we'll just write it directly.
|
||||||
state.SetResourceInstanceCurrent(absAddr, nil, n.ProviderAddr)
|
state.SetResourceInstanceDeposed(absAddr, key, nil, n.ProviderAddr)
|
||||||
|
log.Printf("[TRACE] EvalWriteStateDeposed: removing state object for %s deposed %s", absAddr, key)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
if n.ProviderSchema == nil || *n.ProviderSchema == nil {
|
if n.ProviderSchema == nil || *n.ProviderSchema == nil {
|
||||||
|
@ -275,6 +286,7 @@ func (n *EvalWriteStateDeposed) Eval(ctx EvalContext) (interface{}, error) {
|
||||||
return nil, fmt.Errorf("failed to encode %s in state: %s", absAddr, err)
|
return nil, fmt.Errorf("failed to encode %s in state: %s", absAddr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("[TRACE] EvalWriteStateDeposed: writing state object for %s deposed %s", absAddr, key)
|
||||||
state.SetResourceInstanceDeposed(absAddr, key, src, n.ProviderAddr)
|
state.SetResourceInstanceDeposed(absAddr, key, src, n.ProviderAddr)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue