@@ -21,7 +21,7 @@ import (
2121 "reflect"
2222 "strings"
2323
24- admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014 /admin"
24+ "go.mongodb.org/atlas-sdk/v20250312013 /admin"
2525
2626 "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
2727 "github.com/aws/aws-sdk-go-v2/aws"
@@ -63,7 +63,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
6363 if peErr != nil {
6464 return * peErr , nil
6565 }
66- atlasV2 := client .Atlas20231115014
66+ atlasV2 := client .AtlasSDK
6767
6868 if currentModel .Id != nil && * currentModel .Id != "" {
6969 _ , _ = logger .Warnf ("resource already exists for Id: %s" , * currentModel .Id )
@@ -78,19 +78,20 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
7878 return progressevents .GetFailedEventByCode (err .Error (), string (types .HandlerErrorCodeInvalidRequest )), err
7979 }
8080
81- alertConfigRequest := admin20231115014.GroupAlertsConfig {
82- GroupId : currentModel .ProjectId ,
83- EventTypeName : currentModel .EventTypeName ,
84- Enabled : currentModel .Enabled ,
85- Matchers : expandAlertConfigurationMatchers (currentModel .Matchers ),
86- MetricThreshold : expandAlertConfigurationMetricThresholdConfig (currentModel ),
87- Threshold : expandAlertConfigurationThreshold (currentModel .Threshold ),
88- Notifications : notifications ,
81+ alertConfigRequest := admin.GroupAlertsConfig {
82+ GroupId : currentModel .ProjectId ,
83+ EventTypeName : currentModel .EventTypeName ,
84+ Enabled : currentModel .Enabled ,
85+ Matchers : expandAlertConfigurationMatchers (currentModel .Matchers ),
86+ MetricThreshold : expandAlertConfigurationMetricThresholdConfig (currentModel ),
87+ Threshold : expandAlertConfigurationThreshold (currentModel .Threshold ),
88+ Notifications : notifications ,
89+ SeverityOverride : currentModel .SeverityOverride ,
8990 }
9091
9192 projectID := * currentModel .ProjectId
9293 var res * http.Response
93- alertConfig , res , err := atlasV2 .AlertConfigurationsApi .CreateAlertConfiguration (context .Background (), projectID , & alertConfigRequest ).Execute ()
94+ alertConfig , res , err := atlasV2 .AlertConfigurationsApi .CreateAlertConfig (context .Background (), projectID , & alertConfigRequest ).Execute ()
9495 defer res .Body .Close ()
9596 if err != nil {
9697 return progressevents .GetFailedEventByResponse (err .Error (), res ), nil
@@ -120,7 +121,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
120121 if peErr != nil {
121122 return * peErr , nil
122123 }
123- atlasV2 := client .Atlas20231115014
124+ atlasV2 := client .AtlasSDK
124125
125126 if ! isExist (currentModel , atlasV2 ) {
126127 _ , _ = logger .Warnf ("resource not exist for Id: %s" , * currentModel .Id )
@@ -130,7 +131,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
130131 HandlerErrorCode : string (types .HandlerErrorCodeNotFound )}, nil
131132 }
132133
133- alertConfig , resp , err := atlasV2 .AlertConfigurationsApi .GetAlertConfiguration (context .Background (), * currentModel .ProjectId , * currentModel .Id ).Execute ()
134+ alertConfig , resp , err := atlasV2 .AlertConfigurationsApi .GetAlertConfig (context .Background (), * currentModel .ProjectId , * currentModel .Id ).Execute ()
134135 defer resp .Body .Close ()
135136 if err != nil {
136137 return progressevents .GetFailedEventByResponse (err .Error (), resp ), nil
@@ -160,7 +161,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
160161 if peErr != nil {
161162 return * peErr , nil
162163 }
163- atlasV2 := client .Atlas20231115014
164+ atlasV2 := client .AtlasSDK
164165
165166 if ! isExist (currentModel , atlasV2 ) {
166167 _ , _ = logger .Warnf ("resource not exist for Id: %s" , * currentModel .Id )
@@ -174,7 +175,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
174175 // server returns an error 500
175176 projectID := * currentModel .ProjectId
176177 id := * currentModel .Id
177- alertReq , res , err := atlasV2 .AlertConfigurationsApi .GetAlertConfiguration (context .Background (), projectID , id ).Execute ()
178+ alertReq , res , err := atlasV2 .AlertConfigurationsApi .GetAlertConfig (context .Background (), projectID , id ).Execute ()
178179 if err != nil {
179180 return progressevents .GetFailedEventByResponse (err .Error (), res ), nil
180181 }
@@ -184,15 +185,15 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
184185 // Removing the computed attributes to recreate the original request
185186 alertReq .Created = nil
186187 alertReq .Updated = nil
187- var alertModel * admin20231115014 .GroupAlertsConfig
188+ var alertModel * admin .GroupAlertsConfig
188189
189190 // Cannot enable/disable ONLY via update (if only send enable as changed field server returns a 500 error)
190191 // so have to use different method to change enabled.
191- if reflect .DeepEqual (alertReq , & admin20231115014 .GroupAlertsConfig {Enabled : aws .Bool (true )}) ||
192- reflect .DeepEqual (alertReq , & admin20231115014 .GroupAlertsConfig {Enabled : aws .Bool (false )}) {
193- alertModel , res , err = atlasV2 .AlertConfigurationsApi .ToggleAlertConfiguration (context .Background (), projectID , id , & admin20231115014 .AlertsToggle {Enabled : alertReq .Enabled }).Execute ()
192+ if reflect .DeepEqual (alertReq , & admin .GroupAlertsConfig {Enabled : aws .Bool (true )}) ||
193+ reflect .DeepEqual (alertReq , & admin .GroupAlertsConfig {Enabled : aws .Bool (false )}) {
194+ alertModel , res , err = atlasV2 .AlertConfigurationsApi .ToggleAlertConfig (context .Background (), projectID , id , & admin .AlertsToggle {Enabled : alertReq .Enabled }).Execute ()
194195 } else {
195- alertModel , res , err = atlasV2 .AlertConfigurationsApi .UpdateAlertConfiguration (context .Background (), projectID , id , alertReq ).Execute ()
196+ alertModel , res , err = atlasV2 .AlertConfigurationsApi .UpdateAlertConfig (context .Background (), projectID , id , alertReq ).Execute ()
196197 }
197198
198199 if err != nil {
@@ -224,7 +225,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
224225 if peErr != nil {
225226 return * peErr , nil
226227 }
227- atlasV2 := client .Atlas20231115014
228+ atlasV2 := client .AtlasSDK
228229
229230 if ! isExist (currentModel , atlasV2 ) {
230231 _ , _ = logger .Warnf ("resource not exist for Id: %s" , * currentModel .Id )
@@ -234,7 +235,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
234235 HandlerErrorCode : string (types .HandlerErrorCodeNotFound )}, nil
235236 }
236237
237- res , err := atlasV2 .AlertConfigurationsApi .DeleteAlertConfiguration (context .Background (), * currentModel .ProjectId , * currentModel .Id ).Execute ()
238+ res , err := atlasV2 .AlertConfigurationsApi .DeleteAlertConfig (context .Background (), * currentModel .ProjectId , * currentModel .Id ).Execute ()
238239
239240 if err != nil {
240241 _ , _ = logger .Warnf ("Delete - error: %+v" , err )
@@ -253,15 +254,15 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
253254 HandlerErrorCode : string (types .HandlerErrorCodeNotFound )}, nil
254255}
255256
256- func isExist (currentModel * Model , client * admin20231115014 .APIClient ) bool {
257- alert , _ , err := client .AlertConfigurationsApi .GetAlertConfiguration (context .Background (), * currentModel .ProjectId , * currentModel .Id ).Execute ()
257+ func isExist (currentModel * Model , client * admin .APIClient ) bool {
258+ alert , _ , err := client .AlertConfigurationsApi .GetAlertConfig (context .Background (), * currentModel .ProjectId , * currentModel .Id ).Execute ()
258259 return err == nil && alert != nil
259260}
260261
261- func expandAlertConfigurationMatchers (matchers []Matcher ) * []admin20231115014 .StreamsMatcher {
262- mts := make ([]admin20231115014 .StreamsMatcher , 0 )
262+ func expandAlertConfigurationMatchers (matchers []Matcher ) * []admin .StreamsMatcher {
263+ mts := make ([]admin .StreamsMatcher , 0 )
263264 for ind := range matchers {
264- mMatcher := admin20231115014 .NewStreamsMatcher (
265+ mMatcher := admin .NewStreamsMatcher (
265266 cast .ToString (matchers [ind ].FieldName ),
266267 cast .ToString (matchers [ind ].Operator ),
267268 cast .ToString (matchers [ind ].Value ),
@@ -271,12 +272,12 @@ func expandAlertConfigurationMatchers(matchers []Matcher) *[]admin20231115014.St
271272 return & mts
272273}
273274
274- func expandAlertConfigurationMetricThresholdConfig (currentModel * Model ) * admin20231115014. ServerlessMetricThreshold {
275+ func expandAlertConfigurationMetricThresholdConfig (currentModel * Model ) * admin. FlexClusterMetricThreshold {
275276 threshold := currentModel .MetricThreshold
276277 if threshold == nil {
277278 return nil
278279 }
279- return & admin20231115014. ServerlessMetricThreshold {
280+ return & admin. FlexClusterMetricThreshold {
280281 MetricName : cast .ToString (threshold .MetricName ),
281282 Operator : threshold .Operator ,
282283 Threshold : threshold .Threshold ,
@@ -285,19 +286,19 @@ func expandAlertConfigurationMetricThresholdConfig(currentModel *Model) *admin20
285286 }
286287}
287288
288- func expandAlertConfigurationThreshold (threshold * IntegerThresholdView ) * admin20231115014. GreaterThanRawThreshold {
289+ func expandAlertConfigurationThreshold (threshold * IntegerThresholdView ) * admin. StreamProcessorMetricThreshold {
289290 if threshold == nil {
290291 return nil
291292 }
292- return & admin20231115014. GreaterThanRawThreshold {
293+ return & admin. StreamProcessorMetricThreshold {
293294 Operator : threshold .Operator ,
294- Threshold : util . Pointer ( int ( * threshold .Threshold )) ,
295+ Threshold : threshold .Threshold ,
295296 Units : threshold .Units ,
296297 }
297298}
298299
299- func expandAlertConfigurationNotification (notificationList []NotificationView ) (* []admin20231115014 .AlertsNotificationRootForGroup , error ) {
300- notifications := make ([]admin20231115014 .AlertsNotificationRootForGroup , 0 )
300+ func expandAlertConfigurationNotification (notificationList []NotificationView ) (* []admin .AlertsNotificationRootForGroup , error ) {
301+ notifications := make ([]admin .AlertsNotificationRootForGroup , 0 )
301302
302303 for ind := range notificationList {
303304 if notificationList [ind ].IntervalMin != nil && * notificationList [ind ].IntervalMin > cast .ToFloat64 (0 ) {
@@ -309,7 +310,7 @@ func expandAlertConfigurationNotification(notificationList []NotificationView) (
309310 }
310311
311312 for ind := range notificationList {
312- notification := admin20231115014 .AlertsNotificationRootForGroup {
313+ notification := admin .AlertsNotificationRootForGroup {
313314 ApiToken : notificationList [ind ].ApiToken ,
314315 ChannelName : notificationList [ind ].ChannelName ,
315316 DatadogApiKey : notificationList [ind ].DatadogApiKey ,
@@ -330,15 +331,17 @@ func expandAlertConfigurationNotification(notificationList []NotificationView) (
330331 VictorOpsRoutingKey : notificationList [ind ].VictorOpsRoutingKey ,
331332 Roles : & notificationList [ind ].Roles ,
332333 DelayMin : notificationList [ind ].DelayMin ,
334+ NotifierId : notificationList [ind ].NotifierId ,
335+ IntegrationId : notificationList [ind ].IntegrationId ,
333336 }
334337 notifications = append (notifications , notification )
335338 }
336339 return & notifications , nil
337340}
338341
339- func convertToMongoModel (reqModel * admin20231115014 .GroupAlertsConfig , currentModel * Model ) * admin20231115014 .GroupAlertsConfig {
342+ func convertToMongoModel (reqModel * admin .GroupAlertsConfig , currentModel * Model ) * admin .GroupAlertsConfig {
340343 if reqModel == nil {
341- reqModel = & admin20231115014 .GroupAlertsConfig {}
344+ reqModel = & admin .GroupAlertsConfig {}
342345 }
343346
344347 // Only change the updated fields
@@ -360,10 +363,13 @@ func convertToMongoModel(reqModel *admin20231115014.GroupAlertsConfig, currentMo
360363 if currentModel .Notifications != nil {
361364 reqModel .Notifications , _ = expandAlertConfigurationNotification (currentModel .Notifications )
362365 }
366+ if currentModel .SeverityOverride != nil {
367+ reqModel .SeverityOverride = currentModel .SeverityOverride
368+ }
363369 return reqModel
364370}
365371
366- func convertToUIModel (alertConfig * admin20231115014 .GroupAlertsConfig , currentModel * Model ) * Model {
372+ func convertToUIModel (alertConfig * admin .GroupAlertsConfig , currentModel * Model ) * Model {
367373 currentModel .Id = alertConfig .Id
368374 if alertConfig .Created != nil {
369375 currentModel .Created = util .TimePtrToStringPtr (alertConfig .Created )
@@ -377,5 +383,9 @@ func convertToUIModel(alertConfig *admin20231115014.GroupAlertsConfig, currentMo
377383 currentModel .Enabled = alertConfig .Enabled
378384 }
379385
386+ if alertConfig .SeverityOverride != nil {
387+ currentModel .SeverityOverride = alertConfig .SeverityOverride
388+ }
389+
380390 return currentModel
381391}
0 commit comments