terrform: Thread provisioner factory through Context
This commit is contained in:
parent
ee475e8178
commit
87c3423fd4
|
@ -22,12 +22,13 @@ type genericWalkFunc func(*Resource) error
|
||||||
//
|
//
|
||||||
// Additionally, a context can be created from a Plan using Plan.Context.
|
// Additionally, a context can be created from a Plan using Plan.Context.
|
||||||
type Context struct {
|
type Context struct {
|
||||||
config *config.Config
|
config *config.Config
|
||||||
diff *Diff
|
diff *Diff
|
||||||
hooks []Hook
|
hooks []Hook
|
||||||
state *State
|
state *State
|
||||||
providers map[string]ResourceProviderFactory
|
providers map[string]ResourceProviderFactory
|
||||||
variables map[string]string
|
provisioners map[string]ResourceProvisionerFactory
|
||||||
|
variables map[string]string
|
||||||
|
|
||||||
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
|
||||||
|
@ -39,13 +40,14 @@ type Context struct {
|
||||||
// ContextOpts are the user-creatable configuration structure to create
|
// ContextOpts are the user-creatable configuration structure to create
|
||||||
// a context with NewContext.
|
// a context with NewContext.
|
||||||
type ContextOpts struct {
|
type ContextOpts struct {
|
||||||
Config *config.Config
|
Config *config.Config
|
||||||
Diff *Diff
|
Diff *Diff
|
||||||
Hooks []Hook
|
Hooks []Hook
|
||||||
Parallelism int
|
Parallelism int
|
||||||
State *State
|
State *State
|
||||||
Providers map[string]ResourceProviderFactory
|
Providers map[string]ResourceProviderFactory
|
||||||
Variables map[string]string
|
Provisioners map[string]ResourceProvisionerFactory
|
||||||
|
Variables map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewContext creates a new context.
|
// NewContext creates a new context.
|
||||||
|
@ -70,12 +72,13 @@ func NewContext(opts *ContextOpts) *Context {
|
||||||
parCh := make(chan struct{}, par)
|
parCh := make(chan struct{}, par)
|
||||||
|
|
||||||
return &Context{
|
return &Context{
|
||||||
config: opts.Config,
|
config: opts.Config,
|
||||||
diff: opts.Diff,
|
diff: opts.Diff,
|
||||||
hooks: hooks,
|
hooks: hooks,
|
||||||
state: opts.State,
|
state: opts.State,
|
||||||
providers: opts.Providers,
|
providers: opts.Providers,
|
||||||
variables: opts.Variables,
|
provisioners: opts.Provisioners,
|
||||||
|
variables: opts.Variables,
|
||||||
|
|
||||||
parCh: parCh,
|
parCh: parCh,
|
||||||
sh: sh,
|
sh: sh,
|
||||||
|
@ -92,10 +95,11 @@ func (c *Context) Apply() (*State, error) {
|
||||||
defer c.releaseRun(v)
|
defer c.releaseRun(v)
|
||||||
|
|
||||||
g, err := Graph(&GraphOpts{
|
g, err := Graph(&GraphOpts{
|
||||||
Config: c.config,
|
Config: c.config,
|
||||||
Diff: c.diff,
|
Diff: c.diff,
|
||||||
Providers: c.providers,
|
Providers: c.providers,
|
||||||
State: c.state,
|
Provisioners: c.provisioners,
|
||||||
|
State: c.state,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -135,9 +139,10 @@ func (c *Context) Plan(opts *PlanOpts) (*Plan, error) {
|
||||||
defer c.releaseRun(v)
|
defer c.releaseRun(v)
|
||||||
|
|
||||||
g, err := Graph(&GraphOpts{
|
g, err := Graph(&GraphOpts{
|
||||||
Config: c.config,
|
Config: c.config,
|
||||||
Providers: c.providers,
|
Providers: c.providers,
|
||||||
State: c.state,
|
Provisioners: c.provisioners,
|
||||||
|
State: c.state,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -188,9 +193,10 @@ func (c *Context) Refresh() (*State, error) {
|
||||||
defer c.releaseRun(v)
|
defer c.releaseRun(v)
|
||||||
|
|
||||||
g, err := Graph(&GraphOpts{
|
g, err := Graph(&GraphOpts{
|
||||||
Config: c.config,
|
Config: c.config,
|
||||||
Providers: c.providers,
|
Providers: c.providers,
|
||||||
State: c.state,
|
Provisioners: c.provisioners,
|
||||||
|
State: c.state,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.state, err
|
return c.state, err
|
||||||
|
@ -384,10 +390,11 @@ func (c *Context) computeResourceMultiVariable(
|
||||||
|
|
||||||
func (c *Context) graph() (*depgraph.Graph, error) {
|
func (c *Context) graph() (*depgraph.Graph, error) {
|
||||||
return Graph(&GraphOpts{
|
return Graph(&GraphOpts{
|
||||||
Config: c.config,
|
Config: c.config,
|
||||||
Diff: c.diff,
|
Diff: c.diff,
|
||||||
Providers: c.providers,
|
Providers: c.providers,
|
||||||
State: c.state,
|
Provisioners: c.provisioners,
|
||||||
|
State: c.state,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue