Merge pull request #22690 from hashicorp/jbardin/diff-apply-panic

prevent panics when encountering nil diffs
This commit is contained in:
James Bardin 2019-09-05 09:32:07 -04:00 committed by GitHub
commit 72f9385285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -47,6 +47,8 @@ func TestDiffApply_set(t *testing.T) {
"egress.746197026.security_groups.#": {Old: "", New: "0", NewComputed: false, NewRemoved: false},
"egress.746197026.self": {Old: "", New: "false", NewComputed: false, NewRemoved: false},
"egress.746197026.to_port": {Old: "", New: "8000", NewComputed: false, NewRemoved: false},
// an erroneous nil diff should do nothing
"egress.111111111.to_port": nil,
},
}

View File

@ -513,6 +513,12 @@ func (d *InstanceDiff) applyBlockDiff(path []string, attrs map[string]string, sc
}
for k, diff := range d.Attributes {
// helper/schema should not insert nil diff values, but don't panic
// if it does.
if diff == nil {
continue
}
if strings.HasPrefix(k, blockKey) {
nextDot := strings.Index(k[len(blockKey):], ".")
if nextDot < 0 {
@ -539,6 +545,12 @@ func (d *InstanceDiff) applyBlockDiff(path []string, attrs map[string]string, sc
// that we're dropping. Since we're only applying the "New"
// portion of the set, we can ignore diffs that only contain "Old"
for attr, diff := range d.Attributes {
// helper/schema should not insert nil diff values, but don't panic
// if it does.
if diff == nil {
continue
}
if !strings.HasPrefix(attr, indexPrefix) {
continue
}