mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
Merge pull request #22690 from hashicorp/jbardin/diff-apply-panic
prevent panics when encountering nil diffs
This commit is contained in:
commit
72f9385285
@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user