terraform: change provisioners to take UIOutput

This commit is contained in:
Mitchell Hashimoto 2014-10-04 09:20:05 -07:00
parent 509f293bea
commit 8b129babe5
3 changed files with 13 additions and 4 deletions

View File

@ -34,6 +34,7 @@ type Context struct {
provisioners map[string]ResourceProvisionerFactory
variables map[string]string
uiInput UIInput
uiOutput UIOutput
l sync.Mutex // Lock acquired during any task
parCh chan struct{} // Semaphore used to limit parallelism
@ -55,6 +56,7 @@ type ContextOpts struct {
Variables map[string]string
UIInput UIInput
UIOutput UIOutput
}
// NewContext creates a new context.
@ -88,6 +90,7 @@ func NewContext(opts *ContextOpts) *Context {
provisioners: opts.Provisioners,
variables: opts.Variables,
uiInput: opts.UIInput,
uiOutput: opts.UIOutput,
parCh: parCh,
sh: sh,
@ -1310,7 +1313,8 @@ func (c *walkContext) applyProvisioners(r *Resource, is *InstanceState) error {
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
}

View File

@ -20,7 +20,7 @@ type ResourceProvisioner interface {
// resource state along with an error. Instead of a diff, the ResourceConfig
// is provided since provisioners only run after a resource has been
// newly created.
Apply(*InstanceState, *ResourceConfig) error
Apply(UIOutput, *InstanceState, *ResourceConfig) error
}
// ResourceProvisionerFactory is a function type that creates a new instance

View File

@ -7,6 +7,7 @@ type MockResourceProvisioner struct {
Meta interface{}
ApplyCalled bool
ApplyOutput UIOutput
ApplyState *InstanceState
ApplyConfig *ResourceConfig
ApplyFn func(*InstanceState, *ResourceConfig) error
@ -28,8 +29,12 @@ func (p *MockResourceProvisioner) Validate(c *ResourceConfig) ([]string, []error
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.ApplyOutput = output
p.ApplyState = state
p.ApplyConfig = c
if p.ApplyFn != nil {