Skip to content

Commit 7fdbae1

Browse files
oarbusilantoli
andauthored
fix: Fixes nil pointer dereference in mongodbatlas_alert_configuration (#2463)
* fix nil pointer dereference * avoid nil pointer dereference in metric_threshold_config * changelog entry * changelog suggestion * Update .changelog/2463.txt Co-authored-by: Leo Antoli <[email protected]> * remove periods at the end of changelog entries to make it consistent --------- Co-authored-by: Leo Antoli <[email protected]>
1 parent 7d35739 commit 7fdbae1

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

.changelog/2436.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
```release-note:note
2-
resource/mongodbatlas_cloud_backup_snapshot_export_job: Deprecates the `err_msg` attribute.
2+
resource/mongodbatlas_cloud_backup_snapshot_export_job: Deprecates the `err_msg` attribute
33
```
44

55
```release-note:note
6-
data-source/mongodbatlas_cloud_backup_snapshot_export_job: Deprecates the `err_msg` attribute.
6+
data-source/mongodbatlas_cloud_backup_snapshot_export_job: Deprecates the `err_msg` attribute
77
```
88

99
```release-note:note
10-
data-source/mongodbatlas_cloud_backup_snapshot_export_jobs: Deprecates the `err_msg` attribute.
10+
data-source/mongodbatlas_cloud_backup_snapshot_export_jobs: Deprecates the `err_msg` attribute
1111
```

.changelog/2462.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
```release-note:bug
2-
resource/mongodbatlas_organization: Fixes a bug in organization resource creation where the provider crashed.
2+
resource/mongodbatlas_organization: Fixes a bug in organization resource creation where the provider crashed
33
```

.changelog/2463.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/mongodbatlas_alert_configuration: Fixes an issue where the `terraform apply` command crashes if you attempt to edit an existing `mongodbatlas_alert_configuration` by adding a value to `threshold_config`
3+
```

internal/service/alertconfiguration/model_alert_configuration.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -200,28 +200,28 @@ func NewTFMetricThresholdConfigModel(t *admin.ServerlessMetricThreshold, currSta
200200
return []TfMetricThresholdConfigModel{
201201
{
202202
MetricName: conversion.StringNullIfEmpty(t.MetricName),
203-
Operator: conversion.StringNullIfEmpty(*t.Operator),
204-
Threshold: types.Float64Value(*t.Threshold),
205-
Units: conversion.StringNullIfEmpty(*t.Units),
206-
Mode: conversion.StringNullIfEmpty(*t.Mode),
203+
Operator: conversion.StringNullIfEmpty(t.GetOperator()),
204+
Threshold: types.Float64Value(t.GetThreshold()),
205+
Units: conversion.StringNullIfEmpty(t.GetUnits()),
206+
Mode: conversion.StringNullIfEmpty(t.GetMode()),
207207
},
208208
}
209209
}
210210
currState := currStateSlice[0]
211211
newState := TfMetricThresholdConfigModel{
212-
Threshold: types.Float64Value(*t.Threshold),
212+
Threshold: types.Float64Value(t.GetThreshold()),
213213
}
214214
if !currState.MetricName.IsNull() {
215215
newState.MetricName = conversion.StringNullIfEmpty(t.MetricName)
216216
}
217217
if !currState.Operator.IsNull() {
218-
newState.Operator = conversion.StringNullIfEmpty(*t.Operator)
218+
newState.Operator = conversion.StringNullIfEmpty(t.GetOperator())
219219
}
220220
if !currState.Units.IsNull() {
221-
newState.Units = conversion.StringNullIfEmpty(*t.Units)
221+
newState.Units = conversion.StringNullIfEmpty(t.GetUnits())
222222
}
223223
if !currState.Mode.IsNull() {
224-
newState.Mode = conversion.StringNullIfEmpty(*t.Mode)
224+
newState.Mode = conversion.StringNullIfEmpty(t.GetMode())
225225
}
226226
return []TfMetricThresholdConfigModel{newState}
227227
}
@@ -234,21 +234,21 @@ func NewTFThresholdConfigModel(t *admin.GreaterThanRawThreshold, currStateSlice
234234
if len(currStateSlice) == 0 { // threshold was created elsewhere from terraform, or import statement is being called
235235
return []TfThresholdConfigModel{
236236
{
237-
Operator: conversion.StringNullIfEmpty(*t.Operator),
238-
Threshold: types.Float64Value(float64(*t.Threshold)), // int in new SDK but keeping float64 for backward compatibility
239-
Units: conversion.StringNullIfEmpty(*t.Units),
237+
Operator: conversion.StringNullIfEmpty(t.GetOperator()),
238+
Threshold: types.Float64Value(float64(t.GetThreshold())), // int in new SDK but keeping float64 for backward compatibility
239+
Units: conversion.StringNullIfEmpty(t.GetUnits()),
240240
},
241241
}
242242
}
243243
currState := currStateSlice[0]
244244
newState := TfThresholdConfigModel{}
245245
if !currState.Operator.IsNull() {
246-
newState.Operator = conversion.StringNullIfEmpty(*t.Operator)
246+
newState.Operator = conversion.StringNullIfEmpty(t.GetOperator())
247247
}
248248
if !currState.Units.IsNull() {
249-
newState.Units = conversion.StringNullIfEmpty(*t.Units)
249+
newState.Units = conversion.StringNullIfEmpty(t.GetUnits())
250250
}
251-
newState.Threshold = types.Float64Value(float64(*t.Threshold))
251+
newState.Threshold = types.Float64Value(float64(t.GetThreshold()))
252252

253253
return []TfThresholdConfigModel{newState}
254254
}

0 commit comments

Comments
 (0)