Skip to content

Commit

Permalink
fix: Fixes nil pointer dereference in `mongodbatlas_alert_configurati…
Browse files Browse the repository at this point in the history
…on` (#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 <430982+lantoli@users.noreply.github.com>

* remove periods at the end of changelog entries to make it consistent

---------

Co-authored-by: Leo Antoli <430982+lantoli@users.noreply.github.com>
  • Loading branch information
oarbusi and lantoli authored Jul 30, 2024
1 parent 7d35739 commit 7fdbae1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .changelog/2436.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
```release-note:note
resource/mongodbatlas_cloud_backup_snapshot_export_job: Deprecates the `err_msg` attribute.
resource/mongodbatlas_cloud_backup_snapshot_export_job: Deprecates the `err_msg` attribute
```

```release-note:note
data-source/mongodbatlas_cloud_backup_snapshot_export_job: Deprecates the `err_msg` attribute.
data-source/mongodbatlas_cloud_backup_snapshot_export_job: Deprecates the `err_msg` attribute
```

```release-note:note
data-source/mongodbatlas_cloud_backup_snapshot_export_jobs: Deprecates the `err_msg` attribute.
data-source/mongodbatlas_cloud_backup_snapshot_export_jobs: Deprecates the `err_msg` attribute
```
2 changes: 1 addition & 1 deletion .changelog/2462.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```release-note:bug
resource/mongodbatlas_organization: Fixes a bug in organization resource creation where the provider crashed.
resource/mongodbatlas_organization: Fixes a bug in organization resource creation where the provider crashed
```
3 changes: 3 additions & 0 deletions .changelog/2463.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
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`
```
28 changes: 14 additions & 14 deletions internal/service/alertconfiguration/model_alert_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
},
}
}
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}
}
Expand All @@ -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}
}
Expand Down

0 comments on commit 7fdbae1

Please sign in to comment.