terraform: check for errors initializing a provider
This commit is contained in:
parent
ce0867fa09
commit
0561edc2fd
|
@ -12,8 +12,8 @@ type ResourceProvider interface {
|
||||||
// Configure configures the provider itself with the configuration
|
// Configure configures the provider itself with the configuration
|
||||||
// given. This is useful for setting things like access keys.
|
// given. This is useful for setting things like access keys.
|
||||||
//
|
//
|
||||||
// Configure returns a list of warnings and a potential error.
|
// Configure returns an error if it occurred.
|
||||||
Configure(config map[string]interface{}) ([]string, error)
|
Configure(config map[string]interface{}) error
|
||||||
|
|
||||||
// Resources returns all the available resource types that this provider
|
// Resources returns all the available resource types that this provider
|
||||||
// knows how to manage.
|
// knows how to manage.
|
||||||
|
|
|
@ -6,24 +6,23 @@ type MockResourceProvider struct {
|
||||||
// Anything you want, in case you need to store extra data with the mock.
|
// Anything you want, in case you need to store extra data with the mock.
|
||||||
Meta interface{}
|
Meta interface{}
|
||||||
|
|
||||||
ConfigureCalled bool
|
ConfigureCalled bool
|
||||||
ConfigureConfig map[string]interface{}
|
ConfigureConfig map[string]interface{}
|
||||||
ConfigureReturnWarnings []string
|
ConfigureReturnError error
|
||||||
ConfigureReturnError error
|
DiffCalled bool
|
||||||
DiffCalled bool
|
DiffState *ResourceState
|
||||||
DiffState *ResourceState
|
DiffDesired map[string]interface{}
|
||||||
DiffDesired map[string]interface{}
|
DiffFn func(*ResourceState, map[string]interface{}) (ResourceDiff, error)
|
||||||
DiffFn func(*ResourceState, map[string]interface{}) (ResourceDiff, error)
|
DiffReturn ResourceDiff
|
||||||
DiffReturn ResourceDiff
|
DiffReturnError error
|
||||||
DiffReturnError error
|
ResourcesCalled bool
|
||||||
ResourcesCalled bool
|
ResourcesReturn []ResourceType
|
||||||
ResourcesReturn []ResourceType
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MockResourceProvider) Configure(c map[string]interface{}) ([]string, error) {
|
func (p *MockResourceProvider) Configure(c map[string]interface{}) error {
|
||||||
p.ConfigureCalled = true
|
p.ConfigureCalled = true
|
||||||
p.ConfigureConfig = c
|
p.ConfigureConfig = c
|
||||||
return p.ConfigureReturnWarnings, p.ConfigureReturnError
|
return p.ConfigureReturnError
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MockResourceProvider) Diff(
|
func (p *MockResourceProvider) Diff(
|
||||||
|
|
|
@ -134,7 +134,9 @@ func (t *Terraform) diffWalkFn(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the provider if we haven't already
|
// Initialize the provider if we haven't already
|
||||||
p.init(vars)
|
if err := p.init(vars); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
l.RLock()
|
l.RLock()
|
||||||
var rs *ResourceState
|
var rs *ResourceState
|
||||||
|
@ -173,17 +175,15 @@ func (t *Terraform) diffWalkFn(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *terraformProvider) init(vars map[string]string) error {
|
func (t *terraformProvider) init(vars map[string]string) (err error) {
|
||||||
var err error
|
|
||||||
|
|
||||||
t.Once.Do(func() {
|
t.Once.Do(func() {
|
||||||
var c map[string]interface{}
|
var c map[string]interface{}
|
||||||
if t.Config != nil {
|
if t.Config != nil {
|
||||||
c = t.Config.ReplaceVariables(vars).Config
|
c = t.Config.ReplaceVariables(vars).Config
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = t.Provider.Configure(c)
|
err = t.Provider.Configure(c)
|
||||||
})
|
})
|
||||||
|
|
||||||
return err
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue