terraform: check for errors initializing a provider

This commit is contained in:
Mitchell Hashimoto 2014-06-06 00:28:57 -07:00
parent ce0867fa09
commit 0561edc2fd
3 changed files with 21 additions and 22 deletions

View File

@ -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.

View File

@ -8,7 +8,6 @@ type MockResourceProvider struct {
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
@ -20,10 +19,10 @@ type MockResourceProvider struct {
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(

View File

@ -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
} }