terraform: computeID
This commit is contained in:
parent
7c6920bba1
commit
082e784566
|
@ -27,14 +27,24 @@ type ResourceState struct {
|
||||||
// this resource state in order to generate a new state. This new
|
// this resource state in order to generate a new state. This new
|
||||||
// state can be used to provide updated attribute lookups for
|
// state can be used to provide updated attribute lookups for
|
||||||
// variable interpolation.
|
// 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(
|
func (s *ResourceState) MergeDiff(
|
||||||
d map[string]*ResourceAttrDiff) ResourceState {
|
d map[string]*ResourceAttrDiff,
|
||||||
|
computedID string) ResourceState {
|
||||||
result := *s
|
result := *s
|
||||||
result.Attributes = make(map[string]string)
|
result.Attributes = make(map[string]string)
|
||||||
for k, v := range s.Attributes {
|
for k, v := range s.Attributes {
|
||||||
result.Attributes[k] = v
|
result.Attributes[k] = v
|
||||||
}
|
}
|
||||||
for k, diff := range d {
|
for k, diff := range d {
|
||||||
|
if diff.NewComputed {
|
||||||
|
result.Attributes[k] = computedID
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
result.Attributes[k] = diff.New
|
result.Attributes[k] = diff.New
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,13 +22,19 @@ func TestResourceState_MergeDiff(t *testing.T) {
|
||||||
Old: "",
|
Old: "",
|
||||||
New: "foo",
|
New: "foo",
|
||||||
},
|
},
|
||||||
|
"baz": &ResourceAttrDiff{
|
||||||
|
Old: "",
|
||||||
|
New: "foo",
|
||||||
|
NewComputed: true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
rs2 := rs.MergeDiff(diff)
|
rs2 := rs.MergeDiff(diff, "what")
|
||||||
|
|
||||||
expected := map[string]string{
|
expected := map[string]string{
|
||||||
"foo": "baz",
|
"foo": "baz",
|
||||||
"bar": "foo",
|
"bar": "foo",
|
||||||
|
"baz": "what",
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(expected, rs2.Attributes) {
|
if !reflect.DeepEqual(expected, rs2.Attributes) {
|
||||||
|
|
Loading…
Reference in New Issue