2014-06-26 18:52:15 -05:00
|
|
|
package terraform
|
|
|
|
|
|
|
|
// HookAction is an enum of actions that can be taken as a result of a hook
|
|
|
|
// callback. This allows you to modify the behavior of Terraform at runtime.
|
|
|
|
type HookAction byte
|
|
|
|
|
|
|
|
const (
|
|
|
|
// HookActionContinue continues with processing as usual.
|
|
|
|
HookActionContinue HookAction = iota
|
|
|
|
|
|
|
|
// HookActionHalt halts immediately: no more hooks are processed
|
|
|
|
// and the action that Terraform was about to take is cancelled.
|
|
|
|
HookActionHalt
|
|
|
|
)
|
|
|
|
|
|
|
|
// Hook is the interface that must be implemented to hook into various
|
|
|
|
// parts of Terraform, allowing you to inspect or change behavior at runtime.
|
|
|
|
//
|
|
|
|
// There are MANY hook points into Terraform. If you only want to implement
|
|
|
|
// some hook points, but not all (which is the likely case), then embed the
|
|
|
|
// NilHook into your struct, which implements all of the interface but does
|
|
|
|
// nothing. Then, override only the functions you want to implement.
|
|
|
|
type Hook interface {
|
2014-06-26 19:17:10 -05:00
|
|
|
// PreDiff and PostDiff are called before and after a single resource
|
|
|
|
// resource is diffed.
|
|
|
|
PreDiff(string, *ResourceState) (HookAction, error)
|
|
|
|
PostDiff(string, *ResourceDiff) (HookAction, error)
|
2014-06-26 18:52:15 -05:00
|
|
|
|
2014-06-26 19:17:10 -05:00
|
|
|
// PreRefresh and PostRefresh are called before and after a single
|
|
|
|
// resource state is refreshed, respectively.
|
|
|
|
PreRefresh(string, *ResourceState) (HookAction, error)
|
2014-06-26 19:05:21 -05:00
|
|
|
PostRefresh(string, *ResourceState) (HookAction, error)
|
2014-06-26 18:52:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// NilHook is a Hook implementation that does nothing. It exists only to
|
|
|
|
// simplify implementing hooks. You can embed this into your Hook implementation
|
|
|
|
// and only implement the functions you are interested in.
|
|
|
|
type NilHook struct{}
|
|
|
|
|
2014-06-26 19:17:10 -05:00
|
|
|
func (*NilHook) PreDiff(string, *ResourceState) (HookAction, error) {
|
|
|
|
return HookActionContinue, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (*NilHook) PostDiff(string, *ResourceDiff) (HookAction, error) {
|
|
|
|
return HookActionContinue, nil
|
|
|
|
}
|
|
|
|
|
2014-06-26 19:05:21 -05:00
|
|
|
func (*NilHook) PreRefresh(string, *ResourceState) (HookAction, error) {
|
2014-06-26 18:52:15 -05:00
|
|
|
return HookActionContinue, nil
|
|
|
|
}
|
|
|
|
|
2014-06-26 19:05:21 -05:00
|
|
|
func (*NilHook) PostRefresh(string, *ResourceState) (HookAction, error) {
|
2014-06-26 18:52:15 -05:00
|
|
|
return HookActionContinue, nil
|
|
|
|
}
|