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