Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: aws_dms_replication_task - type assertion to avoid nil pointer panics #41096

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/41096.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_dms_replication_task: Fix `panic: interface conversion: interface {} is float64, not string`
```
27 changes: 20 additions & 7 deletions internal/service/dms/task_settings_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,40 @@ func taskSettingsEqual(state, proposed any) bool {

switch x := state.(type) {
case bool:
p := proposed.(bool)
p, ok := proposed.(bool)
if !ok {
return false
}
return x == p

case float64:
p := proposed.(float64)
p, ok := proposed.(float64)
if !ok {
return false
}
return x == p

case string:
p := proposed.(string)
p, ok := proposed.(string)
if !ok {
return false
}
return x == p

case map[string]any:
proposedMap := proposed.(map[string]any)
p, ok := proposed.(map[string]any)
if !ok {
return false
}
for k, v := range x {
if !taskSettingsEqual(v, proposedMap[k]) {
if !taskSettingsEqual(v, p[k]) {
return false
}
delete(proposedMap, k)
delete(p, k)
}
return len(proposedMap) == 0
return len(p) == 0
}

return false
}

Expand Down
30 changes: 30 additions & 0 deletions internal/service/dms/task_settings_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func TestTaskSettingsEqual(t *testing.T) {
b: false,
expected: false,
},
"incompatible types": {
a: true,
b: acctest.CtTrue,
expected: false,
},
},
"float64": {
"equal": {
Expand All @@ -76,6 +81,11 @@ func TestTaskSettingsEqual(t *testing.T) {
b: float64(1),
expected: false,
},
"incompatible types": {
a: float64(1),
b: "1",
expected: false,
},
},
"string": {
"equal": {
Expand Down Expand Up @@ -103,6 +113,11 @@ func TestTaskSettingsEqual(t *testing.T) {
b: names.AttrValue,
expected: false,
},
"incompatible types": {
a: names.AttrValue,
b: false,
expected: false,
},
},
"map": {
"equal": {
Expand Down Expand Up @@ -150,6 +165,21 @@ func TestTaskSettingsEqual(t *testing.T) {
},
expected: true,
},
"incompatible types": {
a: map[string]any{
acctest.CtKey1: names.AttrValue,
acctest.CtKey2: map[string]any{
"key3": names.AttrValue,
},
},
b: map[int]any{
0: names.AttrValue,
1: map[int]any{
10: names.AttrValue,
},
},
expected: false,
},
},
}

Expand Down
Loading