terraform: MergeDiff can take nil diff
This commit is contained in:
parent
d93df76f66
commit
7eacacbff2
|
@ -131,13 +131,15 @@ func (s *ResourceState) MergeDiff(d *ResourceDiff) *ResourceState {
|
||||||
result.Attributes[k] = v
|
result.Attributes[k] = v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for k, diff := range d.Attributes {
|
if d != nil {
|
||||||
if diff.NewComputed {
|
for k, diff := range d.Attributes {
|
||||||
result.Attributes[k] = config.UnknownVariableValue
|
if diff.NewComputed {
|
||||||
continue
|
result.Attributes[k] = config.UnknownVariableValue
|
||||||
}
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
result.Attributes[k] = diff.New
|
result.Attributes[k] = diff.New
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &result
|
return &result
|
||||||
|
|
|
@ -70,6 +70,25 @@ func TestResourceState_MergeDiff_nil(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestResourceState_MergeDiff_nilDiff(t *testing.T) {
|
||||||
|
rs := ResourceState{
|
||||||
|
ID: "foo",
|
||||||
|
Attributes: map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
rs2 := rs.MergeDiff(nil)
|
||||||
|
|
||||||
|
expected := map[string]string{
|
||||||
|
"foo": "bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(expected, rs2.Attributes) {
|
||||||
|
t.Fatalf("bad: %#v", rs2.Attributes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestReadWriteState(t *testing.T) {
|
func TestReadWriteState(t *testing.T) {
|
||||||
state := &State{
|
state := &State{
|
||||||
Resources: map[string]*ResourceState{
|
Resources: map[string]*ResourceState{
|
||||||
|
|
Loading…
Reference in New Issue