@@ -25,7 +25,7 @@ import (
2525 log "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger"
2626 "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent"
2727 "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator"
28- admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002 /admin"
28+ "go.mongodb.org/atlas-sdk/v20250312012 /admin"
2929)
3030
3131var RequiredFields = []string {constants .IntegrationType , constants .ProjectID }
@@ -41,7 +41,7 @@ var requiredPerType = map[string][]string{
4141 "FLOWDOCK" : {"FlowName" , "ApiToken" , "OrgName" },
4242 "WEBHOOK" : {"Url" },
4343 "MICROSOFT_TEAMS" : {"MicrosoftTeamsWebhookUrl" },
44- "PROMETHEUS" : {"UserName" , "Password" , "ServiceDiscovery" , "Scheme" , " Enabled" },
44+ "PROMETHEUS" : {"UserName" , "Password" , "ServiceDiscovery" , "Enabled" },
4545}
4646
4747func validateModel (fields []string , model * Model ) * handler.ProgressEvent {
@@ -76,18 +76,24 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
7676 }
7777
7878 requestBody := modelToIntegration (currentModel )
79- integrations , resModel , err := client .Atlas20231115002 .ThirdPartyIntegrationsApi .CreateThirdPartyIntegration (context .Background (), * IntegrationType , * ProjectID , requestBody ).Execute ()
79+ integrations , resModel , err := client .AtlasSDK .ThirdPartyIntegrationsApi .CreateGroupIntegration (context .Background (), * IntegrationType , * ProjectID , requestBody ).Execute ()
8080 if err != nil {
81- if apiError , ok := admin20231115002 .AsError (err ); ok && * apiError .Error == http .StatusConflict {
81+ if apiError , ok := admin .AsError (err ); ok && apiError .Error == http .StatusConflict {
8282 return progressevent .GetFailedEventByCode ("INTEGRATION_ALREADY_CONFIGURED." , string (types .HandlerErrorCodeAlreadyExists )), nil
8383 }
8484
8585 return progressevent .GetFailedEventByResponse (err .Error (), resModel ), nil
8686 }
8787
88+ results := integrations .GetResults ()
89+
90+ if len (results ) == 0 {
91+ return progressevent .GetFailedEventByResponse ("No integration returned from create" , resModel ), nil
92+ }
93+
8894 return handler.ProgressEvent {
8995 OperationStatus : handler .Success ,
90- ResourceModel : integrationToModel (* currentModel , & integrations . Results [0 ]),
96+ ResourceModel : integrationToModel (* currentModel , & results [0 ]),
9197 }, nil
9298}
9399
@@ -108,7 +114,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
108114 ProjectID := currentModel .ProjectId
109115 IntegrationType := currentModel .Type
110116
111- integration , res , err := client .Atlas20231115002 .ThirdPartyIntegrationsApi .GetThirdPartyIntegration (context .Background (), * ProjectID , * IntegrationType ).Execute ()
117+ integration , res , err := client .AtlasSDK .ThirdPartyIntegrationsApi .GetGroupIntegration (context .Background (), * ProjectID , * IntegrationType ).Execute ()
112118
113119 if err != nil {
114120 return progressevent .GetFailedEventByResponse (err .Error (), res ), nil
@@ -139,24 +145,29 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler
139145 ProjectID := currentModel .ProjectId
140146 IntegrationType := currentModel .Type
141147
142- integration , res , err := client .Atlas20231115002 .ThirdPartyIntegrationsApi .GetThirdPartyIntegration (context .Background (), * ProjectID , * IntegrationType ).Execute ()
148+ integration , res , err := client .AtlasSDK .ThirdPartyIntegrationsApi .GetGroupIntegration (context .Background (), * ProjectID , * IntegrationType ).Execute ()
143149 if err != nil {
144150 return progressevent .GetFailedEventByResponse (err .Error (), res ), nil
145151 }
146152
147153 updateIntegrationFromSchema (currentModel , integration )
148- integrations , res , err := client .Atlas20231115002 .ThirdPartyIntegrationsApi .UpdateThirdPartyIntegration (context .Background (), * IntegrationType , * ProjectID , integration ).Execute ()
154+ integrations , res , err := client .AtlasSDK .ThirdPartyIntegrationsApi .UpdateGroupIntegration (context .Background (), * IntegrationType , * ProjectID , integration ).Execute ()
149155 if err != nil {
150156 return progressevent .GetFailedEventByResponse (err .Error (), res ), nil
151157 }
152158
159+ results := integrations .GetResults ()
160+ if len (results ) == 0 {
161+ return progressevent .GetFailedEventByResponse ("No integration returned from update" , res ), nil
162+ }
163+
153164 return handler.ProgressEvent {
154165 OperationStatus : handler .Success ,
155- ResourceModel : integrationToModel (* currentModel , & integrations . Results [0 ]),
166+ ResourceModel : integrationToModel (* currentModel , & results [0 ]),
156167 }, nil
157168}
158169
159- func updateIntegrationFromSchema (currentModel * Model , integration * admin20231115002. ThridPartyIntegration ) {
170+ func updateIntegrationFromSchema (currentModel * Model , integration * admin. ThirdPartyIntegration ) {
160171 if util .IsStringPresent (currentModel .Url ) && ! util .AreStringPtrEqual (currentModel .Url , integration .Url ) {
161172 integration .Url = currentModel .Url
162173 }
@@ -196,12 +207,13 @@ func updateIntegrationFromSchema(currentModel *Model, integration *admin20231115
196207 if util .IsStringPresent (currentModel .ServiceDiscovery ) && ! util .AreStringPtrEqual (currentModel .ServiceDiscovery , integration .ServiceDiscovery ) {
197208 integration .ServiceDiscovery = currentModel .ServiceDiscovery
198209 }
199- if util .IsStringPresent (currentModel .Scheme ) && ! util .AreStringPtrEqual (currentModel .Scheme , integration .Scheme ) {
200- integration .Scheme = currentModel .Scheme
201- }
202210 if currentModel .Enabled != nil && currentModel .Enabled != integration .Enabled {
203211 integration .Enabled = currentModel .Enabled
204212 }
213+
214+ if currentModel .SendUserProvidedResourceTags != nil {
215+ integration .SendUserProvidedResourceTags = currentModel .SendUserProvidedResourceTags
216+ }
205217}
206218
207219func Delete (req handler.Request , prevModel * Model , currentModel * Model ) (handler.ProgressEvent , error ) {
@@ -217,13 +229,10 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
217229 return * peErr , nil
218230 }
219231
220- var res * http.Response
221- var err error
222-
223232 ProjectID := currentModel .ProjectId
224233 IntegrationType := currentModel .Type
225234
226- _ , res , err = client .Atlas20231115002 .ThirdPartyIntegrationsApi .DeleteThirdPartyIntegration (context .Background (), * IntegrationType , * ProjectID ).Execute ()
235+ res , err : = client .AtlasSDK .ThirdPartyIntegrationsApi .DeleteGroupIntegration (context .Background (), * IntegrationType , * ProjectID ).Execute ()
227236
228237 if err != nil {
229238 return progressevent .GetFailedEventByResponse (err .Error (), res ), nil
@@ -249,39 +258,37 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
249258 return * peErr , nil
250259 }
251260
252- var res * http.Response
253261 ProjectID := currentModel .ProjectId
254- integrations , res , err := client .Atlas20231115002 .ThirdPartyIntegrationsApi .ListThirdPartyIntegrations (context .Background (), * ProjectID ).Execute ()
262+ integrations , res , err := client .AtlasSDK .ThirdPartyIntegrationsApi .ListGroupIntegrations (context .Background (), * ProjectID ).Execute ()
255263 if err != nil {
256264 return progressevent .GetFailedEventByResponse (err .Error (), res ), nil
257265 }
258266
259267 mm := make ([]interface {}, 0 )
260- for i := range integrations .Results {
261- m := integrationToModel (* currentModel , & integrations .Results [i ])
262- mm = append (mm , m )
268+ if integrations != nil {
269+ results := integrations .GetResults ()
270+ for i := range results {
271+ m := integrationToModel (* currentModel , & results [i ])
272+ mm = append (mm , m )
273+ }
263274 }
264275
265- // Response
266276 return handler.ProgressEvent {
267277 OperationStatus : handler .Success ,
268278 Message : "List successful" ,
269279 ResourceModels : mm ,
270280 }, nil
271281}
272282
273- func modelToIntegration (currentModel * Model ) (out * admin20231115002. ThridPartyIntegration ) {
274- out = & admin20231115002. ThridPartyIntegration {}
283+ func modelToIntegration (currentModel * Model ) (out * admin. ThirdPartyIntegration ) {
284+ out = & admin. ThirdPartyIntegration {}
275285
276286 if util .IsStringPresent (currentModel .Type ) {
277287 out .Type = currentModel .Type
278288 }
279289 if currentModel .Enabled != nil {
280290 out .Enabled = currentModel .Enabled
281291 }
282- if util .IsStringPresent (currentModel .Scheme ) {
283- out .Scheme = currentModel .Scheme
284- }
285292 if util .IsStringPresent (currentModel .ServiceDiscovery ) {
286293 out .ServiceDiscovery = currentModel .ServiceDiscovery
287294 }
@@ -321,25 +328,29 @@ func modelToIntegration(currentModel *Model) (out *admin20231115002.ThridPartyIn
321328 if util .IsStringPresent (currentModel .ApiKey ) {
322329 out .ApiKey = currentModel .ApiKey
323330 }
324-
331+ if currentModel .SendUserProvidedResourceTags != nil {
332+ out .SendUserProvidedResourceTags = currentModel .SendUserProvidedResourceTags
333+ }
325334 return out
326335}
327336
328- func integrationToModel (currentModel Model , integration * admin20231115002. ThridPartyIntegration ) Model {
337+ func integrationToModel (currentModel Model , integration * admin. ThirdPartyIntegration ) Model {
329338 // if "Enabled" is not set in the inputs we dont want to return "Enabled" in outputs
330339 enabled := currentModel .Enabled != nil
331340
332341 /*
333- The variables from the thirdparty integration are not returned back in reposnse because most of the variables are sensitive variables.
342+ The variables from the thirdparty integration are not returned back in response because most of the variables are sensitive variables.
334343 */
335344 out := Model {
336- Type : integration .Type ,
337- ProjectId : currentModel .ProjectId ,
338- Profile : currentModel .Profile ,
345+ Type : integration .Type ,
346+ ProjectId : currentModel .ProjectId ,
347+ Profile : currentModel .Profile ,
348+ SendUserProvidedResourceTags : currentModel .SendUserProvidedResourceTags ,
339349 }
340350
341351 if ! enabled {
342352 out .Enabled = nil
343353 }
354+
344355 return out
345356}
0 commit comments