-
Notifications
You must be signed in to change notification settings - Fork 178
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: Fixes nil pointer dereference in mongodbatlas_alert_configuration
#2463
Changes from 3 commits
e2e9461
55b5b4e
eb6e360
6092388
b079df5
a5155ac
7d93fda
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:bug | ||
resource/mongodbatlas_alert_configuration: Fixes nil pointer dereference when alert is modified outside Terraform | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -200,28 +200,28 @@ func NewTFMetricThresholdConfigModel(t *admin.ServerlessMetricThreshold, currSta | |
return []TfMetricThresholdConfigModel{ | ||
{ | ||
MetricName: conversion.StringNullIfEmpty(t.MetricName), | ||
Operator: conversion.StringNullIfEmpty(*t.Operator), | ||
Threshold: types.Float64Value(*t.Threshold), | ||
Units: conversion.StringNullIfEmpty(*t.Units), | ||
Mode: conversion.StringNullIfEmpty(*t.Mode), | ||
Operator: conversion.StringNullIfEmpty(t.GetOperator()), | ||
Threshold: types.Float64Value(t.GetThreshold()), | ||
Units: conversion.StringNullIfEmpty(t.GetUnits()), | ||
Mode: conversion.StringNullIfEmpty(t.GetMode()), | ||
Comment on lines
-203
to
+206
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just to fully understand, how where you able to have the API respond with a MetricThreshold object that only had some fields defined? Which one was not being returned? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue was for
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in these cases it would be great to create a test that fails before the fix and passes after the fix is applied There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have not been able to create a test for this because to reproduce this issue the resource has to be modified from outside TF. I don't think we currently are able to reproduce this cases in our tests. Open to suggestions though :) |
||
}, | ||
} | ||
} | ||
currState := currStateSlice[0] | ||
newState := TfMetricThresholdConfigModel{ | ||
Threshold: types.Float64Value(*t.Threshold), | ||
Threshold: types.Float64Value(t.GetThreshold()), | ||
} | ||
if !currState.MetricName.IsNull() { | ||
newState.MetricName = conversion.StringNullIfEmpty(t.MetricName) | ||
} | ||
if !currState.Operator.IsNull() { | ||
newState.Operator = conversion.StringNullIfEmpty(*t.Operator) | ||
newState.Operator = conversion.StringNullIfEmpty(t.GetOperator()) | ||
} | ||
if !currState.Units.IsNull() { | ||
newState.Units = conversion.StringNullIfEmpty(*t.Units) | ||
newState.Units = conversion.StringNullIfEmpty(t.GetUnits()) | ||
} | ||
if !currState.Mode.IsNull() { | ||
newState.Mode = conversion.StringNullIfEmpty(*t.Mode) | ||
newState.Mode = conversion.StringNullIfEmpty(t.GetMode()) | ||
} | ||
return []TfMetricThresholdConfigModel{newState} | ||
} | ||
|
@@ -234,21 +234,21 @@ func NewTFThresholdConfigModel(t *admin.GreaterThanRawThreshold, currStateSlice | |
if len(currStateSlice) == 0 { // threshold was created elsewhere from terraform, or import statement is being called | ||
return []TfThresholdConfigModel{ | ||
{ | ||
Operator: conversion.StringNullIfEmpty(*t.Operator), | ||
Threshold: types.Float64Value(float64(*t.Threshold)), // int in new SDK but keeping float64 for backward compatibility | ||
Units: conversion.StringNullIfEmpty(*t.Units), | ||
Operator: conversion.StringNullIfEmpty(t.GetOperator()), | ||
Threshold: types.Float64Value(float64(t.GetThreshold())), // int in new SDK but keeping float64 for backward compatibility | ||
Units: conversion.StringNullIfEmpty(t.GetUnits()), | ||
}, | ||
} | ||
} | ||
currState := currStateSlice[0] | ||
newState := TfThresholdConfigModel{} | ||
if !currState.Operator.IsNull() { | ||
newState.Operator = conversion.StringNullIfEmpty(*t.Operator) | ||
newState.Operator = conversion.StringNullIfEmpty(t.GetOperator()) | ||
} | ||
if !currState.Units.IsNull() { | ||
newState.Units = conversion.StringNullIfEmpty(*t.Units) | ||
newState.Units = conversion.StringNullIfEmpty(t.GetUnits()) | ||
} | ||
newState.Threshold = types.Float64Value(float64(*t.Threshold)) | ||
newState.Threshold = types.Float64Value(float64(t.GetThreshold())) | ||
|
||
return []TfThresholdConfigModel{newState} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please put a period at the end of the sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, pleas consider rewriting as:
Fixes an issue where the
terraform apply
command crashes if you attempt to edit an existing Terraform alert by adding a value tothreshold_config
.