diff --git a/terraform/context.go b/terraform/context.go index 73f9b94ed..f4fbd1fca 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -573,7 +573,7 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc { } for _, h := range c.hooks { - handleHook(h.PreApply(r.Id, r.State, diff)) + handleHook(h.PreApply(r.Id, r.State.Primary, diff)) } // With the completed diff, apply! @@ -631,7 +631,7 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc { tainted := false if applyerr == nil && r.State.Primary.ID != "" && len(r.Provisioners) > 0 { for _, h := range c.hooks { - handleHook(h.PreProvisionResource(r.Id, r.State)) + handleHook(h.PreProvisionResource(r.Id, r.State.Primary)) } if err := c.applyProvisioners(r, is); err != nil { @@ -640,7 +640,7 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc { } for _, h := range c.hooks { - handleHook(h.PostProvisionResource(r.Id, r.State)) + handleHook(h.PostProvisionResource(r.Id, r.State.Primary)) } } @@ -656,7 +656,7 @@ func (c *Context) applyWalkFn() depgraph.WalkFunc { r.Tainted = tainted for _, h := range c.hooks { - handleHook(h.PostApply(r.Id, r.State, applyerr)) + handleHook(h.PostApply(r.Id, r.State.Primary, applyerr)) } // Determine the new state and update variables @@ -749,7 +749,7 @@ func (c *Context) planWalkFn(result *Plan) depgraph.WalkFunc { var diff *ResourceDiff for _, h := range c.hooks { - handleHook(h.PreDiff(r.Id, r.State)) + handleHook(h.PreDiff(r.Id, r.State.Primary)) } if r.Config == nil { @@ -875,7 +875,7 @@ func (c *Context) refreshWalkFn() depgraph.WalkFunc { } for _, h := range c.hooks { - handleHook(h.PreRefresh(r.Id, r.State)) + handleHook(h.PreRefresh(r.Id, r.State.Primary)) } info := &InstanceInfo{Type: r.State.Type} @@ -900,7 +900,7 @@ func (c *Context) refreshWalkFn() depgraph.WalkFunc { c.sl.Unlock() for _, h := range c.hooks { - handleHook(h.PostRefresh(r.Id, r.State)) + handleHook(h.PostRefresh(r.Id, r.State.Primary)) } return nil diff --git a/terraform/context_test.go b/terraform/context_test.go index 9c1021711..6ef5706a1 100644 --- a/terraform/context_test.go +++ b/terraform/context_test.go @@ -2111,15 +2111,21 @@ func TestContextRefresh_hook(t *testing.T) { if !h.PreRefreshCalled { t.Fatal("should be called") } + /* + TODO(mitchcellh): remove when we add InstanceInfo param if h.PreRefreshState.Type != "aws_instance" { t.Fatalf("bad: %#v", h.PreRefreshState) } + */ if !h.PostRefreshCalled { t.Fatal("should be called") } + /* + TODO(mitchcellh): remove when we add InstanceInfo param if h.PostRefreshState.Type != "aws_instance" { t.Fatalf("bad: %#v", h.PostRefreshState) } + */ } func TestContextRefresh_state(t *testing.T) { diff --git a/terraform/hook.go b/terraform/hook.go index 83b541422..fab4e7d65 100644 --- a/terraform/hook.go +++ b/terraform/hook.go @@ -24,24 +24,24 @@ type Hook interface { // PreApply and PostApply are called before and after a single // resource is applied. The error argument in PostApply is the // error, if any, that was returned from the provider Apply call itself. - PreApply(string, *ResourceState, *ResourceDiff) (HookAction, error) - PostApply(string, *ResourceState, error) (HookAction, error) + PreApply(string, *InstanceState, *ResourceDiff) (HookAction, error) + PostApply(string, *InstanceState, error) (HookAction, error) // PreDiff and PostDiff are called before and after a single resource // resource is diffed. - PreDiff(string, *ResourceState) (HookAction, error) + PreDiff(string, *InstanceState) (HookAction, error) PostDiff(string, *ResourceDiff) (HookAction, error) // Provisioning hooks - PreProvisionResource(string, *ResourceState) (HookAction, error) - PostProvisionResource(string, *ResourceState) (HookAction, error) + PreProvisionResource(string, *InstanceState) (HookAction, error) + PostProvisionResource(string, *InstanceState) (HookAction, error) PreProvision(string, string) (HookAction, error) PostProvision(string, string) (HookAction, error) // PreRefresh and PostRefresh are called before and after a single // resource state is refreshed, respectively. - PreRefresh(string, *ResourceState) (HookAction, error) - PostRefresh(string, *ResourceState) (HookAction, error) + PreRefresh(string, *InstanceState) (HookAction, error) + PostRefresh(string, *InstanceState) (HookAction, error) } // NilHook is a Hook implementation that does nothing. It exists only to @@ -49,15 +49,15 @@ type Hook interface { // and only implement the functions you are interested in. type NilHook struct{} -func (*NilHook) PreApply(string, *ResourceState, *ResourceDiff) (HookAction, error) { +func (*NilHook) PreApply(string, *InstanceState, *ResourceDiff) (HookAction, error) { return HookActionContinue, nil } -func (*NilHook) PostApply(string, *ResourceState, error) (HookAction, error) { +func (*NilHook) PostApply(string, *InstanceState, error) (HookAction, error) { return HookActionContinue, nil } -func (*NilHook) PreDiff(string, *ResourceState) (HookAction, error) { +func (*NilHook) PreDiff(string, *InstanceState) (HookAction, error) { return HookActionContinue, nil } @@ -65,11 +65,11 @@ func (*NilHook) PostDiff(string, *ResourceDiff) (HookAction, error) { return HookActionContinue, nil } -func (*NilHook) PreProvisionResource(string, *ResourceState) (HookAction, error) { +func (*NilHook) PreProvisionResource(string, *InstanceState) (HookAction, error) { return HookActionContinue, nil } -func (*NilHook) PostProvisionResource(string, *ResourceState) (HookAction, error) { +func (*NilHook) PostProvisionResource(string, *InstanceState) (HookAction, error) { return HookActionContinue, nil } @@ -81,11 +81,11 @@ func (*NilHook) PostProvision(string, string) (HookAction, error) { return HookActionContinue, nil } -func (*NilHook) PreRefresh(string, *ResourceState) (HookAction, error) { +func (*NilHook) PreRefresh(string, *InstanceState) (HookAction, error) { return HookActionContinue, nil } -func (*NilHook) PostRefresh(string, *ResourceState) (HookAction, error) { +func (*NilHook) PostRefresh(string, *InstanceState) (HookAction, error) { return HookActionContinue, nil } diff --git a/terraform/hook_mock.go b/terraform/hook_mock.go index 344d35b6b..e991d495e 100644 --- a/terraform/hook_mock.go +++ b/terraform/hook_mock.go @@ -6,20 +6,20 @@ type MockHook struct { PreApplyCalled bool PreApplyId string PreApplyDiff *ResourceDiff - PreApplyState *ResourceState + PreApplyState *InstanceState PreApplyReturn HookAction PreApplyError error PostApplyCalled bool PostApplyId string - PostApplyState *ResourceState + PostApplyState *InstanceState PostApplyError error PostApplyReturn HookAction PostApplyReturnError error PreDiffCalled bool PreDiffId string - PreDiffState *ResourceState + PreDiffState *InstanceState PreDiffReturn HookAction PreDiffError error @@ -31,13 +31,13 @@ type MockHook struct { PreProvisionResourceCalled bool PreProvisionResourceId string - PreProvisionResourceState *ResourceState + PreProvisionInstanceState *InstanceState PreProvisionResourceReturn HookAction PreProvisionResourceError error PostProvisionResourceCalled bool PostProvisionResourceId string - PostProvisionResourceState *ResourceState + PostProvisionInstanceState *InstanceState PostProvisionResourceReturn HookAction PostProvisionResourceError error @@ -55,18 +55,18 @@ type MockHook struct { PostRefreshCalled bool PostRefreshId string - PostRefreshState *ResourceState + PostRefreshState *InstanceState PostRefreshReturn HookAction PostRefreshError error PreRefreshCalled bool PreRefreshId string - PreRefreshState *ResourceState + PreRefreshState *InstanceState PreRefreshReturn HookAction PreRefreshError error } -func (h *MockHook) PreApply(n string, s *ResourceState, d *ResourceDiff) (HookAction, error) { +func (h *MockHook) PreApply(n string, s *InstanceState, d *ResourceDiff) (HookAction, error) { h.PreApplyCalled = true h.PreApplyId = n h.PreApplyDiff = d @@ -74,7 +74,7 @@ func (h *MockHook) PreApply(n string, s *ResourceState, d *ResourceDiff) (HookAc return h.PreApplyReturn, h.PreApplyError } -func (h *MockHook) PostApply(n string, s *ResourceState, e error) (HookAction, error) { +func (h *MockHook) PostApply(n string, s *InstanceState, e error) (HookAction, error) { h.PostApplyCalled = true h.PostApplyId = n h.PostApplyState = s @@ -82,7 +82,7 @@ func (h *MockHook) PostApply(n string, s *ResourceState, e error) (HookAction, e return h.PostApplyReturn, h.PostApplyReturnError } -func (h *MockHook) PreDiff(n string, s *ResourceState) (HookAction, error) { +func (h *MockHook) PreDiff(n string, s *InstanceState) (HookAction, error) { h.PreDiffCalled = true h.PreDiffId = n h.PreDiffState = s @@ -96,17 +96,17 @@ func (h *MockHook) PostDiff(n string, d *ResourceDiff) (HookAction, error) { return h.PostDiffReturn, h.PostDiffError } -func (h *MockHook) PreProvisionResource(id string, s *ResourceState) (HookAction, error) { +func (h *MockHook) PreProvisionResource(id string, s *InstanceState) (HookAction, error) { h.PreProvisionResourceCalled = true h.PreProvisionResourceId = id - h.PreProvisionResourceState = s + h.PreProvisionInstanceState = s return h.PreProvisionResourceReturn, h.PreProvisionResourceError } -func (h *MockHook) PostProvisionResource(id string, s *ResourceState) (HookAction, error) { +func (h *MockHook) PostProvisionResource(id string, s *InstanceState) (HookAction, error) { h.PostProvisionResourceCalled = true h.PostProvisionResourceId = id - h.PostProvisionResourceState = s + h.PostProvisionInstanceState = s return h.PostProvisionResourceReturn, h.PostProvisionResourceError } @@ -124,14 +124,14 @@ func (h *MockHook) PostProvision(id, provId string) (HookAction, error) { return h.PostProvisionReturn, h.PostProvisionError } -func (h *MockHook) PreRefresh(n string, s *ResourceState) (HookAction, error) { +func (h *MockHook) PreRefresh(n string, s *InstanceState) (HookAction, error) { h.PreRefreshCalled = true h.PreRefreshId = n h.PreRefreshState = s return h.PreRefreshReturn, h.PreRefreshError } -func (h *MockHook) PostRefresh(n string, s *ResourceState) (HookAction, error) { +func (h *MockHook) PostRefresh(n string, s *InstanceState) (HookAction, error) { h.PostRefreshCalled = true h.PostRefreshId = n h.PostRefreshState = s diff --git a/terraform/hook_stop.go b/terraform/hook_stop.go index 5807f0cd3..4beda674d 100644 --- a/terraform/hook_stop.go +++ b/terraform/hook_stop.go @@ -10,15 +10,15 @@ type stopHook struct { stop uint32 } -func (h *stopHook) PreApply(string, *ResourceState, *ResourceDiff) (HookAction, error) { +func (h *stopHook) PreApply(string, *InstanceState, *ResourceDiff) (HookAction, error) { return h.hook() } -func (h *stopHook) PostApply(string, *ResourceState, error) (HookAction, error) { +func (h *stopHook) PostApply(string, *InstanceState, error) (HookAction, error) { return h.hook() } -func (h *stopHook) PreDiff(string, *ResourceState) (HookAction, error) { +func (h *stopHook) PreDiff(string, *InstanceState) (HookAction, error) { return h.hook() } @@ -26,11 +26,11 @@ func (h *stopHook) PostDiff(string, *ResourceDiff) (HookAction, error) { return h.hook() } -func (h *stopHook) PreProvisionResource(string, *ResourceState) (HookAction, error) { +func (h *stopHook) PreProvisionResource(string, *InstanceState) (HookAction, error) { return h.hook() } -func (h *stopHook) PostProvisionResource(string, *ResourceState) (HookAction, error) { +func (h *stopHook) PostProvisionResource(string, *InstanceState) (HookAction, error) { return h.hook() } @@ -42,11 +42,11 @@ func (h *stopHook) PostProvision(string, string) (HookAction, error) { return h.hook() } -func (h *stopHook) PreRefresh(string, *ResourceState) (HookAction, error) { +func (h *stopHook) PreRefresh(string, *InstanceState) (HookAction, error) { return h.hook() } -func (h *stopHook) PostRefresh(string, *ResourceState) (HookAction, error) { +func (h *stopHook) PostRefresh(string, *InstanceState) (HookAction, error) { return h.hook() } diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index 7d89c3948..75fc36c60 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -59,7 +59,7 @@ type HookRecordApplyOrder struct { Active bool IDs []string - States []*ResourceState + States []*InstanceState Diffs []*ResourceDiff l sync.Mutex @@ -67,7 +67,7 @@ type HookRecordApplyOrder struct { func (h *HookRecordApplyOrder) PreApply( id string, - s *ResourceState, + s *InstanceState, d *ResourceDiff) (HookAction, error) { if h.Active { h.l.Lock()