diff --git a/terraform/hook.go b/terraform/hook.go index 79e69c635..3dcc97331 100644 --- a/terraform/hook.go +++ b/terraform/hook.go @@ -52,6 +52,11 @@ type Hook interface { // PostStateUpdate is called after the state is updated. PostStateUpdate(*State) (HookAction, error) + + // PreImportState and PostImportState are called before and after + // a single resource's state is being improted. + PreImportState(*InstanceInfo) (HookAction, error) + PostImportState(*InstanceInfo, []*InstanceState) (HookAction, error) } // NilHook is a Hook implementation that does nothing. It exists only to @@ -103,6 +108,14 @@ func (*NilHook) PostRefresh(*InstanceInfo, *InstanceState) (HookAction, error) { return HookActionContinue, nil } +func (*NilHook) PreImportState(*InstanceInfo) (HookAction, error) { + return HookActionContinue, nil +} + +func (*NilHook) PostImportState(*InstanceInfo, []*InstanceState) (HookAction, error) { + return HookActionContinue, nil +} + func (*NilHook) PostStateUpdate(*State) (HookAction, error) { return HookActionContinue, nil } diff --git a/terraform/hook_mock.go b/terraform/hook_mock.go index d30ab8f06..0adb1985e 100644 --- a/terraform/hook_mock.go +++ b/terraform/hook_mock.go @@ -70,6 +70,17 @@ type MockHook struct { PreRefreshReturn HookAction PreRefreshError error + PreImportStateCalled bool + PreImportStateInfo *InstanceInfo + PreImportStateReturn HookAction + PreImportStateError error + + PostImportStateCalled bool + PostImportStateInfo *InstanceInfo + PostImportStateState []*InstanceState + PostImportStateReturn HookAction + PostImportStateError error + PostStateUpdateCalled bool PostStateUpdateState *State PostStateUpdateReturn HookAction @@ -158,6 +169,19 @@ func (h *MockHook) PostRefresh(n *InstanceInfo, s *InstanceState) (HookAction, e return h.PostRefreshReturn, h.PostRefreshError } +func (h *MockHook) PreImportState(info *InstanceInfo) (HookAction, error) { + h.PreImportStateCalled = true + h.PreImportStateInfo = info + return h.PreImportStateReturn, h.PreImportStateError +} + +func (h *MockHook) PostImportState(info *InstanceInfo, s []*InstanceState) (HookAction, error) { + h.PostImportStateCalled = true + h.PostImportStateInfo = info + h.PostImportStateState = s + return h.PostImportStateReturn, h.PostImportStateError +} + func (h *MockHook) PostStateUpdate(s *State) (HookAction, error) { h.PostStateUpdateCalled = true h.PostStateUpdateState = s diff --git a/terraform/hook_stop.go b/terraform/hook_stop.go index 34713221e..f93778b89 100644 --- a/terraform/hook_stop.go +++ b/terraform/hook_stop.go @@ -53,6 +53,14 @@ func (h *stopHook) PostRefresh(*InstanceInfo, *InstanceState) (HookAction, error return h.hook() } +func (h *stopHook) PreImportState(*InstanceInfo) (HookAction, error) { + return h.hook() +} + +func (h *stopHook) PostImportState(*InstanceInfo, []*InstanceState) (HookAction, error) { + return h.hook() +} + func (h *stopHook) PostStateUpdate(*State) (HookAction, error) { return h.hook() }