Skip to content

Commit b0f63b9

Browse files
marcabreracastdependabot[bot]svc-apix-Botgithub-merge-queue[bot]lantoli
authored
feat: Add SendUserProvidedResourceTags to third party integrations resource (#1388)
Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: svc-apix-Bot <142542575+svc-apix-Bot@users.noreply.github.com> Co-authored-by: github-merge-queue <118344674+github-merge-queue@users.noreply.github.com> Co-authored-by: Leo Antoli <430982+lantoli@users.noreply.github.com>
1 parent b00a7ab commit b0f63b9

14 files changed

Lines changed: 124 additions & 116 deletions

TESTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ This file contains the steps to follow to test any changes to the CFN resources.
2525
```bash
2626
./../../cfn-testing-helper.sh <resource-folder>
2727
```
28+
29+
> **Note:** When creating or modifying test input files, non-string values (booleans, integers) must be defined as strings. For example, use `"Enabled": "true"` instead of `"Enabled": true`.
30+
2831
- Run cfn test
2932
```bash
3033
cd cfn-resources/[resource-folder]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Changelog
2+
3+
## 3.0.0
4+
5+
- **(Breaking Change)** Removed `Scheme` property.
6+
- Added `SendUserProvidedResourceTags` property to enable sending user-defined resource tags to third-party integrations (Datadog).

cfn-resources/third-party-integration/cmd/main.go

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cfn-resources/third-party-integration/cmd/resource/config.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cfn-resources/third-party-integration/cmd/resource/model.go

Lines changed: 20 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cfn-resources/third-party-integration/cmd/resource/resource.go

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3131
var 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

4747
func 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

207219
func 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
}

cfn-resources/third-party-integration/docs/README.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ To declare this entity in your AWS CloudFormation template, use the following sy
2828
"<a href="#username" title="UserName">UserName</a>" : <i>String</i>,
2929
"<a href="#password" title="Password">Password</a>" : <i>String</i>,
3030
"<a href="#servicediscovery" title="ServiceDiscovery">ServiceDiscovery</a>" : <i>String</i>,
31-
"<a href="#scheme" title="Scheme">Scheme</a>" : <i>String</i>,
3231
"<a href="#enabled" title="Enabled">Enabled</a>" : <i>Boolean</i>,
3332
"<a href="#listenaddress" title="ListenAddress">ListenAddress</a>" : <i>String</i>,
34-
"<a href="#tlspempath" title="TlsPemPath">TlsPemPath</a>" : <i>String</i>
33+
"<a href="#tlspempath" title="TlsPemPath">TlsPemPath</a>" : <i>String</i>,
34+
"<a href="#senduserprovidedresourcetags" title="SendUserProvidedResourceTags">SendUserProvidedResourceTags</a>" : <i>Boolean</i>
3535
}
3636
}
3737
</pre>
@@ -57,10 +57,10 @@ Properties:
5757
<a href="#username" title="UserName">UserName</a>: <i>String</i>
5858
<a href="#password" title="Password">Password</a>: <i>String</i>
5959
<a href="#servicediscovery" title="ServiceDiscovery">ServiceDiscovery</a>: <i>String</i>
60-
<a href="#scheme" title="Scheme">Scheme</a>: <i>String</i>
6160
<a href="#enabled" title="Enabled">Enabled</a>: <i>Boolean</i>
6261
<a href="#listenaddress" title="ListenAddress">ListenAddress</a>: <i>String</i>
6362
<a href="#tlspempath" title="TlsPemPath">TlsPemPath</a>: <i>String</i>
63+
<a href="#senduserprovidedresourcetags" title="SendUserProvidedResourceTags">SendUserProvidedResourceTags</a>: <i>Boolean</i>
6464
</pre>
6565

6666
## Properties
@@ -69,7 +69,7 @@ Properties:
6969

7070
Unique 24-hexadecimal digit string that identifies your project.
7171

72-
_Required_: No
72+
_Required_: Yes
7373

7474
_Type_: String
7575

@@ -89,7 +89,7 @@ _Update requires_: [Replacement](https://docs.aws.amazon.com/AWSCloudFormation/l
8989

9090
Human-readable label that identifies the service to which you want to integrate with MongoDB Cloud. The value must match the third-party service integration type.
9191

92-
_Required_: No
92+
_Required_: Yes
9393

9494
_Type_: String
9595

@@ -229,18 +229,6 @@ _Allowed Values_: <code>http</code> | <code>file</code>
229229

230230
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
231231

232-
#### Scheme
233-
234-
Security Scheme to apply to HyperText Transfer Protocol (HTTP) traffic between Prometheus and MongoDB Cloud.
235-
236-
_Required_: No
237-
238-
_Type_: String
239-
240-
_Allowed Values_: <code>http</code> | <code>https</code>
241-
242-
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
243-
244232
#### Enabled
245233

246234
Flag that indicates whether someone has activated the Prometheus integration.
@@ -271,3 +259,13 @@ _Type_: String
271259

272260
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
273261

262+
#### SendUserProvidedResourceTags
263+
264+
Flag that indicates whether to include user-defined resource tags when sending metrics and alerts to third-party services.
265+
266+
_Required_: No
267+
268+
_Type_: Boolean
269+
270+
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
271+

0 commit comments

Comments
 (0)