|
|
|
|
@ -56,6 +56,9 @@ func (n *EvalReadStateDeposed) Eval(ctx EvalContext) (interface{}, error) {
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Does the bulk of the work for the various flavors of ReadState eval nodes.
|
|
|
|
|
// Each node just provides a function to get from the ResourceState to the
|
|
|
|
|
// InstanceState, and this takes care of all the plumbing.
|
|
|
|
|
func readInstanceFromState(
|
|
|
|
|
ctx EvalContext,
|
|
|
|
|
resourceName string,
|
|
|
|
|
@ -138,17 +141,12 @@ func (n *EvalUpdateStateHook) Eval(ctx EvalContext) (interface{}, error) {
|
|
|
|
|
// EvalWriteState is an EvalNode implementation that reads the
|
|
|
|
|
// InstanceState for a specific resource out of the state.
|
|
|
|
|
type EvalWriteState struct {
|
|
|
|
|
Name string
|
|
|
|
|
ResourceType string
|
|
|
|
|
Dependencies []string
|
|
|
|
|
State **InstanceState
|
|
|
|
|
Tainted *bool
|
|
|
|
|
TaintedIndex int
|
|
|
|
|
TaintedClearPrimary bool
|
|
|
|
|
Deposed bool
|
|
|
|
|
Name string
|
|
|
|
|
ResourceType string
|
|
|
|
|
Dependencies []string
|
|
|
|
|
State **InstanceState
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: test
|
|
|
|
|
func (n *EvalWriteState) Eval(ctx EvalContext) (interface{}, error) {
|
|
|
|
|
state, lock := ctx.State()
|
|
|
|
|
if state == nil {
|
|
|
|
|
@ -175,23 +173,120 @@ func (n *EvalWriteState) Eval(ctx EvalContext) (interface{}, error) {
|
|
|
|
|
rs.Type = n.ResourceType
|
|
|
|
|
rs.Dependencies = n.Dependencies
|
|
|
|
|
|
|
|
|
|
if n.Tainted != nil && *n.Tainted {
|
|
|
|
|
if n.TaintedIndex != -1 {
|
|
|
|
|
rs.Tainted[n.TaintedIndex] = *n.State
|
|
|
|
|
} else {
|
|
|
|
|
rs.Tainted = append(rs.Tainted, *n.State)
|
|
|
|
|
}
|
|
|
|
|
rs.Primary = *n.State
|
|
|
|
|
|
|
|
|
|
if n.TaintedClearPrimary {
|
|
|
|
|
rs.Primary = nil
|
|
|
|
|
}
|
|
|
|
|
} else if n.Deposed {
|
|
|
|
|
rs.Deposed = *n.State
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type EvalWriteStateTainted struct {
|
|
|
|
|
Name string
|
|
|
|
|
ResourceType string
|
|
|
|
|
Dependencies []string
|
|
|
|
|
State **InstanceState
|
|
|
|
|
TaintedIndex int
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *EvalWriteStateTainted) Eval(ctx EvalContext) (interface{}, error) {
|
|
|
|
|
state, lock := ctx.State()
|
|
|
|
|
if state == nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot write state to nil state")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get a write lock so we can access this instance
|
|
|
|
|
lock.Lock()
|
|
|
|
|
defer lock.Unlock()
|
|
|
|
|
|
|
|
|
|
// Look for the module state. If we don't have one, create it.
|
|
|
|
|
mod := state.ModuleByPath(ctx.Path())
|
|
|
|
|
if mod == nil {
|
|
|
|
|
mod = state.AddModule(ctx.Path())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Look for the resource state.
|
|
|
|
|
rs := mod.Resources[n.Name]
|
|
|
|
|
if rs == nil {
|
|
|
|
|
rs = &ResourceState{}
|
|
|
|
|
rs.init()
|
|
|
|
|
mod.Resources[n.Name] = rs
|
|
|
|
|
}
|
|
|
|
|
rs.Type = n.ResourceType
|
|
|
|
|
rs.Dependencies = n.Dependencies
|
|
|
|
|
|
|
|
|
|
if n.TaintedIndex == -1 {
|
|
|
|
|
rs.Tainted = append(rs.Tainted, *n.State)
|
|
|
|
|
} else {
|
|
|
|
|
// Set the primary state
|
|
|
|
|
rs.Primary = *n.State
|
|
|
|
|
rs.Tainted[n.TaintedIndex] = *n.State
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type EvalWriteStateDeposed struct {
|
|
|
|
|
Name string
|
|
|
|
|
ResourceType string
|
|
|
|
|
Dependencies []string
|
|
|
|
|
State **InstanceState
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *EvalWriteStateDeposed) Eval(ctx EvalContext) (interface{}, error) {
|
|
|
|
|
state, lock := ctx.State()
|
|
|
|
|
if state == nil {
|
|
|
|
|
return nil, fmt.Errorf("cannot write state to nil state")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get a write lock so we can access this instance
|
|
|
|
|
lock.Lock()
|
|
|
|
|
defer lock.Unlock()
|
|
|
|
|
|
|
|
|
|
// Look for the module state. If we don't have one, create it.
|
|
|
|
|
mod := state.ModuleByPath(ctx.Path())
|
|
|
|
|
if mod == nil {
|
|
|
|
|
mod = state.AddModule(ctx.Path())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Look for the resource state.
|
|
|
|
|
rs := mod.Resources[n.Name]
|
|
|
|
|
if rs == nil {
|
|
|
|
|
rs = &ResourceState{}
|
|
|
|
|
rs.init()
|
|
|
|
|
mod.Resources[n.Name] = rs
|
|
|
|
|
}
|
|
|
|
|
rs.Type = n.ResourceType
|
|
|
|
|
rs.Dependencies = n.Dependencies
|
|
|
|
|
|
|
|
|
|
rs.Deposed = *n.State
|
|
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// EvalClearPrimaryState is an EvalNode implementation that clears the primary
|
|
|
|
|
// instance from a resource state.
|
|
|
|
|
type EvalClearPrimaryState struct {
|
|
|
|
|
Name string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (n *EvalClearPrimaryState) Eval(ctx EvalContext) (interface{}, error) {
|
|
|
|
|
state, lock := ctx.State()
|
|
|
|
|
|
|
|
|
|
// Get a read lock so we can access this instance
|
|
|
|
|
lock.RLock()
|
|
|
|
|
defer lock.RUnlock()
|
|
|
|
|
|
|
|
|
|
// Look for the module state. If we don't have one, then it doesn't matter.
|
|
|
|
|
mod := state.ModuleByPath(ctx.Path())
|
|
|
|
|
if mod == nil {
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Look for the resource state. If we don't have one, then it is okay.
|
|
|
|
|
rs := mod.Resources[n.Name]
|
|
|
|
|
if rs == nil {
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Clear primary from the resource state
|
|
|
|
|
rs.Primary = nil
|
|
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|