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)