terraform: change provisioners to take UIOutput
This commit is contained in:
parent
509f293bea
commit
8b129babe5
|
@ -34,6 +34,7 @@ type Context struct {
|
||||||
provisioners map[string]ResourceProvisionerFactory
|
provisioners map[string]ResourceProvisionerFactory
|
||||||
variables map[string]string
|
variables map[string]string
|
||||||
uiInput UIInput
|
uiInput UIInput
|
||||||
|
uiOutput UIOutput
|
||||||
|
|
||||||
l sync.Mutex // Lock acquired during any task
|
l sync.Mutex // Lock acquired during any task
|
||||||
parCh chan struct{} // Semaphore used to limit parallelism
|
parCh chan struct{} // Semaphore used to limit parallelism
|
||||||
|
@ -54,7 +55,8 @@ type ContextOpts struct {
|
||||||
Provisioners map[string]ResourceProvisionerFactory
|
Provisioners map[string]ResourceProvisionerFactory
|
||||||
Variables map[string]string
|
Variables map[string]string
|
||||||
|
|
||||||
UIInput UIInput
|
UIInput UIInput
|
||||||
|
UIOutput UIOutput
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContext creates a new context.
|
// NewContext creates a new context.
|
||||||
|
@ -88,6 +90,7 @@ func NewContext(opts *ContextOpts) *Context {
|
||||||
provisioners: opts.Provisioners,
|
provisioners: opts.Provisioners,
|
||||||
variables: opts.Variables,
|
variables: opts.Variables,
|
||||||
uiInput: opts.UIInput,
|
uiInput: opts.UIInput,
|
||||||
|
uiOutput: opts.UIOutput,
|
||||||
|
|
||||||
parCh: parCh,
|
parCh: parCh,
|
||||||
sh: sh,
|
sh: sh,
|
||||||
|
@ -1310,7 +1313,8 @@ func (c *walkContext) applyProvisioners(r *Resource, is *InstanceState) error {
|
||||||
handleHook(h.PreProvision(r.Info, prov.Type))
|
handleHook(h.PreProvision(r.Info, prov.Type))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := prov.Provisioner.Apply(is, prov.Config); err != nil {
|
err := prov.Provisioner.Apply(c.Context.uiOutput, is, prov.Config)
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ type ResourceProvisioner interface {
|
||||||
// resource state along with an error. Instead of a diff, the ResourceConfig
|
// resource state along with an error. Instead of a diff, the ResourceConfig
|
||||||
// is provided since provisioners only run after a resource has been
|
// is provided since provisioners only run after a resource has been
|
||||||
// newly created.
|
// newly created.
|
||||||
Apply(*InstanceState, *ResourceConfig) error
|
Apply(UIOutput, *InstanceState, *ResourceConfig) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResourceProvisionerFactory is a function type that creates a new instance
|
// ResourceProvisionerFactory is a function type that creates a new instance
|
||||||
|
|
|
@ -7,6 +7,7 @@ type MockResourceProvisioner struct {
|
||||||
Meta interface{}
|
Meta interface{}
|
||||||
|
|
||||||
ApplyCalled bool
|
ApplyCalled bool
|
||||||
|
ApplyOutput UIOutput
|
||||||
ApplyState *InstanceState
|
ApplyState *InstanceState
|
||||||
ApplyConfig *ResourceConfig
|
ApplyConfig *ResourceConfig
|
||||||
ApplyFn func(*InstanceState, *ResourceConfig) error
|
ApplyFn func(*InstanceState, *ResourceConfig) error
|
||||||
|
@ -28,8 +29,12 @@ func (p *MockResourceProvisioner) Validate(c *ResourceConfig) ([]string, []error
|
||||||
return p.ValidateReturnWarns, p.ValidateReturnErrors
|
return p.ValidateReturnWarns, p.ValidateReturnErrors
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MockResourceProvisioner) Apply(state *InstanceState, c *ResourceConfig) error {
|
func (p *MockResourceProvisioner) Apply(
|
||||||
|
output UIOutput,
|
||||||
|
state *InstanceState,
|
||||||
|
c *ResourceConfig) error {
|
||||||
p.ApplyCalled = true
|
p.ApplyCalled = true
|
||||||
|
p.ApplyOutput = output
|
||||||
p.ApplyState = state
|
p.ApplyState = state
|
||||||
p.ApplyConfig = c
|
p.ApplyConfig = c
|
||||||
if p.ApplyFn != nil {
|
if p.ApplyFn != nil {
|
||||||
|
|
Loading…
Reference in New Issue