Merge pull request #17261 from hashicorp/b-diff-crash-set
helper/schema: Prevent crash on removal of computed field in CustomizeDiff
This commit is contained in:
commit
a4388b0ef2
|
@ -427,6 +427,13 @@ func (m schemaMap) Diff(
|
|||
}
|
||||
}
|
||||
|
||||
// Remove any nil diffs just to keep things clean
|
||||
for k, v := range result.Attributes {
|
||||
if v == nil {
|
||||
delete(result.Attributes, k)
|
||||
}
|
||||
}
|
||||
|
||||
// If this is a non-destroy diff, call any custom diff logic that has been
|
||||
// defined.
|
||||
if !result.DestroyTainted && customizeDiff != nil {
|
||||
|
@ -521,13 +528,6 @@ func (m schemaMap) Diff(
|
|||
result = result2
|
||||
}
|
||||
|
||||
// Remove any nil diffs just to keep things clean
|
||||
for k, v := range result.Attributes {
|
||||
if v == nil {
|
||||
delete(result.Attributes, k)
|
||||
}
|
||||
}
|
||||
|
||||
// Go through and detect all of the ComputedWhens now that we've
|
||||
// finished the diff.
|
||||
// TODO
|
||||
|
|
|
@ -3142,6 +3142,53 @@ func TestSchemaMap_Diff(t *testing.T) {
|
|||
"var.foo": interfaceToVariableSwallowError(""),
|
||||
},
|
||||
},
|
||||
|
||||
{
|
||||
Name: "optional, computed, empty string should not crash in CustomizeDiff",
|
||||
Schema: map[string]*Schema{
|
||||
"unrelated_set": {
|
||||
Type: TypeSet,
|
||||
Optional: true,
|
||||
Elem: &Schema{Type: TypeString},
|
||||
},
|
||||
"stream_enabled": {
|
||||
Type: TypeBool,
|
||||
Optional: true,
|
||||
},
|
||||
"stream_view_type": {
|
||||
Type: TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
|
||||
State: &terraform.InstanceState{
|
||||
Attributes: map[string]string{
|
||||
"unrelated_set.#": "0",
|
||||
"stream_enabled": "true",
|
||||
"stream_view_type": "KEYS_ONLY",
|
||||
},
|
||||
},
|
||||
Config: map[string]interface{}{
|
||||
"stream_enabled": false,
|
||||
"stream_view_type": "",
|
||||
},
|
||||
CustomizeDiff: func(diff *ResourceDiff, v interface{}) error {
|
||||
v, ok := diff.GetOk("unrelated_set")
|
||||
if ok {
|
||||
return fmt.Errorf("Didn't expect unrelated_set: %#v", v)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Diff: &terraform.InstanceDiff{
|
||||
Attributes: map[string]*terraform.ResourceAttrDiff{
|
||||
"stream_enabled": {
|
||||
Old: "true",
|
||||
New: "false",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tc := range cases {
|
||||
|
|
Loading…
Reference in New Issue