From 5611b9b8a8db3bd533a9e3a212547dc1b4883c3f Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 28 Sep 2014 23:50:37 -0700 Subject: [PATCH] terraform: add Input API to ResourceProvider --- terraform/resource_provider.go | 9 +++++++++ terraform/resource_provider_mock.go | 13 +++++++++++++ 2 files changed, 22 insertions(+) diff --git a/terraform/resource_provider.go b/terraform/resource_provider.go index 859e7a1ec..d8705232d 100644 --- a/terraform/resource_provider.go +++ b/terraform/resource_provider.go @@ -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. diff --git a/terraform/resource_provider_mock.go b/terraform/resource_provider_mock.go index 060fef33b..29db7eeb3 100644 --- a/terraform/resource_provider_mock.go +++ b/terraform/resource_provider_mock.go @@ -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()