terraform: computeID

This commit is contained in:
Mitchell Hashimoto 2014-06-05 07:01:51 -07:00
parent 7c6920bba1
commit 082e784566
2 changed files with 18 additions and 2 deletions

View File

@ -27,14 +27,24 @@ type ResourceState struct {
// this resource state in order to generate a new state. This new
// state can be used to provide updated attribute lookups for
// variable interpolation.
//
// 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 {
d map[string]*ResourceAttrDiff,
computedID string) ResourceState {
result := *s
result.Attributes = make(map[string]string)
for k, v := range s.Attributes {
result.Attributes[k] = v
}
for k, diff := range d {
if diff.NewComputed {
result.Attributes[k] = computedID
continue
}
result.Attributes[k] = diff.New
}

View File

@ -22,13 +22,19 @@ func TestResourceState_MergeDiff(t *testing.T) {
Old: "",
New: "foo",
},
"baz": &ResourceAttrDiff{
Old: "",
New: "foo",
NewComputed: true,
},
}
rs2 := rs.MergeDiff(diff)
rs2 := rs.MergeDiff(diff, "what")
expected := map[string]string{
"foo": "baz",
"bar": "foo",
"baz": "what",
}
if !reflect.DeepEqual(expected, rs2.Attributes) {