diff --git a/cfn-resources/third-party-integration/cmd/main.go b/cfn-resources/third-party-integration/cmd/main.go index 6d3ac4778..3618091e9 100644 --- a/cfn-resources/third-party-integration/cmd/main.go +++ b/cfn-resources/third-party-integration/cmd/main.go @@ -1,17 +1,3 @@ -// Copyright 2023 MongoDB Inc -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - // Code generated by 'cfn generate', changes will be undone by the next invocation. DO NOT EDIT. package main diff --git a/cfn-resources/third-party-integration/cmd/resource/config.go b/cfn-resources/third-party-integration/cmd/resource/config.go new file mode 100644 index 000000000..4d9eb7831 --- /dev/null +++ b/cfn-resources/third-party-integration/cmd/resource/config.go @@ -0,0 +1,19 @@ +// Code generated by 'cfn generate', changes will be undone by the next invocation. DO NOT EDIT. +// Updates to this type are made my editing the schema file and executing the 'generate' command. +package resource + +import "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" + +// TypeConfiguration is autogenerated from the json schema +type TypeConfiguration struct { +} + +// Configuration returns a resource's configuration. +func Configuration(req handler.Request) (*TypeConfiguration, error) { + // Populate the type configuration + typeConfig := &TypeConfiguration{} + if err := req.UnmarshalTypeConfig(typeConfig); err != nil { + return typeConfig, err + } + return typeConfig, nil +} diff --git a/cfn-resources/third-party-integration/cmd/resource/model.go b/cfn-resources/third-party-integration/cmd/resource/model.go index 8bfd41ac6..c40b4c1ec 100644 --- a/cfn-resources/third-party-integration/cmd/resource/model.go +++ b/cfn-resources/third-party-integration/cmd/resource/model.go @@ -1,41 +1,27 @@ -// Copyright 2023 MongoDB Inc -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - // Code generated by 'cfn generate', changes will be undone by the next invocation. DO NOT EDIT. // Updates to this type are made my editing the schema file and executing the 'generate' command. package resource // Model is autogenerated from the json schema type Model struct { - ProjectId *string `json:",omitempty"` - Profile *string `json:",omitempty"` - Type *string `json:",omitempty"` - ApiKey *string `json:",omitempty"` - Region *string `json:",omitempty"` - ServiceKey *string `json:",omitempty"` - ApiToken *string `json:",omitempty"` - TeamName *string `json:",omitempty"` - ChannelName *string `json:",omitempty"` - RoutingKey *string `json:",omitempty"` - Url *string `json:",omitempty"` - Secret *string `json:",omitempty"` - MicrosoftTeamsWebhookUrl *string `json:",omitempty"` - UserName *string `json:",omitempty"` - Password *string `json:",omitempty"` - ServiceDiscovery *string `json:",omitempty"` - Scheme *string `json:",omitempty"` - Enabled *bool `json:",omitempty"` - ListenAddress *string `json:",omitempty"` - TlsPemPath *string `json:",omitempty"` + ProjectId *string `json:",omitempty"` + Profile *string `json:",omitempty"` + Type *string `json:",omitempty"` + ApiKey *string `json:",omitempty"` + Region *string `json:",omitempty"` + ServiceKey *string `json:",omitempty"` + ApiToken *string `json:",omitempty"` + TeamName *string `json:",omitempty"` + ChannelName *string `json:",omitempty"` + RoutingKey *string `json:",omitempty"` + Url *string `json:",omitempty"` + Secret *string `json:",omitempty"` + MicrosoftTeamsWebhookUrl *string `json:",omitempty"` + UserName *string `json:",omitempty"` + Password *string `json:",omitempty"` + ServiceDiscovery *string `json:",omitempty"` + Enabled *bool `json:",omitempty"` + ListenAddress *string `json:",omitempty"` + TlsPemPath *string `json:",omitempty"` + SendUserProvidedResourceTags *bool `json:",omitempty"` } diff --git a/cfn-resources/third-party-integration/cmd/resource/resource.go b/cfn-resources/third-party-integration/cmd/resource/resource.go index ba18a2406..68041d718 100644 --- a/cfn-resources/third-party-integration/cmd/resource/resource.go +++ b/cfn-resources/third-party-integration/cmd/resource/resource.go @@ -25,7 +25,7 @@ import ( log "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - "go.mongodb.org/atlas-sdk/v20231115002/admin" + "go.mongodb.org/atlas-sdk/v20250312005/admin" ) var RequiredFields = []string{constants.IntegrationType, constants.ProjectID} @@ -41,7 +41,7 @@ var requiredPerType = map[string][]string{ "FLOWDOCK": {"FlowName", "ApiToken", "OrgName"}, "WEBHOOK": {"Url"}, "MICROSOFT_TEAMS": {"MicrosoftTeamsWebhookUrl"}, - "PROMETHEUS": {"UserName", "Password", "ServiceDiscovery", "Scheme", "Enabled"}, + "PROMETHEUS": {"UserName", "Password", "ServiceDiscovery", "Enabled"}, } func validateModel(fields []string, model *Model) *handler.ProgressEvent { @@ -76,18 +76,23 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler } requestBody := modelToIntegration(currentModel) - integrations, resModel, err := client.Atlas20231115002.ThirdPartyIntegrationsApi.CreateThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID, requestBody).Execute() + integrations, resModel, err := client.AtlasSDK.ThirdPartyIntegrationsApi.CreateThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID, requestBody).Execute() if err != nil { - if apiError, ok := admin.AsError(err); ok && *apiError.Error == http.StatusConflict { + if apiError, ok := admin.AsError(err); ok && apiError.Error == http.StatusConflict { return progressevent.GetFailedEventByCode("INTEGRATION_ALREADY_CONFIGURED.", cloudformation.HandlerErrorCodeAlreadyExists), nil } return progressevent.GetFailedEventByResponse(err.Error(), resModel), nil } + if integrations == nil || len(integrations.GetResults()) == 0 { + return progressevent.GetFailedEventByResponse("No integration returned from create", resModel), nil + } + + results := integrations.GetResults() return handler.ProgressEvent{ OperationStatus: handler.Success, - ResourceModel: integrationToModel(*currentModel, &integrations.Results[0]), + ResourceModel: integrationToModel(*currentModel, &results[0]), }, nil } @@ -108,7 +113,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P ProjectID := currentModel.ProjectId IntegrationType := currentModel.Type - integration, res, err := client.Atlas20231115002.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(context.Background(), *ProjectID, *IntegrationType).Execute() + integration, res, err := client.AtlasSDK.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(context.Background(), *ProjectID, *IntegrationType).Execute() if err != nil { return progressevent.GetFailedEventByResponse(err.Error(), res), nil @@ -139,24 +144,29 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler ProjectID := currentModel.ProjectId IntegrationType := currentModel.Type - integration, res, err := client.Atlas20231115002.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(context.Background(), *ProjectID, *IntegrationType).Execute() + integration, res, err := client.AtlasSDK.ThirdPartyIntegrationsApi.GetThirdPartyIntegration(context.Background(), *ProjectID, *IntegrationType).Execute() if err != nil { return progressevent.GetFailedEventByResponse(err.Error(), res), nil } updateIntegrationFromSchema(currentModel, integration) - integrations, res, err := client.Atlas20231115002.ThirdPartyIntegrationsApi.UpdateThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID, integration).Execute() + integrations, res, err := client.AtlasSDK.ThirdPartyIntegrationsApi.UpdateThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID, integration).Execute() if err != nil { return progressevent.GetFailedEventByResponse(err.Error(), res), nil } + if integrations == nil || len(integrations.GetResults()) == 0 { + return progressevent.GetFailedEventByResponse("No integration returned from update", res), nil + } + + results := integrations.GetResults() return handler.ProgressEvent{ OperationStatus: handler.Success, - ResourceModel: integrationToModel(*currentModel, &integrations.Results[0]), + ResourceModel: integrationToModel(*currentModel, &results[0]), }, nil } -func updateIntegrationFromSchema(currentModel *Model, integration *admin.ThridPartyIntegration) { +func updateIntegrationFromSchema(currentModel *Model, integration *admin.ThirdPartyIntegration) { if util.IsStringPresent(currentModel.Url) && !util.AreStringPtrEqual(currentModel.Url, integration.Url) { integration.Url = currentModel.Url } @@ -196,12 +206,13 @@ func updateIntegrationFromSchema(currentModel *Model, integration *admin.ThridPa if util.IsStringPresent(currentModel.ServiceDiscovery) && !util.AreStringPtrEqual(currentModel.ServiceDiscovery, integration.ServiceDiscovery) { integration.ServiceDiscovery = currentModel.ServiceDiscovery } - if util.IsStringPresent(currentModel.Scheme) && !util.AreStringPtrEqual(currentModel.Scheme, integration.Scheme) { - integration.Scheme = currentModel.Scheme - } if currentModel.Enabled != nil && currentModel.Enabled != integration.Enabled { integration.Enabled = currentModel.Enabled } + + if currentModel.SendUserProvidedResourceTags != nil { + integration.SendUserProvidedResourceTags = currentModel.SendUserProvidedResourceTags + } } func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler.ProgressEvent, error) { @@ -223,7 +234,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler ProjectID := currentModel.ProjectId IntegrationType := currentModel.Type - _, res, err = client.Atlas20231115002.ThirdPartyIntegrationsApi.DeleteThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID).Execute() + res, err = client.AtlasSDK.ThirdPartyIntegrationsApi.DeleteThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID).Execute() if err != nil { return progressevent.GetFailedEventByResponse(err.Error(), res), nil @@ -251,15 +262,18 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P var res *http.Response ProjectID := currentModel.ProjectId - integrations, res, err := client.Atlas20231115002.ThirdPartyIntegrationsApi.ListThirdPartyIntegrations(context.Background(), *ProjectID).Execute() + integrations, res, err := client.AtlasSDK.ThirdPartyIntegrationsApi.ListThirdPartyIntegrations(context.Background(), *ProjectID).Execute() if err != nil { return progressevent.GetFailedEventByResponse(err.Error(), res), nil } mm := make([]interface{}, 0) - for i := range integrations.Results { - m := integrationToModel(*currentModel, &integrations.Results[i]) - mm = append(mm, m) + if integrations != nil { + results := integrations.GetResults() + for i := range results { + m := integrationToModel(*currentModel, &results[i]) + mm = append(mm, m) + } } // Response @@ -270,8 +284,8 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P }, nil } -func modelToIntegration(currentModel *Model) (out *admin.ThridPartyIntegration) { - out = &admin.ThridPartyIntegration{} +func modelToIntegration(currentModel *Model) (out *admin.ThirdPartyIntegration) { + out = &admin.ThirdPartyIntegration{} if util.IsStringPresent(currentModel.Type) { out.Type = currentModel.Type @@ -279,9 +293,6 @@ func modelToIntegration(currentModel *Model) (out *admin.ThridPartyIntegration) if currentModel.Enabled != nil { out.Enabled = currentModel.Enabled } - if util.IsStringPresent(currentModel.Scheme) { - out.Scheme = currentModel.Scheme - } if util.IsStringPresent(currentModel.ServiceDiscovery) { out.ServiceDiscovery = currentModel.ServiceDiscovery } @@ -321,11 +332,13 @@ func modelToIntegration(currentModel *Model) (out *admin.ThridPartyIntegration) if util.IsStringPresent(currentModel.ApiKey) { out.ApiKey = currentModel.ApiKey } - + if currentModel.SendUserProvidedResourceTags != nil { + out.SendUserProvidedResourceTags = currentModel.SendUserProvidedResourceTags + } return out } -func integrationToModel(currentModel Model, integration *admin.ThridPartyIntegration) Model { +func integrationToModel(currentModel Model, integration *admin.ThirdPartyIntegration) Model { // if "Enabled" is not set in the inputs we dont want to return "Enabled" in outputs enabled := currentModel.Enabled != nil @@ -341,5 +354,6 @@ func integrationToModel(currentModel Model, integration *admin.ThridPartyIntegra if !enabled { out.Enabled = nil } + return out } diff --git a/cfn-resources/third-party-integration/docs/README.md b/cfn-resources/third-party-integration/docs/README.md index ce10026ec..01b8dce17 100644 --- a/cfn-resources/third-party-integration/docs/README.md +++ b/cfn-resources/third-party-integration/docs/README.md @@ -28,10 +28,10 @@ To declare this entity in your AWS CloudFormation template, use the following sy "UserName" : String, "Password" : String, "ServiceDiscovery" : String, - "Scheme" : String, "Enabled" : Boolean, "ListenAddress" : String, - "TlsPemPath" : String + "TlsPemPath" : String, + "SendUserProvidedResourceTags" : Boolean } } @@ -57,10 +57,10 @@ Properties: UserName: String Password: String ServiceDiscovery: String - Scheme: String Enabled: Boolean ListenAddress: String TlsPemPath: String + SendUserProvidedResourceTags: Boolean ## Properties @@ -69,7 +69,7 @@ Properties: Unique 24-hexadecimal digit string that identifies your project. -_Required_: No +_Required_: Yes _Type_: String @@ -89,7 +89,7 @@ _Update requires_: [Replacement](https://docs.aws.amazon.com/AWSCloudFormation/l 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. -_Required_: No +_Required_: Yes _Type_: String @@ -229,18 +229,6 @@ _Allowed Values_: http | file _Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) -#### Scheme - -Security Scheme to apply to HyperText Transfer Protocol (HTTP) traffic between Prometheus and MongoDB Cloud. - -_Required_: No - -_Type_: String - -_Allowed Values_: http | https - -_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) - #### Enabled Flag that indicates whether someone has activated the Prometheus integration. @@ -271,3 +259,13 @@ _Type_: String _Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) +#### SendUserProvidedResourceTags + +Flag that indicates whether to include user-defined resource tags when sending metrics and alerts to third-party services. + +_Required_: No + +_Type_: Boolean + +_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt) + diff --git a/cfn-resources/third-party-integration/mongodb-atlas-thirdpartyintegration.json b/cfn-resources/third-party-integration/mongodb-atlas-thirdpartyintegration.json index fc67e3600..3ce1e9f27 100644 --- a/cfn-resources/third-party-integration/mongodb-atlas-thirdpartyintegration.json +++ b/cfn-resources/third-party-integration/mongodb-atlas-thirdpartyintegration.json @@ -2,6 +2,10 @@ "additionalProperties": false, "definitions": {}, "description": "Returns, adds, edits, and removes third-party service integration configurations. MongoDB Cloud sends alerts to each third-party service that you configure.", + "required": [ + "ProjectId", + "Type" + ], "handlers": { "create": { "permissions": [ @@ -53,7 +57,6 @@ "/properties/MicrosoftTeamsWebhookUrl", "/properties/UserName", "/properties/ServiceDiscovery", - "/properties/Scheme", "/properties/Enabled" ], "properties": { @@ -136,14 +139,6 @@ "file" ] }, - "Scheme": { - "type": "string", - "description": "Security Scheme to apply to HyperText Transfer Protocol (HTTP) traffic between Prometheus and MongoDB Cloud.", - "enum": [ - "http", - "https" - ] - }, "Enabled": { "type": "boolean", "description": "Flag that indicates whether someone has activated the Prometheus integration." @@ -156,6 +151,10 @@ "TlsPemPath": { "type": "string", "description": "Root-relative path to the Transport Layer Security (TLS) Privacy Enhanced Mail (PEM) key and certificate file on the host." + }, + "SendUserProvidedResourceTags": { + "type": "boolean", + "description": "Flag that indicates whether to include user-defined resource tags when sending metrics and alerts to third-party services." } }, "typeName": "MongoDB::Atlas::ThirdPartyIntegration", diff --git a/cfn-resources/third-party-integration/test/inputs_1_update.template.json b/cfn-resources/third-party-integration/test/inputs_1_update.template.json index 72e6d51ee..61d7c3f1c 100644 --- a/cfn-resources/third-party-integration/test/inputs_1_update.template.json +++ b/cfn-resources/third-party-integration/test/inputs_1_update.template.json @@ -3,5 +3,6 @@ "Profile": "default", "Type": "WEBHOOK", "Url": "https://www.google.com", - "Secret": "" + "Secret": "", + "SendUserProvidedResourceTags": true } diff --git a/cfn-resources/third-party-integration/test/inputs_2_create.template.json b/cfn-resources/third-party-integration/test/inputs_2_create.template.json index a0a804dfb..7b015a412 100644 --- a/cfn-resources/third-party-integration/test/inputs_2_create.template.json +++ b/cfn-resources/third-party-integration/test/inputs_2_create.template.json @@ -3,7 +3,6 @@ "Profile": "default", "Type": "PROMETHEUS", "Enabled": true, - "Scheme": "http", "ServiceDiscovery": "http", "UserName": "", "Password": "" diff --git a/cfn-resources/third-party-integration/test/inputs_2_update.template.json b/cfn-resources/third-party-integration/test/inputs_2_update.template.json index a0a804dfb..7b015a412 100644 --- a/cfn-resources/third-party-integration/test/inputs_2_update.template.json +++ b/cfn-resources/third-party-integration/test/inputs_2_update.template.json @@ -3,7 +3,6 @@ "Profile": "default", "Type": "PROMETHEUS", "Enabled": true, - "Scheme": "http", "ServiceDiscovery": "http", "UserName": "", "Password": "" diff --git a/cfn-resources/third-party-integration/test/inputs_4_create.template.json b/cfn-resources/third-party-integration/test/inputs_4_create.template.json index ad1868615..93a8a7c60 100644 --- a/cfn-resources/third-party-integration/test/inputs_4_create.template.json +++ b/cfn-resources/third-party-integration/test/inputs_4_create.template.json @@ -3,5 +3,6 @@ "Profile": "default", "Type": "DATADOG", "ApiKey": "", - "Region": "US" + "Region": "US", + "SendUserProvidedResourceTags": false } diff --git a/cfn-resources/third-party-integration/test/inputs_4_update.template.json b/cfn-resources/third-party-integration/test/inputs_4_update.template.json index ad1868615..37b61b29e 100644 --- a/cfn-resources/third-party-integration/test/inputs_4_update.template.json +++ b/cfn-resources/third-party-integration/test/inputs_4_update.template.json @@ -3,5 +3,6 @@ "Profile": "default", "Type": "DATADOG", "ApiKey": "", - "Region": "US" + "Region": "US", + "SendUserProvidedResourceTags": true } diff --git a/cfn-resources/third-party-integration/test/thirdpartyintegration.sample-template.json b/cfn-resources/third-party-integration/test/thirdpartyintegration.sample-template.json index ab5a43c25..b1dab326a 100644 --- a/cfn-resources/third-party-integration/test/thirdpartyintegration.sample-template.json +++ b/cfn-resources/third-party-integration/test/thirdpartyintegration.sample-template.json @@ -18,7 +18,6 @@ "ProjectId": "636ca5b9ac99222b0ba4de80", "Type": "PROMETHEUS", "Enabled": "true", - "Scheme": "https", "ServiceDiscovery": "file", "UserName": "PromUser12345578", "Password": "Hello@1234" diff --git a/examples/thirdpartyintegrations/datadog.json b/examples/thirdpartyintegrations/datadog.json index f82068104..12dad1290 100644 --- a/examples/thirdpartyintegrations/datadog.json +++ b/examples/thirdpartyintegrations/datadog.json @@ -24,7 +24,8 @@ }, "Type": "DATADOG", "ApiKey": "********************************", - "Region": "US" + "Region": "US", + "SendUserProvidedResourceTags": true } } }