From e8808db8c3d1a11d7c08e623c7d0adac8b014543 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Thu, 19 Jun 2014 14:08:10 -0700 Subject: [PATCH] terraform: MergeDiff uses a Diff as an argument --- terraform/state.go | 5 ++--- terraform/state_test.go | 38 +++++++++++++++++++++----------------- terraform/terraform.go | 2 +- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/terraform/state.go b/terraform/state.go index f99156736..f7ba29733 100644 --- a/terraform/state.go +++ b/terraform/state.go @@ -110,8 +110,7 @@ type ResourceState struct { // If the diff attribute requires computing the value, and hence // won't be available until apply, the value is replaced with the // computeID. -func (s *ResourceState) MergeDiff( - d map[string]*ResourceAttrDiff) *ResourceState { +func (s *ResourceState) MergeDiff(d *ResourceDiff) *ResourceState { var result ResourceState if s != nil { result = *s @@ -123,7 +122,7 @@ func (s *ResourceState) MergeDiff( result.Attributes[k] = v } } - for k, diff := range d { + for k, diff := range d.Attributes { if diff.NewComputed { result.Attributes[k] = config.UnknownVariableValue continue diff --git a/terraform/state_test.go b/terraform/state_test.go index 60d966eaf..e3f24b3ec 100644 --- a/terraform/state_test.go +++ b/terraform/state_test.go @@ -16,19 +16,21 @@ func TestResourceState_MergeDiff(t *testing.T) { }, } - diff := map[string]*ResourceAttrDiff{ - "foo": &ResourceAttrDiff{ - Old: "bar", - New: "baz", - }, - "bar": &ResourceAttrDiff{ - Old: "", - New: "foo", - }, - "baz": &ResourceAttrDiff{ - Old: "", - New: "foo", - NewComputed: true, + diff := &ResourceDiff{ + Attributes: map[string]*ResourceAttrDiff{ + "foo": &ResourceAttrDiff{ + Old: "bar", + New: "baz", + }, + "bar": &ResourceAttrDiff{ + Old: "", + New: "foo", + }, + "baz": &ResourceAttrDiff{ + Old: "", + New: "foo", + NewComputed: true, + }, }, } @@ -48,10 +50,12 @@ func TestResourceState_MergeDiff(t *testing.T) { func TestResourceState_MergeDiff_nil(t *testing.T) { var rs *ResourceState = nil - diff := map[string]*ResourceAttrDiff{ - "foo": &ResourceAttrDiff{ - Old: "", - New: "baz", + diff := &ResourceDiff{ + Attributes: map[string]*ResourceAttrDiff{ + "foo": &ResourceAttrDiff{ + Old: "", + New: "baz", + }, }, } diff --git a/terraform/terraform.go b/terraform/terraform.go index 5b760c14d..669c52c43 100644 --- a/terraform/terraform.go +++ b/terraform/terraform.go @@ -190,7 +190,7 @@ func (t *Terraform) diffWalkFn( // Determine the new state and update variables vars := make(map[string]string) - rs := r.State.MergeDiff(diff.Attributes) + rs := r.State.MergeDiff(diff) for ak, av := range rs.Attributes { vars[fmt.Sprintf("%s.%s", r.Id, ak)] = av }