From a5fc664ea6e545d65640be40d6721bfc0805d75b Mon Sep 17 00:00:00 2001 From: Chris Marchesi Date: Sat, 27 May 2017 17:24:57 -0700 Subject: [PATCH] helper/schema: Add schemaMap.DeepCopy This provides a deep copy of a schemaMap, which will be needed for the diff customization process as ResourceDiff will be able to flag fields as ForceNew - we don't want to affect the source schema. --- helper/schema/schema.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/helper/schema/schema.go b/helper/schema/schema.go index 362e7e6b13..95691072a1 100644 --- a/helper/schema/schema.go +++ b/helper/schema/schema.go @@ -21,6 +21,7 @@ import ( "strings" "github.com/hashicorp/terraform/terraform" + "github.com/mitchellh/copystructure" "github.com/mitchellh/mapstructure" ) @@ -370,6 +371,16 @@ func (m schemaMap) Data( }, nil } +// DeepCopy returns a copy of this schemaMap. The copy can be safely modified +// without affecting the original. +func (m *schemaMap) DeepCopy() schemaMap { + copy, err := copystructure.Config{Lock: true}.Copy(m) + if err != nil { + panic(err) + } + return copy.(schemaMap) +} + // Diff returns the diff for a resource given the schema map, // state, and configuration. func (m schemaMap) Diff(