From f73dc844c7a9e279bb47552f37fb63d4b532ac81 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 26 Sep 2016 18:01:02 -0700 Subject: [PATCH] wip --- terraform/resource_test.go | 13 ++++++++++ terraform/shadow_resource_provider.go | 35 +++++++++++++++++++++------ 2 files changed, 41 insertions(+), 7 deletions(-) diff --git a/terraform/resource_test.go b/terraform/resource_test.go index b6a9577263..85792fc2ea 100644 --- a/terraform/resource_test.go +++ b/terraform/resource_test.go @@ -239,6 +239,19 @@ func TestResourceConfigGet(t *testing.T) { } } +func TestResourceConfigEqual_nil(t *testing.T) { + var nilRc *ResourceConfig + notNil := NewResourceConfig(nil) + + if nilRc.Equal(notNil) { + t.Fatal("should not be equal") + } + + if notNil.Equal(nilRc) { + t.Fatal("should not be equal") + } +} + func testResourceConfig( t *testing.T, c map[string]interface{}) *ResourceConfig { raw, err := config.NewRawConfig(c) diff --git a/terraform/shadow_resource_provider.go b/terraform/shadow_resource_provider.go index 7b512146ac..84dc349bea 100644 --- a/terraform/shadow_resource_provider.go +++ b/terraform/shadow_resource_provider.go @@ -84,6 +84,18 @@ func (p *shadowResourceProviderReal) Close() error { return result } +func (p *shadowResourceProviderReal) Input( + input UIInput, c *ResourceConfig) (*ResourceConfig, error) { + result, err := p.ResourceProvider.Input(input, c) + p.Shared.Input.SetValue(&shadowResourceProviderInput{ + Config: c, + Result: result, + ResultErr: err, + }) + + return result, err +} + // shadowResourceProviderShadow is the shadow resource provider. Function // calls never affect real resources. This is paired with the "real" side // which must be called properly to enable recording. @@ -130,12 +142,6 @@ func (p *shadowResourceProviderShadow) Close() error { return v.(error) } -type shadowResourceProviderInput struct { - Config *ResourceConfig - Result *ResourceConfig - ResultErr error -} - func (p *shadowResourceProviderShadow) Input( input UIInput, c *ResourceConfig) (*ResourceConfig, error) { // Get the result of the input call @@ -154,7 +160,13 @@ func (p *shadowResourceProviderShadow) Input( } // Compare the parameters, which should be identical - // TODO + if !c.Equal(result.Config) { + p.ErrorLock.Lock() + p.Error = multierror.Append(p.Error, fmt.Errorf( + "Input had unequal configurations (real, then shadow):\n\n%#v\n\n%#v", + result.Config, c)) + p.ErrorLock.Unlock() + } // Return the results return result.Result, result.ResultErr @@ -217,3 +229,12 @@ func (p *shadowResourceProviderShadow) ReadDataApply( d *InstanceDiff) (*InstanceState, error) { return nil, nil } + +// The structs for the various function calls are put below. These structs +// are used to carry call information across the real/shadow boundaries. + +type shadowResourceProviderInput struct { + Config *ResourceConfig + Result *ResourceConfig + ResultErr error +}