From d37bb87bf240e26997a83f96244c8caba7914cc8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 30 Sep 2016 11:29:59 -0700 Subject: [PATCH] terraform: ResourceConfig.DeepCopy should handle the nil case --- terraform/resource.go | 5 +++++ terraform/resource_test.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/terraform/resource.go b/terraform/resource.go index db6db9ffd..937efdbe4 100644 --- a/terraform/resource.go +++ b/terraform/resource.go @@ -98,6 +98,11 @@ func NewResourceConfig(c *config.RawConfig) *ResourceConfig { // to modify any of the structures that are part of the resource config without // affecting the original configuration. func (c *ResourceConfig) DeepCopy() *ResourceConfig { + // DeepCopying a nil should return a nil to avoid panics + if c == nil { + return nil + } + // Copy, this will copy all the exported attributes copy, err := copystructure.Config{Lock: true}.Copy(c) if err != nil { diff --git a/terraform/resource_test.go b/terraform/resource_test.go index 85792fc2e..ab6a2273b 100644 --- a/terraform/resource_test.go +++ b/terraform/resource_test.go @@ -239,6 +239,14 @@ func TestResourceConfigGet(t *testing.T) { } } +func TestResourceConfigDeepCopy_nil(t *testing.T) { + var nilRc *ResourceConfig + actual := nilRc.DeepCopy() + if actual != nil { + t.Fatalf("bad: %#v", actual) + } +} + func TestResourceConfigEqual_nil(t *testing.T) { var nilRc *ResourceConfig notNil := NewResourceConfig(nil)