From b8e569056589b25e7355c0926bb222d7e67f96e8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 13 Feb 2015 09:52:11 -0800 Subject: [PATCH] terraform: eval post hook, eerrors --- terraform/eval_apply.go | 33 +++++++++++++++++++++++++++++++++ terraform/transform_resource.go | 5 +++++ 2 files changed, 38 insertions(+) diff --git a/terraform/eval_apply.go b/terraform/eval_apply.go index 70b12f388..dd77b8145 100644 --- a/terraform/eval_apply.go +++ b/terraform/eval_apply.go @@ -106,6 +106,39 @@ func (n *EvalApply) Type() EvalType { return EvalTypeNull } +// EvalApplyPost is an EvalNode implementation that does the post-Apply work +type EvalApplyPost struct { + Info *InstanceInfo + State **InstanceState + Error *error +} + +func (n *EvalApplyPost) Args() ([]EvalNode, []EvalType) { + return nil, nil +} + +// TODO: test +func (n *EvalApplyPost) Eval( + ctx EvalContext, args []interface{}) (interface{}, error) { + state := *n.State + + { + // Call post-apply hook + err := ctx.Hook(func(h Hook) (HookAction, error) { + return h.PostApply(n.Info, state, *n.Error) + }) + if err != nil { + return nil, err + } + } + + return nil, *n.Error +} + +func (n *EvalApplyPost) Type() EvalType { + return EvalTypeNull +} + // EvalApplyProvisioners is an EvalNode implementation that executes // the provisioners for a resource. // diff --git a/terraform/transform_resource.go b/terraform/transform_resource.go index 497f2faa3..ffa5e9875 100644 --- a/terraform/transform_resource.go +++ b/terraform/transform_resource.go @@ -290,6 +290,11 @@ func (n *graphNodeExpandedResource) EvalTree() EvalNode { TaintedIndex: -1, TaintedClearPrimary: true, }, + &EvalApplyPost{ + Info: info, + State: &state, + Error: &err, + }, }, }, })