From 7fdbae1202698506cefb67280d245d737266b7cc Mon Sep 17 00:00:00 2001 From: Oriol Date: Tue, 30 Jul 2024 15:39:35 +0200 Subject: [PATCH] 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 <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> --- .changelog/2436.txt | 6 ++-- .changelog/2462.txt | 2 +- .changelog/2463.txt | 3 ++ .../model_alert_configuration.go | 28 +++++++++---------- 4 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 .changelog/2463.txt diff --git a/.changelog/2436.txt b/.changelog/2436.txt index ee4fe558d3..347e6ddb71 100644 --- a/.changelog/2436.txt +++ b/.changelog/2436.txt @@ -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 ``` diff --git a/.changelog/2462.txt b/.changelog/2462.txt index 7adb409197..588a6e8d3b 100644 --- a/.changelog/2462.txt +++ b/.changelog/2462.txt @@ -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 ``` diff --git a/.changelog/2463.txt b/.changelog/2463.txt new file mode 100644 index 0000000000..9c4edff18e --- /dev/null +++ b/.changelog/2463.txt @@ -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` +``` diff --git a/internal/service/alertconfiguration/model_alert_configuration.go b/internal/service/alertconfiguration/model_alert_configuration.go index ef42960051..ab2b50c2ba 100644 --- a/internal/service/alertconfiguration/model_alert_configuration.go +++ b/internal/service/alertconfiguration/model_alert_configuration.go @@ -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} } @@ -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} }