terraform: import state ID should be sent to hook

This commit is contained in:
Mitchell Hashimoto 2016-05-04 13:02:51 -07:00
parent c02c6c3f9c
commit b728f8c018
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
5 changed files with 10 additions and 8 deletions

View File

@ -252,13 +252,13 @@ func (h *UiHook) PreRefresh(
}
func (h *UiHook) PreImportState(
n *terraform.InstanceInfo) (terraform.HookAction, error) {
n *terraform.InstanceInfo,
id string) (terraform.HookAction, error) {
h.once.Do(h.init)
id := n.HumanId()
h.ui.Output(h.Colorize.Color(fmt.Sprintf(
"[reset][bold]%s: Importing from ID %q...",
id, n.Id)))
n.HumanId(), id)))
return terraform.HookActionContinue, nil
}

View File

@ -21,7 +21,7 @@ func (n *EvalImportState) Eval(ctx EvalContext) (interface{}, error) {
{
// Call pre-import hook
err := ctx.Hook(func(h Hook) (HookAction, error) {
return h.PreImportState(n.Info)
return h.PreImportState(n.Info, n.Id)
})
if err != nil {
return nil, err

View File

@ -55,7 +55,7 @@ type Hook interface {
// PreImportState and PostImportState are called before and after
// a single resource's state is being improted.
PreImportState(*InstanceInfo) (HookAction, error)
PreImportState(*InstanceInfo, string) (HookAction, error)
PostImportState(*InstanceInfo, []*InstanceState) (HookAction, error)
}
@ -108,7 +108,7 @@ func (*NilHook) PostRefresh(*InstanceInfo, *InstanceState) (HookAction, error) {
return HookActionContinue, nil
}
func (*NilHook) PreImportState(*InstanceInfo) (HookAction, error) {
func (*NilHook) PreImportState(*InstanceInfo, string) (HookAction, error) {
return HookActionContinue, nil
}

View File

@ -72,6 +72,7 @@ type MockHook struct {
PreImportStateCalled bool
PreImportStateInfo *InstanceInfo
PreImportStateId string
PreImportStateReturn HookAction
PreImportStateError error
@ -169,9 +170,10 @@ func (h *MockHook) PostRefresh(n *InstanceInfo, s *InstanceState) (HookAction, e
return h.PostRefreshReturn, h.PostRefreshError
}
func (h *MockHook) PreImportState(info *InstanceInfo) (HookAction, error) {
func (h *MockHook) PreImportState(info *InstanceInfo, id string) (HookAction, error) {
h.PreImportStateCalled = true
h.PreImportStateInfo = info
h.PreImportStateId = id
return h.PreImportStateReturn, h.PreImportStateError
}

View File

@ -53,7 +53,7 @@ func (h *stopHook) PostRefresh(*InstanceInfo, *InstanceState) (HookAction, error
return h.hook()
}
func (h *stopHook) PreImportState(*InstanceInfo) (HookAction, error) {
func (h *stopHook) PreImportState(*InstanceInfo, string) (HookAction, error) {
return h.hook()
}