terraform: add Input API to ResourceProvider

This commit is contained in:
Mitchell Hashimoto 2014-09-28 23:50:37 -07:00
parent fd70e5e7bf
commit 5611b9b8a8
2 changed files with 22 additions and 0 deletions

View File

@ -4,6 +4,15 @@ package terraform
// resource provider: the thing that creates and manages the resources in
// a Terraform configuration.
type ResourceProvider interface {
// Input is called to ask the provider to ask the user for input
// for completing the configuration if necesarry.
//
// This may or may not be called, so resource provider writers shouldn't
// rely on this being available to set some default values for validate
// later. Example of a situation where this wouldn't be called is if
// the user is not using a TTY.
Input(UIInput, *ResourceConfig) (*ResourceConfig, error)
// Validate is called once at the beginning with the raw configuration
// (no interpolation done) and can return a list of warnings and/or
// errors.

View File

@ -12,6 +12,11 @@ type MockResourceProvider struct {
// Anything you want, in case you need to store extra data with the mock.
Meta interface{}
InputCalled bool
InputInput UIInput
InputConfig *ResourceConfig
InputReturnConfig *ResourceConfig
InputReturnError error
ApplyCalled bool
ApplyInfo *InstanceInfo
ApplyState *InstanceState
@ -51,6 +56,14 @@ type MockResourceProvider struct {
ValidateResourceReturnErrors []error
}
func (p *MockResourceProvider) Input(
input UIInput, c *ResourceConfig) (*ResourceConfig, error) {
p.InputCalled = true
p.InputInput = input
p.InputConfig = c
return p.InputReturnConfig, p.InputReturnError
}
func (p *MockResourceProvider) Validate(c *ResourceConfig) ([]string, []error) {
p.Lock()
defer p.Unlock()