From 3504054b1e517f56c03a3f0afe35c6eea8714638 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 1 Oct 2016 13:11:32 -0700 Subject: [PATCH] terraform: EvalContext.CloseProvider (shadow) works if never init --- terraform/shadow_eval_context.go | 7 ++++++- terraform/shadow_eval_context_test.go | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/terraform/shadow_eval_context.go b/terraform/shadow_eval_context.go index e39fc14db..0c962c433 100644 --- a/terraform/shadow_eval_context.go +++ b/terraform/shadow_eval_context.go @@ -229,7 +229,12 @@ func (c *shadowEvalContextShadow) Provider(n string) ResourceProvider { func (c *shadowEvalContextShadow) CloseProvider(n string) error { // Wait for the provider value - raw := c.Shared.Providers.Value(n) + raw, ok := c.Shared.Providers.ValueOk(n) + if !ok { + c.err(fmt.Errorf( + "CloseProvider called for uninitialized provider %q", n)) + return nil + } if raw == nil { c.err(fmt.Errorf( "Unknown 'CloseProvider' call for %q", n)) diff --git a/terraform/shadow_eval_context_test.go b/terraform/shadow_eval_context_test.go index 2ef5e2c09..08db93a9f 100644 --- a/terraform/shadow_eval_context_test.go +++ b/terraform/shadow_eval_context_test.go @@ -234,3 +234,24 @@ func TestShadowEvalContextCloseProvider_noInitClose(t *testing.T) { t.Fatal("should error") } } + +func TestShadowEvalContextCloseProvider_noCreate(t *testing.T) { + mock := new(MockEvalContext) + _, shadow := NewShadowEvalContext(mock) + + // Args, results + name := "foo" + mockResult := new(MockResourceProvider) + + // Configure the mock + mock.InitProviderProvider = mockResult + + // Close the provider + if err := shadow.CloseProvider(name); err != nil { + t.Fatalf("err: %s", err) + } + + if err := shadow.CloseShadow(); err == nil { + t.Fatal("should error") + } +}