terraform: MergeDiff uses a Diff as an argument

This commit is contained in:
Mitchell Hashimoto 2014-06-19 14:08:10 -07:00
parent c646c9c9ad
commit e8808db8c3
3 changed files with 24 additions and 21 deletions

View File

@ -110,8 +110,7 @@ type ResourceState struct {
// If the diff attribute requires computing the value, and hence // If the diff attribute requires computing the value, and hence
// won't be available until apply, the value is replaced with the // won't be available until apply, the value is replaced with the
// computeID. // computeID.
func (s *ResourceState) MergeDiff( func (s *ResourceState) MergeDiff(d *ResourceDiff) *ResourceState {
d map[string]*ResourceAttrDiff) *ResourceState {
var result ResourceState var result ResourceState
if s != nil { if s != nil {
result = *s result = *s
@ -123,7 +122,7 @@ func (s *ResourceState) MergeDiff(
result.Attributes[k] = v result.Attributes[k] = v
} }
} }
for k, diff := range d { for k, diff := range d.Attributes {
if diff.NewComputed { if diff.NewComputed {
result.Attributes[k] = config.UnknownVariableValue result.Attributes[k] = config.UnknownVariableValue
continue continue

View File

@ -16,7 +16,8 @@ func TestResourceState_MergeDiff(t *testing.T) {
}, },
} }
diff := map[string]*ResourceAttrDiff{ diff := &ResourceDiff{
Attributes: map[string]*ResourceAttrDiff{
"foo": &ResourceAttrDiff{ "foo": &ResourceAttrDiff{
Old: "bar", Old: "bar",
New: "baz", New: "baz",
@ -30,6 +31,7 @@ func TestResourceState_MergeDiff(t *testing.T) {
New: "foo", New: "foo",
NewComputed: true, NewComputed: true,
}, },
},
} }
rs2 := rs.MergeDiff(diff) rs2 := rs.MergeDiff(diff)
@ -48,11 +50,13 @@ func TestResourceState_MergeDiff(t *testing.T) {
func TestResourceState_MergeDiff_nil(t *testing.T) { func TestResourceState_MergeDiff_nil(t *testing.T) {
var rs *ResourceState = nil var rs *ResourceState = nil
diff := map[string]*ResourceAttrDiff{ diff := &ResourceDiff{
Attributes: map[string]*ResourceAttrDiff{
"foo": &ResourceAttrDiff{ "foo": &ResourceAttrDiff{
Old: "", Old: "",
New: "baz", New: "baz",
}, },
},
} }
rs2 := rs.MergeDiff(diff) rs2 := rs.MergeDiff(diff)

View File

@ -190,7 +190,7 @@ func (t *Terraform) diffWalkFn(
// Determine the new state and update variables // Determine the new state and update variables
vars := make(map[string]string) vars := make(map[string]string)
rs := r.State.MergeDiff(diff.Attributes) rs := r.State.MergeDiff(diff)
for ak, av := range rs.Attributes { for ak, av := range rs.Attributes {
vars[fmt.Sprintf("%s.%s", r.Id, ak)] = av vars[fmt.Sprintf("%s.%s", r.Id, ak)] = av
} }