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,19 +16,21 @@ func TestResourceState_MergeDiff(t *testing.T) {
}, },
} }
diff := map[string]*ResourceAttrDiff{ diff := &ResourceDiff{
"foo": &ResourceAttrDiff{ Attributes: map[string]*ResourceAttrDiff{
Old: "bar", "foo": &ResourceAttrDiff{
New: "baz", Old: "bar",
}, New: "baz",
"bar": &ResourceAttrDiff{ },
Old: "", "bar": &ResourceAttrDiff{
New: "foo", Old: "",
}, New: "foo",
"baz": &ResourceAttrDiff{ },
Old: "", "baz": &ResourceAttrDiff{
New: "foo", Old: "",
NewComputed: true, New: "foo",
NewComputed: true,
},
}, },
} }
@ -48,10 +50,12 @@ 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{
"foo": &ResourceAttrDiff{ Attributes: map[string]*ResourceAttrDiff{
Old: "", "foo": &ResourceAttrDiff{
New: "baz", Old: "",
New: "baz",
},
}, },
} }

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
} }