From 930651357b9c11763818c21fa40037839c3d2416 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Wed, 29 Oct 2025 07:09:31 +0530 Subject: [PATCH 01/22] init --- .../cmd/resource/resource.go | 22 ++++++++++--------- .../cmd/resource/resource.go | 22 ++++++++++--------- .../api-key/cmd/resource/resource.go | 13 ++++++----- .../auditing/cmd/resource/resource.go | 22 ++++++++++--------- 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/cfn-resources/access-list-api-key/cmd/resource/resource.go b/cfn-resources/access-list-api-key/cmd/resource/resource.go index d0df00061..ad8d9f99b 100644 --- a/cfn-resources/access-list-api-key/cmd/resource/resource.go +++ b/cfn-resources/access-list-api-key/cmd/resource/resource.go @@ -21,16 +21,18 @@ import ( "net/http" "strings" + admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" progress_events "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" ) var CreateRequiredFields = []string{constants.OrgID, constants.APIUserID} @@ -79,14 +81,14 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: EitherOrMessage, - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil } if currentModel.CidrBlock != nil && currentModel.IpAddress != nil { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: MutualExclusiveMessage, - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil } // createReq.ApiService. @@ -140,14 +142,14 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: EitherOrMessage, - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil } if currentModel.CidrBlock != nil && currentModel.IpAddress != nil { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: MutualExclusiveMessage, - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil } entry := getEntryAddress(currentModel) @@ -191,14 +193,14 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: EitherOrMessage, - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil } if currentModel.CidrBlock != nil && currentModel.IpAddress != nil { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: MutualExclusiveMessage, - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil } entry := getEntryAddress(currentModel) @@ -294,14 +296,14 @@ func handleError(response *http.Response, method string, err error) (handler.Pro return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errMsg, - HandlerErrorCode: cloudformation.HandlerErrorCodeInternalFailure}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInternalFailure)}, nil } if response.StatusCode == http.StatusConflict { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errMsg, - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil } return progress_events.GetFailedEventByResponse(errMsg, response), nil } diff --git a/cfn-resources/alert-configuration/cmd/resource/resource.go b/cfn-resources/alert-configuration/cmd/resource/resource.go index 7e8d1132a..6c271c2a5 100644 --- a/cfn-resources/alert-configuration/cmd/resource/resource.go +++ b/cfn-resources/alert-configuration/cmd/resource/resource.go @@ -21,17 +21,19 @@ import ( "reflect" "strings" + admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/spf13/cast" + "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" progressevents "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - "github.com/spf13/cast" - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" ) var CreateRequiredFields = []string{constants.EventTypeName, constants.ProjectID} @@ -68,12 +70,12 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource Already Exists", - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil } notifications, err := expandAlertConfigurationNotification(currentModel.Notifications) if err != nil { - return progressevents.GetFailedEventByCode(err.Error(), cloudformation.HandlerErrorCodeInvalidRequest), err + return progressevents.GetFailedEventByCode(err.Error(), string(cloudformationtypes.HandlerErrorCodeInvalidRequest)), err } alertConfigRequest := admin20231115014.GroupAlertsConfig{ @@ -125,7 +127,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource Not Found", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil } alertConfig, resp, err := atlasV2.AlertConfigurationsApi.GetAlertConfiguration(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute() @@ -165,7 +167,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource Not Found", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil } // In order to update an alert config it is necessary to send the original alert configuration request again, if not the @@ -229,7 +231,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource Not Found", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil } res, err := atlasV2.AlertConfigurationsApi.DeleteAlertConfiguration(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute() @@ -248,7 +250,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "List operation is not supported", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil } func isExist(currentModel *Model, client *admin20231115014.APIClient) bool { diff --git a/cfn-resources/api-key/cmd/resource/resource.go b/cfn-resources/api-key/cmd/resource/resource.go index 028fb73e3..3989d7c47 100644 --- a/cfn-resources/api-key/cmd/resource/resource.go +++ b/cfn-resources/api-key/cmd/resource/resource.go @@ -20,9 +20,12 @@ import ( "net/http" "sort" + admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -30,8 +33,6 @@ import ( progress_events "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/secrets" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" ) var CreateRequiredFields = []string{constants.OrgID, constants.Description, constants.AwsSecretName} @@ -285,13 +286,13 @@ func handleError(response *http.Response, method constants.CfnFunctions, err err return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errMsg, - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil } if response.StatusCode == http.StatusBadRequest { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errMsg, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil } return progress_events.GetFailedEventByResponse(errMsg, response), nil } diff --git a/cfn-resources/auditing/cmd/resource/resource.go b/cfn-resources/auditing/cmd/resource/resource.go index 6c62e12bf..e689b424b 100644 --- a/cfn-resources/auditing/cmd/resource/resource.go +++ b/cfn-resources/auditing/cmd/resource/resource.go @@ -19,15 +19,17 @@ import ( "errors" "net/http" + admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" 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" - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" ) var RequiredFields = []string{constants.ProjectID} @@ -58,9 +60,9 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return progressevent.GetFailedEventByResponse(err.Error(), res), nil } - if aws.BoolValue(atlasAuditing.Enabled) { + if aws.ToBool(atlasAuditing.Enabled) { return handler.ProgressEvent{ - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists, + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists), OperationStatus: handler.Failed, }, nil } @@ -116,9 +118,9 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return progressevent.GetFailedEventByResponse(err.Error(), res), nil } - if !aws.BoolValue(atlasAuditing.Enabled) { + if !aws.ToBool(atlasAuditing.Enabled) { return handler.ProgressEvent{ - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound, + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound), OperationStatus: handler.Failed, }, nil } @@ -156,7 +158,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler } if !resourceEnabled { return handler.ProgressEvent{ - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound, + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound), OperationStatus: handler.Failed, Message: "resource not found", }, nil @@ -222,7 +224,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler if !resourceEnabled { return handler.ProgressEvent{ - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound, + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound), OperationStatus: handler.Failed, }, nil } @@ -254,7 +256,7 @@ func isEnabled(client admin20231115014.APIClient, currentModel Model) (bool, *ha return false, &er } - return aws.BoolValue(atlasAuditing.Enabled), nil + return aws.ToBool(atlasAuditing.Enabled), nil } func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.ProgressEvent, error) { From bb8cc0b6813d53fda8eccf01749f4c4bd14ba5e0 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Wed, 29 Oct 2025 20:38:12 +0530 Subject: [PATCH 02/22] util --- cfn-resources/go.mod | 8 +++-- cfn-resources/go.sum | 11 ++++++ cfn-resources/profile/profile.go | 17 +++++++--- cfn-resources/util/aws/utils.go | 6 ++-- cfn-resources/util/cluster_common.go | 8 ++--- cfn-resources/util/deployment_secret.go | 27 ++++++++++----- .../util/progressevent/failed_event.go | 20 +++++------ cfn-resources/util/util.go | 34 +++++++++++-------- cfn-resources/util/validator/validator.go | 4 +-- 9 files changed, 84 insertions(+), 51 deletions(-) diff --git a/cfn-resources/go.mod b/cfn-resources/go.mod index 9872bf77b..4879f2feb 100644 --- a/cfn-resources/go.mod +++ b/cfn-resources/go.mod @@ -8,9 +8,11 @@ replace go.mongodb.org/atlas-sdk/v20231115014 => ../vendor/go.mongodb.org/atlas- require ( github.com/aws-cloudformation/cloudformation-cli-go-plugin v1.2.0 github.com/aws/aws-sdk-go v1.55.7 - github.com/aws/aws-sdk-go-v2 v1.39.3 + github.com/aws/aws-sdk-go-v2 v1.39.4 github.com/aws/aws-sdk-go-v2/config v1.31.14 github.com/aws/aws-sdk-go-v2/service/cloudformation v1.67.1 + github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.39.9 + github.com/aws/aws-sdk-go-v2/service/ssm v1.66.2 github.com/aws/smithy-go v1.23.1 github.com/dave/jennifer v1.7.1 github.com/getkin/kin-openapi v0.133.0 @@ -30,8 +32,8 @@ require ( github.com/aws/aws-lambda-go v1.37.0 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.18.18 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.10 // indirect - github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.10 // indirect - github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.10 // indirect + github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.11 // indirect + github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.11 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.2 // indirect github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.10 // indirect diff --git a/cfn-resources/go.sum b/cfn-resources/go.sum index cfc7765ca..ebdcf2ebe 100644 --- a/cfn-resources/go.sum +++ b/cfn-resources/go.sum @@ -6,6 +6,8 @@ github.com/aws/aws-sdk-go v1.55.7 h1:UJrkFq7es5CShfBwlWAC8DA077vp8PyVbQd3lqLiztE github.com/aws/aws-sdk-go v1.55.7/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= github.com/aws/aws-sdk-go-v2 v1.39.3 h1:h7xSsanJ4EQJXG5iuW4UqgP7qBopLpj84mpkNx3wPjM= github.com/aws/aws-sdk-go-v2 v1.39.3/go.mod h1:yWSxrnioGUZ4WVv9TgMrNUeLV3PFESn/v+6T/Su8gnM= +github.com/aws/aws-sdk-go-v2 v1.39.4 h1:qTsQKcdQPHnfGYBBs+Btl8QwxJeoWcOcPcixK90mRhg= +github.com/aws/aws-sdk-go-v2 v1.39.4/go.mod h1:yWSxrnioGUZ4WVv9TgMrNUeLV3PFESn/v+6T/Su8gnM= github.com/aws/aws-sdk-go-v2/config v1.31.14 h1:kj/KpDqvt0UqcEL3WOvCykE9QUpBb6b23hQdnXe+elo= github.com/aws/aws-sdk-go-v2/config v1.31.14/go.mod h1:X5PaY6QCzViihn/ru7VxnIamcJQrG9NSeTxuSKm2YtU= github.com/aws/aws-sdk-go-v2/credentials v1.18.18 h1:5AfxTvDN0AJoA7rg/yEc0sHhl6/B9fZ+NtiQuOjWGQM= @@ -14,8 +16,12 @@ github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.10 h1:UuGVOX48oP4vgQ36oiKmW9 github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.10/go.mod h1:vM/Ini41PzvudT4YkQyE/+WiQJiQ6jzeDyU8pQKwCac= github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.10 h1:mj/bdWleWEh81DtpdHKkw41IrS+r3uw1J/VQtbwYYp8= github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.10/go.mod h1:7+oEMxAZWP8gZCyjcm9VicI0M61Sx4DJtcGfKYv2yKQ= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.11 h1:7AANQZkF3ihM8fbdftpjhken0TP9sBzFbV/Ze/Y4HXA= +github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.11/go.mod h1:NTF4QCGkm6fzVwncpkFQqoquQyOolcyXfbpC98urj+c= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.10 h1:wh+/mn57yhUrFtLIxyFPh2RgxgQz/u+Yrf7hiHGHqKY= github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.10/go.mod h1:7zirD+ryp5gitJJ2m1BBux56ai8RIRDykXZrJSp540w= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.11 h1:ShdtWUZT37LCAA4Mw2kJAJtzaszfSHFb5n25sdcv4YE= +github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.11/go.mod h1:7bUb2sSr2MZ3M/N+VyETLTQtInemHXb/Fl3s8CLzm0Y= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 h1:WKuaxf++XKWlHWu9ECbMlha8WOEGm0OUEZqm4K/Gcfk= github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4/go.mod h1:ZWy7j6v1vWGmPReu0iSGvRiise4YI5SkR3OHKTZ6Wuc= github.com/aws/aws-sdk-go-v2/service/cloudformation v1.67.1 h1:AWeH93WCWPqgbWBv6n+yUI7DJOxhCyZJIbWniY5ZkSI= @@ -24,6 +30,11 @@ github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.2 h1:xtuxji5 github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.2/go.mod h1:zxwi0DIR0rcRcgdbl7E2MSOvxDyyXGBlScvBkARFaLQ= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.10 h1:DRND0dkCKtJzCj4Xl4OpVbXZgfttY5q712H9Zj7qc/0= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.10/go.mod h1:tGGNmJKOTernmR2+VJ0fCzQRurcPZj9ut60Zu5Fi6us= +github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.32.7/go.mod h1:BYr9P/rrcLNJ8A36nT15p8tpoVDZ5lroHuMn/njecBw= +github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.39.9 h1:SateVRwzAULF812BCR6+DZ77n8KBlbQoKNiqJvfbAII= +github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.39.9/go.mod h1:uyJVFSxMat78YTaaz+ROx+FI+K78Qa7VyEQmt8hBSWI= +github.com/aws/aws-sdk-go-v2/service/ssm v1.66.2 h1:f1d7XwtcPywunzl/2vFZ9nxumsvhCjKVaFsEy7kHQDE= +github.com/aws/aws-sdk-go-v2/service/ssm v1.66.2/go.mod h1:CpiCR+ZLofnmhb0zRIq2FxVgfKIdevx43rIENOgN1vY= github.com/aws/aws-sdk-go-v2/service/sso v1.29.7 h1:fspVFg6qMx0svs40YgRmE7LZXh9VRZvTT35PfdQR6FM= github.com/aws/aws-sdk-go-v2/service/sso v1.29.7/go.mod h1:BQTKL3uMECaLaUV3Zc2L4Qybv8C6BIXjuu1dOPyxTQs= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.2 h1:scVnW+NLXasGOhy7HhkdT9AGb6kjgW7fJ5xYkUaqHs0= diff --git a/cfn-resources/profile/profile.go b/cfn-resources/profile/profile.go index 14c564521..193b02de4 100644 --- a/cfn-resources/profile/profile.go +++ b/cfn-resources/profile/profile.go @@ -15,13 +15,16 @@ package profile import ( + "context" "encoding/json" "fmt" "os" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/secretsmanager" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/service/secretsmanager" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" ) @@ -41,18 +44,22 @@ func NewProfile(req *handler.Request, profileName *string, prefixRequired bool) profileName = aws.String(DefaultProfile) } - secretsManagerClient := secretsmanager.New(req.Session) + cfg, err := config.LoadDefaultConfig(context.Background()) + if err != nil { + return nil, err + } + secretsManagerClient := secretsmanager.NewFromConfig(cfg) secretID := *profileName if prefixRequired { secretID = SecretNameWithPrefix(*profileName) } - resp, err := secretsManagerClient.GetSecretValue(&secretsmanager.GetSecretValueInput{SecretId: &secretID}) + resp, err := secretsManagerClient.GetSecretValue(context.Background(), &secretsmanager.GetSecretValueInput{SecretId: &secretID}) if err != nil { return nil, err } profile := new(Profile) - err = json.Unmarshal([]byte(*resp.SecretString), &profile) + err = json.Unmarshal([]byte(aws.ToString(resp.SecretString)), &profile) if err != nil { return nil, err } diff --git a/cfn-resources/util/aws/utils.go b/cfn-resources/util/aws/utils.go index 4e7eec4c4..e71e9216c 100644 --- a/cfn-resources/util/aws/utils.go +++ b/cfn-resources/util/aws/utils.go @@ -19,8 +19,8 @@ import ( "strings" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" "github.com/aws/aws-sdk-go/service/ec2" progress_events "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" ) @@ -70,7 +70,7 @@ func CreatePrivateEndpoint(req handler.Request, endpointServiceName string, regi vpcE, err := svc.CreateVpcEndpoint(&connection) if err != nil { fpe := progress_events.GetFailedEventByCode(fmt.Sprintf("Error creating vcp Endpoint: %s", err.Error()), - cloudformation.HandlerErrorCodeGeneralServiceException) + string(cloudformationtypes.HandlerErrorCodeGeneralServiceException)) return nil, &fpe } @@ -101,7 +101,7 @@ func DeletePrivateEndpoint(req handler.Request, interfaceEndpoints []string, reg if err != nil { fpe := progress_events.GetFailedEventByCode(fmt.Sprintf("Error deleting vcp Endpoint: %s", err.Error()), - cloudformation.HandlerErrorCodeGeneralServiceException) + string(cloudformationtypes.HandlerErrorCodeGeneralServiceException)) return &fpe } diff --git a/cfn-resources/util/cluster_common.go b/cfn-resources/util/cluster_common.go index 28a51a2b8..36a738c3d 100644 --- a/cfn-resources/util/cluster_common.go +++ b/cfn-resources/util/cluster_common.go @@ -19,7 +19,7 @@ import ( "strings" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" ) @@ -31,13 +31,13 @@ func HandleClusterError(err error, resp *http.Response) *handler.ProgressEvent { } pe := progressevent.GetFailedEventByResponse(err.Error(), resp) if resp != nil && resp.StatusCode == http.StatusBadRequest && strings.Contains(err.Error(), constants.Duplicate) { - pe.HandlerErrorCode = cloudformation.HandlerErrorCodeAlreadyExists + pe.HandlerErrorCode = string(cloudformationtypes.HandlerErrorCodeAlreadyExists) } if resp != nil && resp.StatusCode == http.StatusNotFound { - pe.HandlerErrorCode = cloudformation.HandlerErrorCodeNotFound + pe.HandlerErrorCode = string(cloudformationtypes.HandlerErrorCodeNotFound) } if strings.Contains(err.Error(), "not exist") || strings.Contains(err.Error(), "being deleted") { - pe.HandlerErrorCode = cloudformation.HandlerErrorCodeNotFound + pe.HandlerErrorCode = string(cloudformationtypes.HandlerErrorCodeNotFound) } return &pe } diff --git a/cfn-resources/util/deployment_secret.go b/cfn-resources/util/deployment_secret.go index 103d1f08e..d989daede 100644 --- a/cfn-resources/util/deployment_secret.go +++ b/cfn-resources/util/deployment_secret.go @@ -15,13 +15,15 @@ package util import ( + "context" "encoding/json" "log" "os" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/secretsmanager" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/service/secretsmanager" ) type DeploymentSecret struct { @@ -49,16 +51,19 @@ func CreateDeploymentSecret(req *handler.Request, cfnID *ResourceIdentifier, pub // sess := credentials.SessionFromCredentialsProvider(creds) // create a new secret from this struct with the json string - // Create service client value configured for credentials - // from assumed role. - svc := secretsmanager.New(req.Session) + cfg, err := config.LoadDefaultConfig(context.Background()) + if err != nil { + log.Printf("error loading AWS config: %v", err) + return nil, err + } + svc := secretsmanager.NewFromConfig(cfg) input := &secretsmanager.CreateSecretInput{ Description: aws.String("MongoDB Atlas Quickstart Deployment Secret"), Name: aws.String(cfnID.String()), SecretString: aws.String(string(deploySecretString)), } - result, err := svc.CreateSecret(input) + result, err := svc.CreateSecret(context.Background(), input) if err != nil { // Print the error, cast err to awserr. Error to get the Code and // Message from an error. @@ -70,15 +75,19 @@ func CreateDeploymentSecret(req *handler.Request, cfnID *ResourceIdentifier, pub } func GetAPIKeyFromDeploymentSecret(req *handler.Request, secretName string) (DeploymentSecret, error) { - sm := secretsmanager.New(req.Session) - output, err := sm.GetSecretValue(&secretsmanager.GetSecretValueInput{SecretId: &secretName}) + cfg, err := config.LoadDefaultConfig(context.Background()) + if err != nil { + return DeploymentSecret{}, err + } + sm := secretsmanager.NewFromConfig(cfg) + output, err := sm.GetSecretValue(context.Background(), &secretsmanager.GetSecretValueInput{SecretId: &secretName}) if err != nil { log.Printf("Error --- %v", err.Error()) return DeploymentSecret{}, err } var key DeploymentSecret - err = json.Unmarshal([]byte(*output.SecretString), &key) + err = json.Unmarshal([]byte(aws.ToString(output.SecretString)), &key) if err != nil { log.Printf("Error --- %v", err.Error()) return key, err diff --git a/cfn-resources/util/progressevent/failed_event.go b/cfn-resources/util/progressevent/failed_event.go index d5fdeaae2..af748f342 100644 --- a/cfn-resources/util/progressevent/failed_event.go +++ b/cfn-resources/util/progressevent/failed_event.go @@ -18,21 +18,21 @@ import ( "net/http" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" ) func getHandlerErrorCode(response *http.Response) string { switch response.StatusCode { case http.StatusBadRequest: - return cloudformation.HandlerErrorCodeInvalidRequest + return string(cloudformationtypes.HandlerErrorCodeInvalidRequest) case http.StatusNotFound: - return cloudformation.HandlerErrorCodeNotFound + return string(cloudformationtypes.HandlerErrorCodeNotFound) case http.StatusInternalServerError: - return cloudformation.HandlerErrorCodeServiceInternalError + return string(cloudformationtypes.HandlerErrorCodeServiceInternalError) case http.StatusPaymentRequired, http.StatusUnauthorized: - return cloudformation.HandlerErrorCodeAccessDenied + return string(cloudformationtypes.HandlerErrorCodeAccessDenied) default: - return cloudformation.HandlerErrorCodeInternalFailure + return string(cloudformationtypes.HandlerErrorCodeInternalFailure) } } @@ -41,28 +41,28 @@ func GetFailedEventByResponse(message string, response *http.Response) handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: message, - HandlerErrorCode: cloudformation.HandlerErrorCodeHandlerInternalFailure} + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeHandlerInternalFailure)} } if response.StatusCode == http.StatusConflict { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: message, - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists} + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)} } if response.StatusCode == http.StatusUnauthorized { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Not found", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound} + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)} } if response.StatusCode == http.StatusBadRequest { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: message, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound} + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)} } return handler.ProgressEvent{ diff --git a/cfn-resources/util/util.go b/cfn-resources/util/util.go index 4930c1778..907dd7a7d 100644 --- a/cfn-resources/util/util.go +++ b/cfn-resources/util/util.go @@ -32,10 +32,10 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/logging" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" - "github.com/aws/aws-sdk-go/service/cloudformation" - "github.com/aws/aws-sdk-go/service/ssm" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/config" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/ssm" "github.com/mongodb-forks/digest" "github.com/mongodb-labs/go-client-mongodb-atlas-app-services/appservices" appServicesAuth "github.com/mongodb-labs/go-client-mongodb-atlas-app-services/auth" @@ -140,7 +140,7 @@ func newAtlasV2Client(req *handler.Request, profileName *string, profileNamePref return nil, &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound} + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)} } // setup a transport to handle digest @@ -152,7 +152,7 @@ func newAtlasV2Client(req *handler.Request, profileName *string, profileNamePref return nil, &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest} + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)} } c := Config{BaseURL: prof.BaseURL, DebugClient: prof.UseDebug()} @@ -163,7 +163,7 @@ func newAtlasV2Client(req *handler.Request, profileName *string, profileNamePref return nil, &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest} + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)} } // new V2 version 20231115014 instance @@ -172,7 +172,7 @@ func newAtlasV2Client(req *handler.Request, profileName *string, profileNamePref return nil, &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest} + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)} } // latest V2 instance @@ -181,7 +181,7 @@ func newAtlasV2Client(req *handler.Request, profileName *string, profileNamePref return nil, &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest} + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)} } clients := &MongoDBClient{ @@ -281,24 +281,28 @@ func ToStringMapE(ep any) (map[string]any, error) { return eMap, nil } -func CreateSSManagerClient(curSession *session.Session) (*ssm.SSM, error) { - ssmCli := ssm.New(curSession) +func CreateSSManagerClient(ctx context.Context) (*ssm.Client, error) { + cfg, err := config.LoadDefaultConfig(ctx) + if err != nil { + return nil, err + } + ssmCli := ssm.NewFromConfig(cfg) return ssmCli, nil } -func Get(keyID, prefix string, curSession *session.Session) string { - ssmClient, err := CreateSSManagerClient(curSession) +func Get(keyID, prefix string) string { + ssmClient, err := CreateSSManagerClient(context.Background()) if err != nil { return "" } parameterName := buildKey(keyID, prefix) decrypt := true - getParamOutput, err := ssmClient.GetParameter(&ssm.GetParameterInput{Name: ¶meterName, WithDecryption: &decrypt}) + getParamOutput, err := ssmClient.GetParameter(context.Background(), &ssm.GetParameterInput{Name: aws.String(parameterName), WithDecryption: aws.Bool(decrypt)}) if err != nil { return "" } - return *getParamOutput.Parameter.Value + return aws.ToString(getParamOutput.Parameter.Value) } func Pointer[T any](x T) *T { diff --git a/cfn-resources/util/validator/validator.go b/cfn-resources/util/validator/validator.go index 3b87b17b0..a9f2ace0c 100644 --- a/cfn-resources/util/validator/validator.go +++ b/cfn-resources/util/validator/validator.go @@ -20,7 +20,7 @@ import ( "strings" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" progressevents "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" ) @@ -37,7 +37,7 @@ func ValidateModel(fields []string, model interface{}) *handler.ProgressEvent { } progressEvent := progressevents.GetFailedEventByCode(fmt.Sprintf("The next fields are required%s", requiredFields), - cloudformation.HandlerErrorCodeInvalidRequest) + string(cloudformationtypes.HandlerErrorCodeInvalidRequest)) return &progressEvent } From b7e70b03a393f9f430655cbd157e7ed31d97c3d5 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Wed, 29 Oct 2025 23:35:14 +0530 Subject: [PATCH 03/22] c --- .../cmd/resource/resource.go | 34 ++++++++++--------- .../cmd/resource/resource.go | 30 ++++++++-------- .../cmd/resource/resource.go | 18 +++++----- .../cmd/resource/resource.go | 18 +++++----- .../cluster/cmd/resource/mappings.go | 4 +-- .../cluster/cmd/resource/resource.go | 9 +++-- .../custom-db-role/cmd/resource/resource.go | 8 +++-- .../cmd/resource/resource.go | 12 ++++--- 8 files changed, 72 insertions(+), 61 deletions(-) diff --git a/cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go b/cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go index 3b5dddaf5..516373531 100644 --- a/cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go +++ b/cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go @@ -20,14 +20,16 @@ import ( "fmt" "time" + admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" ) var CreateRequiredFields = []string{constants.SnapshotID, constants.DeliveryType, constants.InstanceType, constants.InstanceName} @@ -53,7 +55,7 @@ func validateModel(fields []string, model *Model) *handler.ProgressEvent { if *model.InstanceType != clusterInstanceType && *model.InstanceType != serverlessInstanceType { pe := progressevent.GetFailedEventByCode(fmt.Sprintf("InstanceType must be %s or %s", clusterInstanceType, serverlessInstanceType), - cloudformation.HandlerErrorCodeInvalidRequest) + string(cloudformationtypes.HandlerErrorCodeInvalidRequest)) return &pe } @@ -74,7 +76,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler err := currentModel.validateAsynchronousProperties() if err != nil { - return progressevent.GetFailedEventByCode(err.Error(), cloudformation.HandlerErrorCodeInvalidRequest), err + return progressevent.GetFailedEventByCode(err.Error(), string(cloudformationtypes.HandlerErrorCodeInvalidRequest)), err } if _, idExists := req.CallbackContext[constants.StateName]; idExists { @@ -110,7 +112,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler currentModel.Id = server.Id } - if aws.BoolValue(currentModel.EnableSynchronousCreation) { + if aws.ToBool(currentModel.EnableSynchronousCreation) { return progressevent.GetInProgressProgressEvent( "Create in progress", map[string]interface{}{ @@ -146,11 +148,11 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return *err, nil } - if aws.BoolValue(currentModel.Cancelled) { + if aws.ToBool(currentModel.Cancelled) { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "The job is in status cancelled, Cannot read a cancelled job", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil } return handler.ProgressEvent{ @@ -180,14 +182,14 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return *err, nil } - if aws.BoolValue(currentModel.Cancelled) { + if aws.ToBool(currentModel.Cancelled) { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "The job is in status cancelled, Cannot delete a cancelled job", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil } - if util.IsStringPresent(currentModel.FinishedAt) || aws.BoolValue(currentModel.Failed) || aws.BoolValue(currentModel.Expired) { + if util.IsStringPresent(currentModel.FinishedAt) || aws.ToBool(currentModel.Failed) || aws.ToBool(currentModel.Expired) { return handler.ProgressEvent{ OperationStatus: handler.Success, Message: "The resource is finished, failed, or expired", @@ -242,7 +244,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P InstanceName: currentModel.InstanceName, Profile: currentModel.Profile, } - if !aws.BoolValue(job.Cancelled) && !aws.BoolValue(job.Expired) { + if !aws.ToBool(job.Cancelled) && !aws.ToBool(job.Expired) { updateModelServerless(model, job) models = append(models, model) } @@ -262,7 +264,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P InstanceName: currentModel.InstanceName, Profile: currentModel.Profile, } - if !aws.BoolValue(job.Cancelled) && !aws.BoolValue(job.Expired) { + if !aws.ToBool(job.Cancelled) && !aws.ToBool(job.Expired) { updateModelServer(model, job) models = append(models, model) } @@ -283,11 +285,11 @@ func (model *Model) validateAsynchronousProperties() error { } if model.SynchronousCreationOptions.CallbackDelaySeconds == nil { - model.SynchronousCreationOptions.CallbackDelaySeconds = aws.Int(defaultBackSeconds) + model.SynchronousCreationOptions.CallbackDelaySeconds = util.IntPtr(defaultBackSeconds) } if model.SynchronousCreationOptions.TimeOutInSeconds == nil { - model.SynchronousCreationOptions.TimeOutInSeconds = aws.Int(defaultTimeOutInSeconds) + model.SynchronousCreationOptions.TimeOutInSeconds = util.IntPtr(defaultTimeOutInSeconds) } if model.SynchronousCreationOptions.ReturnSuccessIfTimeOut == nil { @@ -321,7 +323,7 @@ func createCallback(client *util.MongoDBClient, currentModel *Model, jobID, star } } - return progressevent.GetFailedEventByCode("Create failed with Timout", cloudformation.HandlerErrorCodeInternalFailure) + return progressevent.GetFailedEventByCode("Create failed with Timout", string(cloudformationtypes.HandlerErrorCodeInternalFailure)) } return progressevent.GetInProgressProgressEvent( diff --git a/cfn-resources/cloud-backup-schedule/cmd/resource/resource.go b/cfn-resources/cloud-backup-schedule/cmd/resource/resource.go index 47e270545..5409ed764 100644 --- a/cfn-resources/cloud-backup-schedule/cmd/resource/resource.go +++ b/cfn-resources/cloud-backup-schedule/cmd/resource/resource.go @@ -18,14 +18,16 @@ import ( "context" "errors" + admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" ) var RequiredFields = []string{constants.ProjectID, constants.ClusterName} @@ -80,11 +82,11 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler } events, _ := Read(req, prevModel, currentModel) - if events.HandlerErrorCode == cloudformation.HandlerErrorCodeNotFound { + if events.HandlerErrorCode == string(cloudformationtypes.HandlerErrorCodeNotFound) { return handler.ProgressEvent{ Message: "Not Found", OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil } return cloudBackupScheduleCreateOrUpdate(req, prevModel, currentModel) @@ -173,12 +175,12 @@ func cloudBackupScheduleCreateOrUpdate(req handler.Request, prevModel *Model, cu func validatePolicies(currentModel *Model) (pe handler.ProgressEvent, err error) { if len(currentModel.Policies) == 0 { msg := "validation error: policies cannot be empty" - return progressevent.GetFailedEventByCode(msg, cloudformation.HandlerErrorCodeInvalidRequest), errors.New(msg) + return progressevent.GetFailedEventByCode(msg, string(cloudformationtypes.HandlerErrorCodeInvalidRequest)), errors.New(msg) } for _, policy := range currentModel.Policies { if len(policy.PolicyItems) == 0 { msg := "validation error: policy items cannot be empty" - return progressevent.GetFailedEventByCode(msg, cloudformation.HandlerErrorCodeInvalidRequest), errors.New(msg) + return progressevent.GetFailedEventByCode(msg, string(cloudformationtypes.HandlerErrorCodeInvalidRequest)), errors.New(msg) } for _, policyItem := range policy.PolicyItems { if policyItem.FrequencyInterval == nil || policyItem.FrequencyType == nil || @@ -187,7 +189,7 @@ func validatePolicies(currentModel *Model) (pe handler.ProgressEvent, err error) return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, err + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, err } } } @@ -201,7 +203,7 @@ func validateExportDetails(currentModel *Model) (pe handler.ProgressEvent, err e return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, err + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, err } } return handler.ProgressEvent{}, nil @@ -214,7 +216,7 @@ func validateExist(policy *admin20231115014.DiskBackupSnapshotSchedule) *handler return &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Not Found", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound} + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)} } func (m *Model) getParams() *admin20231115014.DiskBackupSnapshotSchedule { @@ -227,7 +229,7 @@ func (m *Model) getParams() *admin20231115014.DiskBackupSnapshotSchedule { UseOrgAndGroupNamesInExportPrefix: m.UseOrgAndGroupNamesInExportPrefix, Policies: expandPolicies(m.Policies), CopySettings: expandCopySettings(m.CopySettings), - Export: expandExport(m.Export, aws.BoolValue(m.AutoExportEnabled)), + Export: expandExport(m.Export, aws.ToBool(m.AutoExportEnabled)), UpdateSnapshots: m.UpdateSnapshots, DeleteCopiedBackups: expandDeleteCopiedBackups(m.DeleteCopiedBackups), } @@ -248,7 +250,7 @@ func (m *Model) newModel(policy *admin20231115014.DiskBackupSnapshotSchedule) *M Policies: flattenPolicies(policy.Policies), Links: flattenLinks(policy.Links), CopySettings: flattenCopySettings(policy.CopySettings), - Export: flattenExport(policy.Export, aws.BoolValue(policy.AutoExportEnabled)), + Export: flattenExport(policy.Export, aws.ToBool(policy.AutoExportEnabled)), } } @@ -302,10 +304,10 @@ func expandPolicyItems(cloudPolicyItems []ApiPolicyItemView) *[]admin20231115014 for _, policyItem := range cloudPolicyItems { cPolicyItem := admin20231115014.DiskBackupApiPolicyItem{ Id: policyItem.ID, - FrequencyInterval: aws.IntValue(policyItem.FrequencyInterval), + FrequencyInterval: util.SafeInt(policyItem.FrequencyInterval), FrequencyType: util.SafeString(policyItem.FrequencyType), RetentionUnit: util.SafeString(policyItem.RetentionUnit), - RetentionValue: aws.IntValue(policyItem.RetentionValue), + RetentionValue: util.SafeInt(policyItem.RetentionValue), } policyItems = append(policyItems, cPolicyItem) } diff --git a/cfn-resources/cloud-backup-snapshot/cmd/resource/resource.go b/cfn-resources/cloud-backup-snapshot/cmd/resource/resource.go index ac1a3481f..10eb5f32a 100644 --- a/cfn-resources/cloud-backup-snapshot/cmd/resource/resource.go +++ b/cfn-resources/cloud-backup-snapshot/cmd/resource/resource.go @@ -19,14 +19,16 @@ import ( "errors" "fmt" + admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" ) const ( @@ -171,7 +173,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P models := make([]interface{}, 0) if *currentModel.InstanceType == clusterInstanceType { - server, resp, err := client.Atlas20231115002.CloudBackupsApi.ListReplicaSetBackups(aws.BackgroundContext(), *currentModel.ProjectId, *currentModel.InstanceName).Execute() + server, resp, err := client.Atlas20231115002.CloudBackupsApi.ListReplicaSetBackups(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName).Execute() if err != nil { return progressevent.GetFailedEventByResponse(err.Error(), resp), nil } @@ -186,7 +188,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P models = append(models, &model) } } else { - serverless, resp, err := client.Atlas20231115002.CloudBackupsApi.ListServerlessBackups(aws.BackgroundContext(), *currentModel.ProjectId, *currentModel.InstanceName).Execute() + serverless, resp, err := client.Atlas20231115002.CloudBackupsApi.ListServerlessBackups(context.Background(), *currentModel.ProjectId, *currentModel.InstanceName).Execute() if err != nil { return progressevent.GetFailedEventByResponse(err.Error(), resp), nil } @@ -211,7 +213,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P func validateExist(client *util.MongoDBClient, model *Model) *handler.ProgressEvent { if *model.InstanceType == clusterInstanceType { - server, resp, err := client.Atlas20231115002.CloudBackupsApi.ListReplicaSetBackups(aws.BackgroundContext(), *model.ProjectId, *model.InstanceName).Execute() + server, resp, err := client.Atlas20231115002.CloudBackupsApi.ListReplicaSetBackups(context.Background(), *model.ProjectId, *model.InstanceName).Execute() if err != nil { pe := progressevent.GetFailedEventByResponse(err.Error(), resp) return &pe @@ -222,7 +224,7 @@ func validateExist(client *util.MongoDBClient, model *Model) *handler.ProgressEv } } } else { - serverless, resp, err := client.Atlas20231115002.CloudBackupsApi.ListServerlessBackups(aws.BackgroundContext(), *model.ProjectId, *model.InstanceName).Execute() + serverless, resp, err := client.Atlas20231115002.CloudBackupsApi.ListServerlessBackups(context.Background(), *model.ProjectId, *model.InstanceName).Execute() if err != nil { pe := progressevent.GetFailedEventByResponse(err.Error(), resp) return &pe @@ -237,7 +239,7 @@ func validateExist(client *util.MongoDBClient, model *Model) *handler.ProgressEv return &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource Not Found", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound} + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)} } func validateProgress(client *util.MongoDBClient, currentModel *Model, targetState string) (handler.ProgressEvent, error) { diff --git a/cfn-resources/cluster-outage-simulation/cmd/resource/resource.go b/cfn-resources/cluster-outage-simulation/cmd/resource/resource.go index 1680012cc..6cc50c42d 100644 --- a/cfn-resources/cluster-outage-simulation/cmd/resource/resource.go +++ b/cfn-resources/cluster-outage-simulation/cmd/resource/resource.go @@ -20,17 +20,19 @@ import ( "log" "net/http" + admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/spf13/cast" + "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" progressevents "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - "github.com/spf13/cast" - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" ) const ( @@ -72,7 +74,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: constants.AlreadyExist, - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil } requestBody := admin20231115014.ClusterOutageSimulation{ @@ -131,7 +133,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: constants.ResourceNotFound, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil } convertToUIModel(*outageSimulation, currentModel) @@ -172,7 +174,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: constants.ResourceNotFound, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil } simulationObject, res, err := client.Atlas20231115014.ClusterOutageSimulationApi.EndOutageSimulation(context.Background(), projectID, clusterName).Execute() @@ -230,7 +232,7 @@ func validateProgress(client *util.MongoDBClient, currentModel *Model, targetSta return handler.ProgressEvent{ Message: err.Error(), OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeServiceInternalError}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeServiceInternalError)}, nil } if !isReady { diff --git a/cfn-resources/cluster/cmd/resource/mappings.go b/cfn-resources/cluster/cmd/resource/mappings.go index 61e931539..ae0e7a99b 100644 --- a/cfn-resources/cluster/cmd/resource/mappings.go +++ b/cfn-resources/cluster/cmd/resource/mappings.go @@ -22,7 +22,7 @@ import ( admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/spf13/cast" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" @@ -595,7 +595,7 @@ func setClusterRequest(currentModel *Model) (*admin20231115014.AdvancedClusterDe return clusterRequest, &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest, + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest), } } clusterRequest.Tags = tags diff --git a/cfn-resources/cluster/cmd/resource/resource.go b/cfn-resources/cluster/cmd/resource/resource.go index ffb0b89dc..7a0d0e2dc 100644 --- a/cfn-resources/cluster/cmd/resource/resource.go +++ b/cfn-resources/cluster/cmd/resource/resource.go @@ -22,13 +22,12 @@ import ( admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" - flex "github.com/mongodb/mongodbatlas-cloudformation-resources/flex-cluster/cmd/resource" - "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/spf13/cast" + flex "github.com/mongodb/mongodbatlas-cloudformation-resources/flex-cluster/cmd/resource" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" @@ -361,7 +360,7 @@ func validateProgress(client *util.MongoDBClient, currentModel *Model, targetSta return handler.ProgressEvent{ Message: err.Error(), OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeServiceInternalError}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeServiceInternalError)}, nil } if !isReady { diff --git a/cfn-resources/custom-db-role/cmd/resource/resource.go b/cfn-resources/custom-db-role/cmd/resource/resource.go index 611f6fcc8..e03c517e5 100644 --- a/cfn-resources/custom-db-role/cmd/resource/resource.go +++ b/cfn-resources/custom-db-role/cmd/resource/resource.go @@ -19,13 +19,15 @@ import ( "fmt" "net/http" + admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" progress_events "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" ) func setup() { @@ -58,7 +60,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler if err != nil { if apiError, ok := admin20231115002.AsError(err); ok && *apiError.Error == http.StatusConflict { return progress_events.GetFailedEventByCode("Resource already exists", - cloudformation.HandlerErrorCodeAlreadyExists), nil + string(cloudformationtypes.HandlerErrorCodeAlreadyExists)), nil } return progress_events.GetFailedEventByResponse(fmt.Sprintf("Error creating resource : %s", err.Error()), diff --git a/cfn-resources/custom-dns-configuration-cluster-aws/cmd/resource/resource.go b/cfn-resources/custom-dns-configuration-cluster-aws/cmd/resource/resource.go index c6503e8c5..9ade36a2a 100644 --- a/cfn-resources/custom-dns-configuration-cluster-aws/cmd/resource/resource.go +++ b/cfn-resources/custom-dns-configuration-cluster-aws/cmd/resource/resource.go @@ -19,13 +19,15 @@ import ( "errors" "fmt" + admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" ) var RequiredFields = []string{constants.ProjectID} @@ -50,7 +52,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler if isCustomAWSDNSSettingExists(currentModel, client) { return progressevent.GetFailedEventByCode(fmt.Sprintf("Custom AWS dns settings already enabled for : %s", *currentModel.ProjectId), - cloudformation.HandlerErrorCodeAlreadyExists), nil + string(cloudformationtypes.HandlerErrorCodeAlreadyExists)), nil } // API call to enabled := true @@ -79,7 +81,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P enabled := customAWSDNSSetting.Enabled if !enabled { return progressevent.GetFailedEventByCode(fmt.Sprintf("Custom AWS dns settings not found for Project : %s", *currentModel.ProjectId), - cloudformation.HandlerErrorCodeNotFound), nil + string(cloudformationtypes.HandlerErrorCodeNotFound)), nil } return handler.ProgressEvent{ @@ -125,7 +127,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler }, nil } return progressevent.GetFailedEventByCode(fmt.Sprintf("Error in disabling Custom AWS DNS settings for Project : %s", *currentModel.ProjectId), - cloudformation.HandlerErrorCodeNotFound), nil + string(cloudformationtypes.HandlerErrorCodeNotFound)), nil } // List handles the List event from the Cloudformation service. From 6f849a1dea13aed757038f40d1a4e83afd3eb26a Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 21 Nov 2025 16:33:11 -0500 Subject: [PATCH 04/22] deps --- cfn-resources/go.mod | 2 ++ cfn-resources/go.sum | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/cfn-resources/go.mod b/cfn-resources/go.mod index f84d1598d..9d1d304ac 100644 --- a/cfn-resources/go.mod +++ b/cfn-resources/go.mod @@ -11,6 +11,8 @@ require ( github.com/aws/aws-sdk-go-v2 v1.39.6 github.com/aws/aws-sdk-go-v2/config v1.31.20 github.com/aws/aws-sdk-go-v2/service/cloudformation v1.69.0 + github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.39.9 + github.com/aws/aws-sdk-go-v2/service/ssm v1.66.2 github.com/aws/smithy-go v1.23.2 github.com/dave/jennifer v1.7.1 github.com/getkin/kin-openapi v0.133.0 diff --git a/cfn-resources/go.sum b/cfn-resources/go.sum index 9fcebd283..7d91fb432 100644 --- a/cfn-resources/go.sum +++ b/cfn-resources/go.sum @@ -24,6 +24,10 @@ github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3 h1:x2Ibm/A github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3/go.mod h1:IW1jwyrQgMdhisceG8fQLmQIydcT/jWY21rFhzgaKwo= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.13 h1:kDqdFvMY4AtKoACfzIGD8A0+hbT41KTKF//gq7jITfM= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.13/go.mod h1:lmKuogqSU3HzQCwZ9ZtcqOc5XGMqtDK7OIc2+DxiUEg= +github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.39.9 h1:SateVRwzAULF812BCR6+DZ77n8KBlbQoKNiqJvfbAII= +github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.39.9/go.mod h1:uyJVFSxMat78YTaaz+ROx+FI+K78Qa7VyEQmt8hBSWI= +github.com/aws/aws-sdk-go-v2/service/ssm v1.66.2 h1:f1d7XwtcPywunzl/2vFZ9nxumsvhCjKVaFsEy7kHQDE= +github.com/aws/aws-sdk-go-v2/service/ssm v1.66.2/go.mod h1:CpiCR+ZLofnmhb0zRIq2FxVgfKIdevx43rIENOgN1vY= github.com/aws/aws-sdk-go-v2/service/sso v1.30.3 h1:NjShtS1t8r5LUfFVtFeI8xLAHQNTa7UI0VawXlrBMFQ= github.com/aws/aws-sdk-go-v2/service/sso v1.30.3/go.mod h1:fKvyjJcz63iL/ftA6RaM8sRCtN4r4zl4tjL3qw5ec7k= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.7 h1:gTsnx0xXNQ6SBbymoDvcoRHL+q4l/dAFsQuKfDWSaGc= From fa48c8ae2d78474d9cf51d465b7129fee2d2cd36 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 21 Nov 2025 16:42:51 -0500 Subject: [PATCH 05/22] e2e --- cfn-resources/project/cmd/resource/resource.go | 18 +++++++++--------- .../search-deployment/cmd/resource/resource.go | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cfn-resources/project/cmd/resource/resource.go b/cfn-resources/project/cmd/resource/resource.go index 36c061e69..12f22ad9d 100644 --- a/cfn-resources/project/cmd/resource/resource.go +++ b/cfn-resources/project/cmd/resource/resource.go @@ -21,7 +21,7 @@ import ( "reflect" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" @@ -86,7 +86,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler for _, key := range currentModel.ProjectApiKeys { if key.Key == nil { errorMessage := fmt.Sprintf("ApiKey is missing the configuration for projectID=%s", projectID) - return progressevent.GetFailedEventByCode(errorMessage, cloudformation.HandlerErrorCodeInvalidRequest), nil + return progressevent.GetFailedEventByCode(errorMessage, string(cloudformationtypes.HandlerErrorCodeInvalidRequest)), nil } apiKey := *key.Key _, res, err := atlasV2.ProgrammaticAPIKeysApi.UpdateApiKeyRoles(context.Background(), projectID, apiKey, &admin20231115014.UpdateAtlasProjectApiKey{ @@ -196,7 +196,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (event h return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Error while finding teams in project", - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil } if teamsAssigned != nil && teamsAssigned.Results != nil { errorMessage, err := changeProjectTeams(*atlasV2, currentModel, teamsAssigned.GetResults()) @@ -204,7 +204,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (event h return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errorMessage, - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest, + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest), }, nil } } @@ -219,7 +219,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (event h return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: fmt.Sprintf("Error while Un-assigning Key to project %s", err.Error()), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil } } @@ -231,7 +231,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (event h return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: fmt.Sprintf("Error while Assigning Key to project %s", err.Error()), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil } } @@ -243,7 +243,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (event h return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: fmt.Sprintf("Error while Assigning Key to project %s", err.Error()), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil } } } @@ -340,7 +340,7 @@ func updateProject(client *admin20231115014.APIClient, currentModel *Model) (eve if res.StatusCode == 401 { // cfn test return progressevent.GetFailedEventByCode( "Unauthorized Error: Unable to update project name. Please verify that the API keys provided in the profile have sufficient privileges to access the project.", - cloudformation.HandlerErrorCodeNotFound), nil, err + string(cloudformationtypes.HandlerErrorCodeNotFound)), nil, err } return progressevent.GetFailedEventByResponse(err.Error(), res), project, err @@ -354,7 +354,7 @@ func getProjectByID(id *string, atlasV2 *admin20231115014.APIClient) (event hand if res.StatusCode == 401 { // cfn test return progressevent.GetFailedEventByCode( "Unauthorized Error: Unable to retrieve Project by ID. Please verify that the API keys provided in the profile have sufficient privileges to access the project.", - cloudformation.HandlerErrorCodeNotFound), nil, err + string(cloudformationtypes.HandlerErrorCodeNotFound)), nil, err } return progressevent.GetFailedEventByResponse(err.Error(), res), project, err diff --git a/cfn-resources/search-deployment/cmd/resource/resource.go b/cfn-resources/search-deployment/cmd/resource/resource.go index 8fbfb20cc..a1f299d0d 100644 --- a/cfn-resources/search-deployment/cmd/resource/resource.go +++ b/cfn-resources/search-deployment/cmd/resource/resource.go @@ -21,7 +21,7 @@ import ( "strings" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" @@ -171,13 +171,13 @@ func handleError(res *http.Response, err error) (handler.ProgressEvent, error) { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil } if apiError, ok := admin20231115014.AsError(err); ok && *apiError.Error == http.StatusBadRequest && strings.Contains(*apiError.ErrorCode, SearchDeploymentDoesNotExistsError) { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil } return progressevent.GetFailedEventByResponse(err.Error(), res), nil } From 0fe18059ac12bd974b63c0b0f11dcde8096e6119 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 21 Nov 2025 16:56:20 -0500 Subject: [PATCH 06/22] fmt --- .../cmd/resource/resource.go | 18 +++++++-------- .../cmd/resource/resource.go | 14 ++++++------ .../api-key/cmd/resource/resource.go | 6 ++--- .../auditing/cmd/resource/resource.go | 10 ++++----- .../cmd/resource/resource.go | 12 +++++----- .../cmd/resource/resource.go | 16 +++++++------- .../cmd/resource/resource.go | 4 ++-- .../cmd/resource/resource.go | 10 ++++----- .../cluster/cmd/resource/mappings.go | 4 ++-- .../cluster/cmd/resource/resource.go | 4 ++-- .../custom-db-role/cmd/resource/resource.go | 4 ++-- .../cmd/resource/resource.go | 8 +++---- .../project/cmd/resource/resource.go | 22 ++++++++++--------- .../cmd/resource/resource.go | 10 +++++---- cfn-resources/util/aws/utils.go | 6 ++--- cfn-resources/util/cluster_common.go | 8 +++---- .../util/progressevent/failed_event.go | 20 ++++++++--------- cfn-resources/util/util.go | 12 +++++----- cfn-resources/util/validator/validator.go | 4 ++-- 19 files changed, 98 insertions(+), 94 deletions(-) diff --git a/cfn-resources/access-list-api-key/cmd/resource/resource.go b/cfn-resources/access-list-api-key/cmd/resource/resource.go index ad8d9f99b..0f820f48b 100644 --- a/cfn-resources/access-list-api-key/cmd/resource/resource.go +++ b/cfn-resources/access-list-api-key/cmd/resource/resource.go @@ -25,7 +25,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" @@ -81,14 +81,14 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: EitherOrMessage, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } if currentModel.CidrBlock != nil && currentModel.IpAddress != nil { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: MutualExclusiveMessage, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } // createReq.ApiService. @@ -142,14 +142,14 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: EitherOrMessage, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } if currentModel.CidrBlock != nil && currentModel.IpAddress != nil { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: MutualExclusiveMessage, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } entry := getEntryAddress(currentModel) @@ -193,14 +193,14 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: EitherOrMessage, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } if currentModel.CidrBlock != nil && currentModel.IpAddress != nil { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: MutualExclusiveMessage, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } entry := getEntryAddress(currentModel) @@ -296,14 +296,14 @@ func handleError(response *http.Response, method string, err error) (handler.Pro return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errMsg, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInternalFailure)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInternalFailure)}, nil } if response.StatusCode == http.StatusConflict { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errMsg, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil } return progress_events.GetFailedEventByResponse(errMsg, response), nil } diff --git a/cfn-resources/alert-configuration/cmd/resource/resource.go b/cfn-resources/alert-configuration/cmd/resource/resource.go index 6c271c2a5..c8e8bf691 100644 --- a/cfn-resources/alert-configuration/cmd/resource/resource.go +++ b/cfn-resources/alert-configuration/cmd/resource/resource.go @@ -25,7 +25,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/spf13/cast" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" @@ -70,12 +70,12 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource Already Exists", - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil } notifications, err := expandAlertConfigurationNotification(currentModel.Notifications) if err != nil { - return progressevents.GetFailedEventByCode(err.Error(), string(cloudformationtypes.HandlerErrorCodeInvalidRequest)), err + return progressevents.GetFailedEventByCode(err.Error(), string(types.HandlerErrorCodeInvalidRequest)), err } alertConfigRequest := admin20231115014.GroupAlertsConfig{ @@ -127,7 +127,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource Not Found", - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } alertConfig, resp, err := atlasV2.AlertConfigurationsApi.GetAlertConfiguration(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute() @@ -167,7 +167,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource Not Found", - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } // In order to update an alert config it is necessary to send the original alert configuration request again, if not the @@ -231,7 +231,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource Not Found", - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } res, err := atlasV2.AlertConfigurationsApi.DeleteAlertConfiguration(context.Background(), *currentModel.ProjectId, *currentModel.Id).Execute() @@ -250,7 +250,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "List operation is not supported", - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } func isExist(currentModel *Model, client *admin20231115014.APIClient) bool { diff --git a/cfn-resources/api-key/cmd/resource/resource.go b/cfn-resources/api-key/cmd/resource/resource.go index 3989d7c47..67cbd8630 100644 --- a/cfn-resources/api-key/cmd/resource/resource.go +++ b/cfn-resources/api-key/cmd/resource/resource.go @@ -24,7 +24,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" @@ -286,13 +286,13 @@ func handleError(response *http.Response, method constants.CfnFunctions, err err return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errMsg, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil } if response.StatusCode == http.StatusBadRequest { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errMsg, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } return progress_events.GetFailedEventByResponse(errMsg, response), nil } diff --git a/cfn-resources/auditing/cmd/resource/resource.go b/cfn-resources/auditing/cmd/resource/resource.go index e689b424b..0900652db 100644 --- a/cfn-resources/auditing/cmd/resource/resource.go +++ b/cfn-resources/auditing/cmd/resource/resource.go @@ -23,7 +23,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -62,7 +62,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler if aws.ToBool(atlasAuditing.Enabled) { return handler.ProgressEvent{ - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists), + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists), OperationStatus: handler.Failed, }, nil } @@ -120,7 +120,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P if !aws.ToBool(atlasAuditing.Enabled) { return handler.ProgressEvent{ - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound), + HandlerErrorCode: string(types.HandlerErrorCodeNotFound), OperationStatus: handler.Failed, }, nil } @@ -158,7 +158,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler } if !resourceEnabled { return handler.ProgressEvent{ - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound), + HandlerErrorCode: string(types.HandlerErrorCodeNotFound), OperationStatus: handler.Failed, Message: "resource not found", }, nil @@ -224,7 +224,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler if !resourceEnabled { return handler.ProgressEvent{ - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound), + HandlerErrorCode: string(types.HandlerErrorCodeNotFound), OperationStatus: handler.Failed, }, nil } diff --git a/cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go b/cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go index 516373531..b9bdcbb0c 100644 --- a/cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go +++ b/cfn-resources/cloud-backup-restore-jobs/cmd/resource/resource.go @@ -24,7 +24,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -55,7 +55,7 @@ func validateModel(fields []string, model *Model) *handler.ProgressEvent { if *model.InstanceType != clusterInstanceType && *model.InstanceType != serverlessInstanceType { pe := progressevent.GetFailedEventByCode(fmt.Sprintf("InstanceType must be %s or %s", clusterInstanceType, serverlessInstanceType), - string(cloudformationtypes.HandlerErrorCodeInvalidRequest)) + string(types.HandlerErrorCodeInvalidRequest)) return &pe } @@ -76,7 +76,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler err := currentModel.validateAsynchronousProperties() if err != nil { - return progressevent.GetFailedEventByCode(err.Error(), string(cloudformationtypes.HandlerErrorCodeInvalidRequest)), err + return progressevent.GetFailedEventByCode(err.Error(), string(types.HandlerErrorCodeInvalidRequest)), err } if _, idExists := req.CallbackContext[constants.StateName]; idExists { @@ -152,7 +152,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "The job is in status cancelled, Cannot read a cancelled job", - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } return handler.ProgressEvent{ @@ -186,7 +186,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "The job is in status cancelled, Cannot delete a cancelled job", - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } if util.IsStringPresent(currentModel.FinishedAt) || aws.ToBool(currentModel.Failed) || aws.ToBool(currentModel.Expired) { @@ -323,7 +323,7 @@ func createCallback(client *util.MongoDBClient, currentModel *Model, jobID, star } } - return progressevent.GetFailedEventByCode("Create failed with Timout", string(cloudformationtypes.HandlerErrorCodeInternalFailure)) + return progressevent.GetFailedEventByCode("Create failed with Timout", string(types.HandlerErrorCodeInternalFailure)) } return progressevent.GetInProgressProgressEvent( diff --git a/cfn-resources/cloud-backup-schedule/cmd/resource/resource.go b/cfn-resources/cloud-backup-schedule/cmd/resource/resource.go index 5409ed764..9afe4e2d7 100644 --- a/cfn-resources/cloud-backup-schedule/cmd/resource/resource.go +++ b/cfn-resources/cloud-backup-schedule/cmd/resource/resource.go @@ -22,7 +22,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -82,11 +82,11 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler } events, _ := Read(req, prevModel, currentModel) - if events.HandlerErrorCode == string(cloudformationtypes.HandlerErrorCodeNotFound) { + if events.HandlerErrorCode == string(types.HandlerErrorCodeNotFound) { return handler.ProgressEvent{ Message: "Not Found", OperationStatus: handler.Failed, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } return cloudBackupScheduleCreateOrUpdate(req, prevModel, currentModel) @@ -175,12 +175,12 @@ func cloudBackupScheduleCreateOrUpdate(req handler.Request, prevModel *Model, cu func validatePolicies(currentModel *Model) (pe handler.ProgressEvent, err error) { if len(currentModel.Policies) == 0 { msg := "validation error: policies cannot be empty" - return progressevent.GetFailedEventByCode(msg, string(cloudformationtypes.HandlerErrorCodeInvalidRequest)), errors.New(msg) + return progressevent.GetFailedEventByCode(msg, string(types.HandlerErrorCodeInvalidRequest)), errors.New(msg) } for _, policy := range currentModel.Policies { if len(policy.PolicyItems) == 0 { msg := "validation error: policy items cannot be empty" - return progressevent.GetFailedEventByCode(msg, string(cloudformationtypes.HandlerErrorCodeInvalidRequest)), errors.New(msg) + return progressevent.GetFailedEventByCode(msg, string(types.HandlerErrorCodeInvalidRequest)), errors.New(msg) } for _, policyItem := range policy.PolicyItems { if policyItem.FrequencyInterval == nil || policyItem.FrequencyType == nil || @@ -189,7 +189,7 @@ func validatePolicies(currentModel *Model) (pe handler.ProgressEvent, err error) return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, err + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, err } } } @@ -203,7 +203,7 @@ func validateExportDetails(currentModel *Model) (pe handler.ProgressEvent, err e return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, err + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, err } } return handler.ProgressEvent{}, nil @@ -216,7 +216,7 @@ func validateExist(policy *admin20231115014.DiskBackupSnapshotSchedule) *handler return &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Not Found", - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)} + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)} } func (m *Model) getParams() *admin20231115014.DiskBackupSnapshotSchedule { diff --git a/cfn-resources/cloud-backup-snapshot/cmd/resource/resource.go b/cfn-resources/cloud-backup-snapshot/cmd/resource/resource.go index 10eb5f32a..87d55b8aa 100644 --- a/cfn-resources/cloud-backup-snapshot/cmd/resource/resource.go +++ b/cfn-resources/cloud-backup-snapshot/cmd/resource/resource.go @@ -23,7 +23,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -239,7 +239,7 @@ func validateExist(client *util.MongoDBClient, model *Model) *handler.ProgressEv return &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource Not Found", - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)} + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)} } func validateProgress(client *util.MongoDBClient, currentModel *Model, targetState string) (handler.ProgressEvent, error) { diff --git a/cfn-resources/cluster-outage-simulation/cmd/resource/resource.go b/cfn-resources/cluster-outage-simulation/cmd/resource/resource.go index 6cc50c42d..1404447e9 100644 --- a/cfn-resources/cluster-outage-simulation/cmd/resource/resource.go +++ b/cfn-resources/cluster-outage-simulation/cmd/resource/resource.go @@ -24,7 +24,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/spf13/cast" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" @@ -74,7 +74,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: constants.AlreadyExist, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil } requestBody := admin20231115014.ClusterOutageSimulation{ @@ -133,7 +133,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: constants.ResourceNotFound, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } convertToUIModel(*outageSimulation, currentModel) @@ -174,7 +174,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: constants.ResourceNotFound, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } simulationObject, res, err := client.Atlas20231115014.ClusterOutageSimulationApi.EndOutageSimulation(context.Background(), projectID, clusterName).Execute() @@ -232,7 +232,7 @@ func validateProgress(client *util.MongoDBClient, currentModel *Model, targetSta return handler.ProgressEvent{ Message: err.Error(), OperationStatus: handler.Failed, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeServiceInternalError)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeServiceInternalError)}, nil } if !isReady { diff --git a/cfn-resources/cluster/cmd/resource/mappings.go b/cfn-resources/cluster/cmd/resource/mappings.go index ae0e7a99b..9fef9ee00 100644 --- a/cfn-resources/cluster/cmd/resource/mappings.go +++ b/cfn-resources/cluster/cmd/resource/mappings.go @@ -22,7 +22,7 @@ import ( admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/spf13/cast" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" @@ -595,7 +595,7 @@ func setClusterRequest(currentModel *Model) (*admin20231115014.AdvancedClusterDe return clusterRequest, &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest), + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest), } } clusterRequest.Tags = tags diff --git a/cfn-resources/cluster/cmd/resource/resource.go b/cfn-resources/cluster/cmd/resource/resource.go index b0771ef9a..e486448aa 100644 --- a/cfn-resources/cluster/cmd/resource/resource.go +++ b/cfn-resources/cluster/cmd/resource/resource.go @@ -24,7 +24,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/spf13/cast" flex "github.com/mongodb/mongodbatlas-cloudformation-resources/flex-cluster/cmd/resource" @@ -379,7 +379,7 @@ func validateProgress(client *util.MongoDBClient, currentModel *Model, targetSta return handler.ProgressEvent{ Message: err.Error(), OperationStatus: handler.Failed, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeServiceInternalError)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeServiceInternalError)}, nil } if !isReady { diff --git a/cfn-resources/custom-db-role/cmd/resource/resource.go b/cfn-resources/custom-db-role/cmd/resource/resource.go index e03c517e5..6325f646f 100644 --- a/cfn-resources/custom-db-role/cmd/resource/resource.go +++ b/cfn-resources/custom-db-role/cmd/resource/resource.go @@ -22,7 +22,7 @@ import ( admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -60,7 +60,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler if err != nil { if apiError, ok := admin20231115002.AsError(err); ok && *apiError.Error == http.StatusConflict { return progress_events.GetFailedEventByCode("Resource already exists", - string(cloudformationtypes.HandlerErrorCodeAlreadyExists)), nil + string(types.HandlerErrorCodeAlreadyExists)), nil } return progress_events.GetFailedEventByResponse(fmt.Sprintf("Error creating resource : %s", err.Error()), diff --git a/cfn-resources/custom-dns-configuration-cluster-aws/cmd/resource/resource.go b/cfn-resources/custom-dns-configuration-cluster-aws/cmd/resource/resource.go index 9ade36a2a..1e77a7393 100644 --- a/cfn-resources/custom-dns-configuration-cluster-aws/cmd/resource/resource.go +++ b/cfn-resources/custom-dns-configuration-cluster-aws/cmd/resource/resource.go @@ -22,7 +22,7 @@ import ( admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -52,7 +52,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler if isCustomAWSDNSSettingExists(currentModel, client) { return progressevent.GetFailedEventByCode(fmt.Sprintf("Custom AWS dns settings already enabled for : %s", *currentModel.ProjectId), - string(cloudformationtypes.HandlerErrorCodeAlreadyExists)), nil + string(types.HandlerErrorCodeAlreadyExists)), nil } // API call to enabled := true @@ -81,7 +81,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P enabled := customAWSDNSSetting.Enabled if !enabled { return progressevent.GetFailedEventByCode(fmt.Sprintf("Custom AWS dns settings not found for Project : %s", *currentModel.ProjectId), - string(cloudformationtypes.HandlerErrorCodeNotFound)), nil + string(types.HandlerErrorCodeNotFound)), nil } return handler.ProgressEvent{ @@ -127,7 +127,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler }, nil } return progressevent.GetFailedEventByCode(fmt.Sprintf("Error in disabling Custom AWS DNS settings for Project : %s", *currentModel.ProjectId), - string(cloudformationtypes.HandlerErrorCodeNotFound)), nil + string(types.HandlerErrorCodeNotFound)), nil } // List handles the List event from the Cloudformation service. diff --git a/cfn-resources/project/cmd/resource/resource.go b/cfn-resources/project/cmd/resource/resource.go index 12f22ad9d..401dbabde 100644 --- a/cfn-resources/project/cmd/resource/resource.go +++ b/cfn-resources/project/cmd/resource/resource.go @@ -20,13 +20,15 @@ import ( "fmt" "reflect" + admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" ) var CreateRequiredFields = []string{constants.OrgID, constants.Name} @@ -86,7 +88,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler for _, key := range currentModel.ProjectApiKeys { if key.Key == nil { errorMessage := fmt.Sprintf("ApiKey is missing the configuration for projectID=%s", projectID) - return progressevent.GetFailedEventByCode(errorMessage, string(cloudformationtypes.HandlerErrorCodeInvalidRequest)), nil + return progressevent.GetFailedEventByCode(errorMessage, string(types.HandlerErrorCodeInvalidRequest)), nil } apiKey := *key.Key _, res, err := atlasV2.ProgrammaticAPIKeysApi.UpdateApiKeyRoles(context.Background(), projectID, apiKey, &admin20231115014.UpdateAtlasProjectApiKey{ @@ -196,7 +198,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (event h return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Error while finding teams in project", - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } if teamsAssigned != nil && teamsAssigned.Results != nil { errorMessage, err := changeProjectTeams(*atlasV2, currentModel, teamsAssigned.GetResults()) @@ -204,7 +206,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (event h return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errorMessage, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest), + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest), }, nil } } @@ -219,7 +221,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (event h return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: fmt.Sprintf("Error while Un-assigning Key to project %s", err.Error()), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } } @@ -231,7 +233,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (event h return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: fmt.Sprintf("Error while Assigning Key to project %s", err.Error()), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } } @@ -243,7 +245,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (event h return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: fmt.Sprintf("Error while Assigning Key to project %s", err.Error()), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } } } @@ -340,7 +342,7 @@ func updateProject(client *admin20231115014.APIClient, currentModel *Model) (eve if res.StatusCode == 401 { // cfn test return progressevent.GetFailedEventByCode( "Unauthorized Error: Unable to update project name. Please verify that the API keys provided in the profile have sufficient privileges to access the project.", - string(cloudformationtypes.HandlerErrorCodeNotFound)), nil, err + string(types.HandlerErrorCodeNotFound)), nil, err } return progressevent.GetFailedEventByResponse(err.Error(), res), project, err @@ -354,7 +356,7 @@ func getProjectByID(id *string, atlasV2 *admin20231115014.APIClient) (event hand if res.StatusCode == 401 { // cfn test return progressevent.GetFailedEventByCode( "Unauthorized Error: Unable to retrieve Project by ID. Please verify that the API keys provided in the profile have sufficient privileges to access the project.", - string(cloudformationtypes.HandlerErrorCodeNotFound)), nil, err + string(types.HandlerErrorCodeNotFound)), nil, err } return progressevent.GetFailedEventByResponse(err.Error(), res), project, err diff --git a/cfn-resources/search-deployment/cmd/resource/resource.go b/cfn-resources/search-deployment/cmd/resource/resource.go index a1f299d0d..651e0b128 100644 --- a/cfn-resources/search-deployment/cmd/resource/resource.go +++ b/cfn-resources/search-deployment/cmd/resource/resource.go @@ -20,13 +20,15 @@ import ( "net/http" "strings" + admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" ) const ( @@ -171,13 +173,13 @@ func handleError(res *http.Response, err error) (handler.ProgressEvent, error) { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil } if apiError, ok := admin20231115014.AsError(err); ok && *apiError.Error == http.StatusBadRequest && strings.Contains(*apiError.ErrorCode, SearchDeploymentDoesNotExistsError) { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } return progressevent.GetFailedEventByResponse(err.Error(), res), nil } diff --git a/cfn-resources/util/aws/utils.go b/cfn-resources/util/aws/utils.go index e71e9216c..fab47b2e3 100644 --- a/cfn-resources/util/aws/utils.go +++ b/cfn-resources/util/aws/utils.go @@ -19,7 +19,7 @@ import ( "strings" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/ec2" progress_events "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" @@ -70,7 +70,7 @@ func CreatePrivateEndpoint(req handler.Request, endpointServiceName string, regi vpcE, err := svc.CreateVpcEndpoint(&connection) if err != nil { fpe := progress_events.GetFailedEventByCode(fmt.Sprintf("Error creating vcp Endpoint: %s", err.Error()), - string(cloudformationtypes.HandlerErrorCodeGeneralServiceException)) + string(types.HandlerErrorCodeGeneralServiceException)) return nil, &fpe } @@ -101,7 +101,7 @@ func DeletePrivateEndpoint(req handler.Request, interfaceEndpoints []string, reg if err != nil { fpe := progress_events.GetFailedEventByCode(fmt.Sprintf("Error deleting vcp Endpoint: %s", err.Error()), - string(cloudformationtypes.HandlerErrorCodeGeneralServiceException)) + string(types.HandlerErrorCodeGeneralServiceException)) return &fpe } diff --git a/cfn-resources/util/cluster_common.go b/cfn-resources/util/cluster_common.go index 36a738c3d..a64de9c63 100644 --- a/cfn-resources/util/cluster_common.go +++ b/cfn-resources/util/cluster_common.go @@ -19,7 +19,7 @@ import ( "strings" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" ) @@ -31,13 +31,13 @@ func HandleClusterError(err error, resp *http.Response) *handler.ProgressEvent { } pe := progressevent.GetFailedEventByResponse(err.Error(), resp) if resp != nil && resp.StatusCode == http.StatusBadRequest && strings.Contains(err.Error(), constants.Duplicate) { - pe.HandlerErrorCode = string(cloudformationtypes.HandlerErrorCodeAlreadyExists) + pe.HandlerErrorCode = string(types.HandlerErrorCodeAlreadyExists) } if resp != nil && resp.StatusCode == http.StatusNotFound { - pe.HandlerErrorCode = string(cloudformationtypes.HandlerErrorCodeNotFound) + pe.HandlerErrorCode = string(types.HandlerErrorCodeNotFound) } if strings.Contains(err.Error(), "not exist") || strings.Contains(err.Error(), "being deleted") { - pe.HandlerErrorCode = string(cloudformationtypes.HandlerErrorCodeNotFound) + pe.HandlerErrorCode = string(types.HandlerErrorCodeNotFound) } return &pe } diff --git a/cfn-resources/util/progressevent/failed_event.go b/cfn-resources/util/progressevent/failed_event.go index af748f342..adfd406de 100644 --- a/cfn-resources/util/progressevent/failed_event.go +++ b/cfn-resources/util/progressevent/failed_event.go @@ -18,21 +18,21 @@ import ( "net/http" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" ) func getHandlerErrorCode(response *http.Response) string { switch response.StatusCode { case http.StatusBadRequest: - return string(cloudformationtypes.HandlerErrorCodeInvalidRequest) + return string(types.HandlerErrorCodeInvalidRequest) case http.StatusNotFound: - return string(cloudformationtypes.HandlerErrorCodeNotFound) + return string(types.HandlerErrorCodeNotFound) case http.StatusInternalServerError: - return string(cloudformationtypes.HandlerErrorCodeServiceInternalError) + return string(types.HandlerErrorCodeServiceInternalError) case http.StatusPaymentRequired, http.StatusUnauthorized: - return string(cloudformationtypes.HandlerErrorCodeAccessDenied) + return string(types.HandlerErrorCodeAccessDenied) default: - return string(cloudformationtypes.HandlerErrorCodeInternalFailure) + return string(types.HandlerErrorCodeInternalFailure) } } @@ -41,28 +41,28 @@ func GetFailedEventByResponse(message string, response *http.Response) handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: message, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeHandlerInternalFailure)} + HandlerErrorCode: string(types.HandlerErrorCodeHandlerInternalFailure)} } if response.StatusCode == http.StatusConflict { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: message, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeAlreadyExists)} + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)} } if response.StatusCode == http.StatusUnauthorized { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Not found", - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)} + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)} } if response.StatusCode == http.StatusBadRequest { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: message, - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)} + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)} } return handler.ProgressEvent{ diff --git a/cfn-resources/util/util.go b/cfn-resources/util/util.go index 907dd7a7d..0955d8a08 100644 --- a/cfn-resources/util/util.go +++ b/cfn-resources/util/util.go @@ -34,7 +34,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/logging" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/aws/aws-sdk-go-v2/service/ssm" "github.com/mongodb-forks/digest" "github.com/mongodb-labs/go-client-mongodb-atlas-app-services/appservices" @@ -140,7 +140,7 @@ func newAtlasV2Client(req *handler.Request, profileName *string, profileNamePref return nil, &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeNotFound)} + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)} } // setup a transport to handle digest @@ -152,7 +152,7 @@ func newAtlasV2Client(req *handler.Request, profileName *string, profileNamePref return nil, &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)} + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)} } c := Config{BaseURL: prof.BaseURL, DebugClient: prof.UseDebug()} @@ -163,7 +163,7 @@ func newAtlasV2Client(req *handler.Request, profileName *string, profileNamePref return nil, &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)} + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)} } // new V2 version 20231115014 instance @@ -172,7 +172,7 @@ func newAtlasV2Client(req *handler.Request, profileName *string, profileNamePref return nil, &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)} + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)} } // latest V2 instance @@ -181,7 +181,7 @@ func newAtlasV2Client(req *handler.Request, profileName *string, profileNamePref return nil, &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: string(cloudformationtypes.HandlerErrorCodeInvalidRequest)} + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)} } clients := &MongoDBClient{ diff --git a/cfn-resources/util/validator/validator.go b/cfn-resources/util/validator/validator.go index a9f2ace0c..07ead5666 100644 --- a/cfn-resources/util/validator/validator.go +++ b/cfn-resources/util/validator/validator.go @@ -20,7 +20,7 @@ import ( "strings" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - cloudformationtypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" progressevents "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" ) @@ -37,7 +37,7 @@ func ValidateModel(fields []string, model interface{}) *handler.ProgressEvent { } progressEvent := progressevents.GetFailedEventByCode(fmt.Sprintf("The next fields are required%s", requiredFields), - string(cloudformationtypes.HandlerErrorCodeInvalidRequest)) + string(types.HandlerErrorCodeInvalidRequest)) return &progressEvent } From 3311dc3c0c6eec1b4ef3dc99140d003f0296c7db Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Fri, 21 Nov 2025 17:11:47 -0500 Subject: [PATCH 07/22] cred --- cfn-resources/profile/profile.go | 18 ++++++++++++- cfn-resources/util/deployment_secret.go | 34 ++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/cfn-resources/profile/profile.go b/cfn-resources/profile/profile.go index 193b02de4..c7d634a3d 100644 --- a/cfn-resources/profile/profile.go +++ b/cfn-resources/profile/profile.go @@ -23,6 +23,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/secretsmanager" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -44,7 +45,22 @@ func NewProfile(req *handler.Request, profileName *string, prefixRequired bool) profileName = aws.String(DefaultProfile) } - cfg, err := config.LoadDefaultConfig(context.Background()) + // Build v2 config using CFN-provided session credentials and region + credsValue, err := req.Session.Config.Credentials.Get() + if err != nil { + return nil, err + } + region := "" + if req.Session.Config.Region != nil { + region = *req.Session.Config.Region + } + cfg, err := config.LoadDefaultConfig( + context.Background(), + config.WithRegion(region), + config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider( + credsValue.AccessKeyID, credsValue.SecretAccessKey, credsValue.SessionToken, + )), + ) if err != nil { return nil, err } diff --git a/cfn-resources/util/deployment_secret.go b/cfn-resources/util/deployment_secret.go index d989daede..d36c353b5 100644 --- a/cfn-resources/util/deployment_secret.go +++ b/cfn-resources/util/deployment_secret.go @@ -23,6 +23,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" + "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/secretsmanager" ) @@ -51,9 +52,22 @@ func CreateDeploymentSecret(req *handler.Request, cfnID *ResourceIdentifier, pub // sess := credentials.SessionFromCredentialsProvider(creds) // create a new secret from this struct with the json string - cfg, err := config.LoadDefaultConfig(context.Background()) + credsValue, err := req.Session.Config.Credentials.Get() + if err != nil { + return nil, err + } + region := "" + if req.Session.Config.Region != nil { + region = *req.Session.Config.Region + } + cfg, err := config.LoadDefaultConfig( + context.Background(), + config.WithRegion(region), + config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider( + credsValue.AccessKeyID, credsValue.SecretAccessKey, credsValue.SessionToken, + )), + ) if err != nil { - log.Printf("error loading AWS config: %v", err) return nil, err } svc := secretsmanager.NewFromConfig(cfg) @@ -75,7 +89,21 @@ func CreateDeploymentSecret(req *handler.Request, cfnID *ResourceIdentifier, pub } func GetAPIKeyFromDeploymentSecret(req *handler.Request, secretName string) (DeploymentSecret, error) { - cfg, err := config.LoadDefaultConfig(context.Background()) + credsValue, err := req.Session.Config.Credentials.Get() + if err != nil { + return DeploymentSecret{}, err + } + region := "" + if req.Session.Config.Region != nil { + region = *req.Session.Config.Region + } + cfg, err := config.LoadDefaultConfig( + context.Background(), + config.WithRegion(region), + config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider( + credsValue.AccessKeyID, credsValue.SecretAccessKey, credsValue.SessionToken, + )), + ) if err != nil { return DeploymentSecret{}, err } From b3b5d0ff2e7220afda1b24f65c1ac271bfce3d1e Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Mon, 24 Nov 2025 14:42:39 -0500 Subject: [PATCH 08/22] Revert "cred" This reverts commit 3311dc3c0c6eec1b4ef3dc99140d003f0296c7db. --- cfn-resources/profile/profile.go | 18 +------------ cfn-resources/util/deployment_secret.go | 34 +++---------------------- 2 files changed, 4 insertions(+), 48 deletions(-) diff --git a/cfn-resources/profile/profile.go b/cfn-resources/profile/profile.go index c7d634a3d..193b02de4 100644 --- a/cfn-resources/profile/profile.go +++ b/cfn-resources/profile/profile.go @@ -23,7 +23,6 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" - "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/secretsmanager" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -45,22 +44,7 @@ func NewProfile(req *handler.Request, profileName *string, prefixRequired bool) profileName = aws.String(DefaultProfile) } - // Build v2 config using CFN-provided session credentials and region - credsValue, err := req.Session.Config.Credentials.Get() - if err != nil { - return nil, err - } - region := "" - if req.Session.Config.Region != nil { - region = *req.Session.Config.Region - } - cfg, err := config.LoadDefaultConfig( - context.Background(), - config.WithRegion(region), - config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider( - credsValue.AccessKeyID, credsValue.SecretAccessKey, credsValue.SessionToken, - )), - ) + cfg, err := config.LoadDefaultConfig(context.Background()) if err != nil { return nil, err } diff --git a/cfn-resources/util/deployment_secret.go b/cfn-resources/util/deployment_secret.go index d36c353b5..d989daede 100644 --- a/cfn-resources/util/deployment_secret.go +++ b/cfn-resources/util/deployment_secret.go @@ -23,7 +23,6 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" - "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/secretsmanager" ) @@ -52,22 +51,9 @@ func CreateDeploymentSecret(req *handler.Request, cfnID *ResourceIdentifier, pub // sess := credentials.SessionFromCredentialsProvider(creds) // create a new secret from this struct with the json string - credsValue, err := req.Session.Config.Credentials.Get() - if err != nil { - return nil, err - } - region := "" - if req.Session.Config.Region != nil { - region = *req.Session.Config.Region - } - cfg, err := config.LoadDefaultConfig( - context.Background(), - config.WithRegion(region), - config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider( - credsValue.AccessKeyID, credsValue.SecretAccessKey, credsValue.SessionToken, - )), - ) + cfg, err := config.LoadDefaultConfig(context.Background()) if err != nil { + log.Printf("error loading AWS config: %v", err) return nil, err } svc := secretsmanager.NewFromConfig(cfg) @@ -89,21 +75,7 @@ func CreateDeploymentSecret(req *handler.Request, cfnID *ResourceIdentifier, pub } func GetAPIKeyFromDeploymentSecret(req *handler.Request, secretName string) (DeploymentSecret, error) { - credsValue, err := req.Session.Config.Credentials.Get() - if err != nil { - return DeploymentSecret{}, err - } - region := "" - if req.Session.Config.Region != nil { - region = *req.Session.Config.Region - } - cfg, err := config.LoadDefaultConfig( - context.Background(), - config.WithRegion(region), - config.WithCredentialsProvider(credentials.NewStaticCredentialsProvider( - credsValue.AccessKeyID, credsValue.SecretAccessKey, credsValue.SessionToken, - )), - ) + cfg, err := config.LoadDefaultConfig(context.Background()) if err != nil { return DeploymentSecret{}, err } From 516b98248db556306bb8f3f0899210d86d076f28 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Mon, 24 Nov 2025 15:11:44 -0500 Subject: [PATCH 09/22] profile --- cfn-resources/profile/profile.go | 16 +++++---------- cfn-resources/util/deployment_secret.go | 27 +++++++++---------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/cfn-resources/profile/profile.go b/cfn-resources/profile/profile.go index 193b02de4..e22fa4aaf 100644 --- a/cfn-resources/profile/profile.go +++ b/cfn-resources/profile/profile.go @@ -15,15 +15,13 @@ package profile import ( - "context" "encoding/json" "fmt" "os" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/config" - "github.com/aws/aws-sdk-go-v2/service/secretsmanager" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/secretsmanager" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" ) @@ -44,22 +42,18 @@ func NewProfile(req *handler.Request, profileName *string, prefixRequired bool) profileName = aws.String(DefaultProfile) } - cfg, err := config.LoadDefaultConfig(context.Background()) - if err != nil { - return nil, err - } - secretsManagerClient := secretsmanager.NewFromConfig(cfg) + secretsManagerClient := secretsmanager.New(req.Session) secretID := *profileName if prefixRequired { secretID = SecretNameWithPrefix(*profileName) } - resp, err := secretsManagerClient.GetSecretValue(context.Background(), &secretsmanager.GetSecretValueInput{SecretId: &secretID}) + resp, err := secretsManagerClient.GetSecretValue(&secretsmanager.GetSecretValueInput{SecretId: &secretID}) if err != nil { return nil, err } profile := new(Profile) - err = json.Unmarshal([]byte(aws.ToString(resp.SecretString)), &profile) + err = json.Unmarshal([]byte(*resp.SecretString), &profile) if err != nil { return nil, err } diff --git a/cfn-resources/util/deployment_secret.go b/cfn-resources/util/deployment_secret.go index d989daede..103d1f08e 100644 --- a/cfn-resources/util/deployment_secret.go +++ b/cfn-resources/util/deployment_secret.go @@ -15,15 +15,13 @@ package util import ( - "context" "encoding/json" "log" "os" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/config" - "github.com/aws/aws-sdk-go-v2/service/secretsmanager" + "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/service/secretsmanager" ) type DeploymentSecret struct { @@ -51,19 +49,16 @@ func CreateDeploymentSecret(req *handler.Request, cfnID *ResourceIdentifier, pub // sess := credentials.SessionFromCredentialsProvider(creds) // create a new secret from this struct with the json string - cfg, err := config.LoadDefaultConfig(context.Background()) - if err != nil { - log.Printf("error loading AWS config: %v", err) - return nil, err - } - svc := secretsmanager.NewFromConfig(cfg) + // Create service client value configured for credentials + // from assumed role. + svc := secretsmanager.New(req.Session) input := &secretsmanager.CreateSecretInput{ Description: aws.String("MongoDB Atlas Quickstart Deployment Secret"), Name: aws.String(cfnID.String()), SecretString: aws.String(string(deploySecretString)), } - result, err := svc.CreateSecret(context.Background(), input) + result, err := svc.CreateSecret(input) if err != nil { // Print the error, cast err to awserr. Error to get the Code and // Message from an error. @@ -75,19 +70,15 @@ func CreateDeploymentSecret(req *handler.Request, cfnID *ResourceIdentifier, pub } func GetAPIKeyFromDeploymentSecret(req *handler.Request, secretName string) (DeploymentSecret, error) { - cfg, err := config.LoadDefaultConfig(context.Background()) - if err != nil { - return DeploymentSecret{}, err - } - sm := secretsmanager.NewFromConfig(cfg) - output, err := sm.GetSecretValue(context.Background(), &secretsmanager.GetSecretValueInput{SecretId: &secretName}) + sm := secretsmanager.New(req.Session) + output, err := sm.GetSecretValue(&secretsmanager.GetSecretValueInput{SecretId: &secretName}) if err != nil { log.Printf("Error --- %v", err.Error()) return DeploymentSecret{}, err } var key DeploymentSecret - err = json.Unmarshal([]byte(aws.ToString(output.SecretString)), &key) + err = json.Unmarshal([]byte(*output.SecretString), &key) if err != nil { log.Printf("Error --- %v", err.Error()) return key, err From 197a5e58ab595a0ae4d0372d04a406ea0127a7b4 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Mon, 24 Nov 2025 15:34:55 -0500 Subject: [PATCH 10/22] profile v2 --- cfn-resources/profile/profile.go | 14 ++++--- cfn-resources/util/awsconfig/awsconfig.go | 47 +++++++++++++++++++++++ cfn-resources/util/deployment_secret.go | 25 ++++++------ 3 files changed, 69 insertions(+), 17 deletions(-) create mode 100644 cfn-resources/util/awsconfig/awsconfig.go diff --git a/cfn-resources/profile/profile.go b/cfn-resources/profile/profile.go index e22fa4aaf..eb810af53 100644 --- a/cfn-resources/profile/profile.go +++ b/cfn-resources/profile/profile.go @@ -15,14 +15,16 @@ package profile import ( + "context" "encoding/json" "fmt" "os" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/secretsmanager" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/secretsmanager" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util/awsconfig" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" ) @@ -42,18 +44,20 @@ func NewProfile(req *handler.Request, profileName *string, prefixRequired bool) profileName = aws.String(DefaultProfile) } - secretsManagerClient := secretsmanager.New(req.Session) + // Create AWS SDK v2 config using CloudFormation handler's SDK v1 session credentials + cfg := awsconfig.FromHandlerRequest(req) + secretsManagerClient := secretsmanager.NewFromConfig(cfg) secretID := *profileName if prefixRequired { secretID = SecretNameWithPrefix(*profileName) } - resp, err := secretsManagerClient.GetSecretValue(&secretsmanager.GetSecretValueInput{SecretId: &secretID}) + resp, err := secretsManagerClient.GetSecretValue(context.Background(), &secretsmanager.GetSecretValueInput{SecretId: &secretID}) if err != nil { return nil, err } profile := new(Profile) - err = json.Unmarshal([]byte(*resp.SecretString), &profile) + err = json.Unmarshal([]byte(aws.ToString(resp.SecretString)), &profile) if err != nil { return nil, err } diff --git a/cfn-resources/util/awsconfig/awsconfig.go b/cfn-resources/util/awsconfig/awsconfig.go new file mode 100644 index 000000000..4e4023c96 --- /dev/null +++ b/cfn-resources/util/awsconfig/awsconfig.go @@ -0,0 +1,47 @@ +// 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. + +// Package awsconfig provides utilities for creating AWS SDK v2 configurations +// from CloudFormation handler requests. +package awsconfig + +import ( + "context" + "fmt" + + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" + "github.com/aws/aws-sdk-go-v2/aws" +) + +// FromHandlerRequest creates an AWS SDK v2 config using the CloudFormation handler's SDK v1 session. +// +// The cloudformation-cli-go-plugin provides credentials via handler.Request.Session, +// which is an AWS SDK v1 session. This function bridges those credentials to SDK v2 +// using a provider that fetches credentials on each AWS API call. +func FromHandlerRequest(req *handler.Request) aws.Config { + return aws.Config{ + Region: aws.ToString(req.Session.Config.Region), + Credentials: aws.CredentialsProviderFunc(func(ctx context.Context) (aws.Credentials, error) { + v1Creds, err := req.Session.Config.Credentials.Get() + if err != nil { + return aws.Credentials{}, fmt.Errorf("failed to get credentials from CloudFormation handler session: %w", err) + } + return aws.Credentials{ + AccessKeyID: v1Creds.AccessKeyID, + SecretAccessKey: v1Creds.SecretAccessKey, + SessionToken: v1Creds.SessionToken, + }, nil + }), + } +} diff --git a/cfn-resources/util/deployment_secret.go b/cfn-resources/util/deployment_secret.go index 103d1f08e..c66d8ce90 100644 --- a/cfn-resources/util/deployment_secret.go +++ b/cfn-resources/util/deployment_secret.go @@ -15,13 +15,16 @@ package util import ( + "context" "encoding/json" "log" "os" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/secretsmanager" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/secretsmanager" + + "github.com/mongodb/mongodbatlas-cloudformation-resources/util/awsconfig" ) type DeploymentSecret struct { @@ -46,19 +49,16 @@ func CreateDeploymentSecret(req *handler.Request, cfnID *ResourceIdentifier, pub log.Printf("%+v", os.Environ()) log.Println("===============================================") - // sess := credentials.SessionFromCredentialsProvider(creds) - // create a new secret from this struct with the json string - - // Create service client value configured for credentials - // from assumed role. - svc := secretsmanager.New(req.Session) + // Create service client using credentials from the CloudFormation handler's session + cfg := awsconfig.FromHandlerRequest(req) + svc := secretsmanager.NewFromConfig(cfg) input := &secretsmanager.CreateSecretInput{ Description: aws.String("MongoDB Atlas Quickstart Deployment Secret"), Name: aws.String(cfnID.String()), SecretString: aws.String(string(deploySecretString)), } - result, err := svc.CreateSecret(input) + result, err := svc.CreateSecret(context.Background(), input) if err != nil { // Print the error, cast err to awserr. Error to get the Code and // Message from an error. @@ -70,15 +70,16 @@ func CreateDeploymentSecret(req *handler.Request, cfnID *ResourceIdentifier, pub } func GetAPIKeyFromDeploymentSecret(req *handler.Request, secretName string) (DeploymentSecret, error) { - sm := secretsmanager.New(req.Session) - output, err := sm.GetSecretValue(&secretsmanager.GetSecretValueInput{SecretId: &secretName}) + cfg := awsconfig.FromHandlerRequest(req) + sm := secretsmanager.NewFromConfig(cfg) + output, err := sm.GetSecretValue(context.Background(), &secretsmanager.GetSecretValueInput{SecretId: &secretName}) if err != nil { log.Printf("Error --- %v", err.Error()) return DeploymentSecret{}, err } var key DeploymentSecret - err = json.Unmarshal([]byte(*output.SecretString), &key) + err = json.Unmarshal([]byte(aws.ToString(output.SecretString)), &key) if err != nil { log.Printf("Error --- %v", err.Error()) return key, err From 9e6405a729c5a970037179f3aa01c55ea153b615 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Mon, 24 Nov 2025 17:21:59 -0500 Subject: [PATCH 11/22] nit --- cfn-resources/profile/profile.go | 2 +- cfn-resources/util/deployment_secret.go | 2 +- cfn-resources/util/util.go | 26 ------------------------- 3 files changed, 2 insertions(+), 28 deletions(-) diff --git a/cfn-resources/profile/profile.go b/cfn-resources/profile/profile.go index eb810af53..aa06bb21f 100644 --- a/cfn-resources/profile/profile.go +++ b/cfn-resources/profile/profile.go @@ -57,7 +57,7 @@ func NewProfile(req *handler.Request, profileName *string, prefixRequired bool) } profile := new(Profile) - err = json.Unmarshal([]byte(aws.ToString(resp.SecretString)), &profile) + err = json.Unmarshal([]byte(*resp.SecretString), &profile) if err != nil { return nil, err } diff --git a/cfn-resources/util/deployment_secret.go b/cfn-resources/util/deployment_secret.go index c66d8ce90..ccff9fb7b 100644 --- a/cfn-resources/util/deployment_secret.go +++ b/cfn-resources/util/deployment_secret.go @@ -79,7 +79,7 @@ func GetAPIKeyFromDeploymentSecret(req *handler.Request, secretName string) (Dep } var key DeploymentSecret - err = json.Unmarshal([]byte(aws.ToString(output.SecretString)), &key) + err = json.Unmarshal([]byte(*output.SecretString), &key) if err != nil { log.Printf("Error --- %v", err.Error()) return key, err diff --git a/cfn-resources/util/util.go b/cfn-resources/util/util.go index 0955d8a08..40f50f30b 100644 --- a/cfn-resources/util/util.go +++ b/cfn-resources/util/util.go @@ -33,9 +33,7 @@ import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/logging" "github.com/aws/aws-sdk-go-v2/aws" - "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" - "github.com/aws/aws-sdk-go-v2/service/ssm" "github.com/mongodb-forks/digest" "github.com/mongodb-labs/go-client-mongodb-atlas-app-services/appservices" appServicesAuth "github.com/mongodb-labs/go-client-mongodb-atlas-app-services/auth" @@ -281,30 +279,6 @@ func ToStringMapE(ep any) (map[string]any, error) { return eMap, nil } -func CreateSSManagerClient(ctx context.Context) (*ssm.Client, error) { - cfg, err := config.LoadDefaultConfig(ctx) - if err != nil { - return nil, err - } - ssmCli := ssm.NewFromConfig(cfg) - return ssmCli, nil -} - -func Get(keyID, prefix string) string { - ssmClient, err := CreateSSManagerClient(context.Background()) - if err != nil { - return "" - } - parameterName := buildKey(keyID, prefix) - decrypt := true - getParamOutput, err := ssmClient.GetParameter(context.Background(), &ssm.GetParameterInput{Name: aws.String(parameterName), WithDecryption: aws.Bool(decrypt)}) - if err != nil { - return "" - } - - return aws.ToString(getParamOutput.Parameter.Value) -} - func Pointer[T any](x T) *T { return &x } From 8bb8d405febbc8ffd079338642cceb59a547a21e Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Mon, 24 Nov 2025 17:26:30 -0500 Subject: [PATCH 12/22] nit2 --- cfn-resources/online-archive/cmd/resource/resource.go | 7 +++++-- cfn-resources/organization/cmd/resource/resource.go | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cfn-resources/online-archive/cmd/resource/resource.go b/cfn-resources/online-archive/cmd/resource/resource.go index 509d5c8a5..2b45723db 100644 --- a/cfn-resources/online-archive/cmd/resource/resource.go +++ b/cfn-resources/online-archive/cmd/resource/resource.go @@ -18,15 +18,17 @@ import ( "context" "net/http" + admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/spf13/cast" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - "github.com/spf13/cast" - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" ) var CreateRequiredFields = []string{constants.ProjectID, constants.ClusterName, constants.Criteria, constants.CriteriaType} @@ -46,6 +48,7 @@ func setup() { func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler.ProgressEvent, error) { setup() + // temp test util.SetDefaultProfileIfNotDefined(¤tModel.Profile) if err := validator.ValidateModel(CreateRequiredFields, currentModel); err != nil { return *err, nil diff --git a/cfn-resources/organization/cmd/resource/resource.go b/cfn-resources/organization/cmd/resource/resource.go index f170d868d..722e96161 100644 --- a/cfn-resources/organization/cmd/resource/resource.go +++ b/cfn-resources/organization/cmd/resource/resource.go @@ -44,6 +44,7 @@ const ( DeletingState = "Deleting" DeleteInProgress = "Delete Organization is in progress" DeleteCompleted = "Delete Organization is completed" + // temp test ) type OrgProfile struct { From 2b2886332eb02444afcd8b0cf6f059beee5c57a6 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Mon, 24 Nov 2025 17:34:46 -0500 Subject: [PATCH 13/22] oa --- cfn-resources/online-archive/test/cfn-test-create-inputs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cfn-resources/online-archive/test/cfn-test-create-inputs.sh b/cfn-resources/online-archive/test/cfn-test-create-inputs.sh index 4dd01a4dc..c36c141ab 100755 --- a/cfn-resources/online-archive/test/cfn-test-create-inputs.sh +++ b/cfn-resources/online-archive/test/cfn-test-create-inputs.sh @@ -33,7 +33,7 @@ echo -e "=====\nrun this command to clean up\n=====\nmongocli iam projects delet ClusterName="${projectName}" # shellcheck disable=SC2086 -atlas clusters create "${ClusterName}" --projectId ${projectId} --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --mdbVersion 5.0 --diskSizeGB 10 --output=json +atlas clusters create "${ClusterName}" --projectId ${projectId} --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --diskSizeGB 10 --output=json atlas clusters watch "${ClusterName}" --projectId "${projectId}" echo -e "Created Cluster \"${ClusterName}\"" From d7ad5a305e2ec6f466d408b8ca633a7d19b70a19 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Mon, 24 Nov 2025 18:06:44 -0500 Subject: [PATCH 14/22] lint --- cfn-resources/project/cmd/resource/resource.go | 4 ++-- cfn-resources/util/util.go | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/cfn-resources/project/cmd/resource/resource.go b/cfn-resources/project/cmd/resource/resource.go index 401dbabde..f64351366 100644 --- a/cfn-resources/project/cmd/resource/resource.go +++ b/cfn-resources/project/cmd/resource/resource.go @@ -339,7 +339,7 @@ func updateProject(client *admin20231115014.APIClient, currentModel *Model) (eve } project, res, err := client.ProjectsApi.UpdateProject(context.Background(), *currentModel.Id, &projectUpdate).Execute() if err != nil { - if res.StatusCode == 401 { // cfn test + if res != nil && res.StatusCode == 401 { // cfn test return progressevent.GetFailedEventByCode( "Unauthorized Error: Unable to update project name. Please verify that the API keys provided in the profile have sufficient privileges to access the project.", string(types.HandlerErrorCodeNotFound)), nil, err @@ -353,7 +353,7 @@ func updateProject(client *admin20231115014.APIClient, currentModel *Model) (eve func getProjectByID(id *string, atlasV2 *admin20231115014.APIClient) (event handler.ProgressEvent, model *admin20231115014.Group, err error) { project, res, err := atlasV2.ProjectsApi.GetProject(context.Background(), *id).Execute() if err != nil { - if res.StatusCode == 401 { // cfn test + if res != nil && res.StatusCode == 401 { // cfn test return progressevent.GetFailedEventByCode( "Unauthorized Error: Unable to retrieve Project by ID. Please verify that the API keys provided in the profile have sufficient privileges to access the project.", string(types.HandlerErrorCodeNotFound)), nil, err diff --git a/cfn-resources/util/util.go b/cfn-resources/util/util.go index 40f50f30b..3836663e1 100644 --- a/cfn-resources/util/util.go +++ b/cfn-resources/util/util.go @@ -283,12 +283,6 @@ func Pointer[T any](x T) *T { return &x } -func buildKey(keyID, storePrefix string) string { - // this is strictly coupled with permissions for handlers, changing this means changing permissions in handler - // moreover changing this might cause pollution in parameter store - be sure you know what you are doing - return fmt.Sprintf("%s-%s", storePrefix, keyID) -} - // Contains checks if a string is present in a slice func Contains(s []string, str string) bool { for _, v := range s { From 139142f8571ac199f6af7ce74f5652c9de812062 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Mon, 24 Nov 2025 18:13:15 -0500 Subject: [PATCH 15/22] lint From d11c6d8b3e4efd92ce54c027099d27e3e71fd9ac Mon Sep 17 00:00:00 2001 From: maastha <122359335+maastha@users.noreply.github.com> Date: Mon, 24 Nov 2025 18:13:54 -0500 Subject: [PATCH 16/22] Delete cfn-resources/private-endpoint-adl/mongodb-atlas-privateendpointadl.json --- .../private-endpoint-adl/mongodb-atlas-privateendpointadl.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 cfn-resources/private-endpoint-adl/mongodb-atlas-privateendpointadl.json diff --git a/cfn-resources/private-endpoint-adl/mongodb-atlas-privateendpointadl.json b/cfn-resources/private-endpoint-adl/mongodb-atlas-privateendpointadl.json deleted file mode 100644 index 8b1378917..000000000 --- a/cfn-resources/private-endpoint-adl/mongodb-atlas-privateendpointadl.json +++ /dev/null @@ -1 +0,0 @@ - From 74521b7545c97f5a47aba698d2076677a141c9c5 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Mon, 24 Nov 2025 18:17:13 -0500 Subject: [PATCH 17/22] nit --- cfn-resources/online-archive/cmd/resource/resource.go | 1 - cfn-resources/online-archive/test/cfn-test-create-inputs.sh | 2 +- cfn-resources/organization/cmd/resource/resource.go | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/cfn-resources/online-archive/cmd/resource/resource.go b/cfn-resources/online-archive/cmd/resource/resource.go index 2b45723db..66062414b 100644 --- a/cfn-resources/online-archive/cmd/resource/resource.go +++ b/cfn-resources/online-archive/cmd/resource/resource.go @@ -48,7 +48,6 @@ func setup() { func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler.ProgressEvent, error) { setup() - // temp test util.SetDefaultProfileIfNotDefined(¤tModel.Profile) if err := validator.ValidateModel(CreateRequiredFields, currentModel); err != nil { return *err, nil diff --git a/cfn-resources/online-archive/test/cfn-test-create-inputs.sh b/cfn-resources/online-archive/test/cfn-test-create-inputs.sh index c36c141ab..4dd01a4dc 100755 --- a/cfn-resources/online-archive/test/cfn-test-create-inputs.sh +++ b/cfn-resources/online-archive/test/cfn-test-create-inputs.sh @@ -33,7 +33,7 @@ echo -e "=====\nrun this command to clean up\n=====\nmongocli iam projects delet ClusterName="${projectName}" # shellcheck disable=SC2086 -atlas clusters create "${ClusterName}" --projectId ${projectId} --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --diskSizeGB 10 --output=json +atlas clusters create "${ClusterName}" --projectId ${projectId} --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --mdbVersion 5.0 --diskSizeGB 10 --output=json atlas clusters watch "${ClusterName}" --projectId "${projectId}" echo -e "Created Cluster \"${ClusterName}\"" diff --git a/cfn-resources/organization/cmd/resource/resource.go b/cfn-resources/organization/cmd/resource/resource.go index 722e96161..f170d868d 100644 --- a/cfn-resources/organization/cmd/resource/resource.go +++ b/cfn-resources/organization/cmd/resource/resource.go @@ -44,7 +44,6 @@ const ( DeletingState = "Deleting" DeleteInProgress = "Delete Organization is in progress" DeleteCompleted = "Delete Organization is completed" - // temp test ) type OrgProfile struct { From e2f197bc34cfde389d8d8f471a89b0567a3f8df0 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Tue, 25 Nov 2025 08:31:56 -0500 Subject: [PATCH 18/22] nit --- cfn-resources/online-archive/cmd/resource/resource.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cfn-resources/online-archive/cmd/resource/resource.go b/cfn-resources/online-archive/cmd/resource/resource.go index 66062414b..509d5c8a5 100644 --- a/cfn-resources/online-archive/cmd/resource/resource.go +++ b/cfn-resources/online-archive/cmd/resource/resource.go @@ -18,17 +18,15 @@ import ( "context" "net/http" - admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" - "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/cloudformation" - "github.com/spf13/cast" - "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" + "github.com/spf13/cast" + admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin" ) var CreateRequiredFields = []string{constants.ProjectID, constants.ClusterName, constants.Criteria, constants.CriteriaType} From b29f76c17c51ca918dbb0998cd11ac6891463057 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Tue, 25 Nov 2025 23:21:21 +0100 Subject: [PATCH 19/22] nit --- cfn-resources/go.mod | 1 - 1 file changed, 1 deletion(-) diff --git a/cfn-resources/go.mod b/cfn-resources/go.mod index 976ff9ba5..f90d04975 100644 --- a/cfn-resources/go.mod +++ b/cfn-resources/go.mod @@ -12,7 +12,6 @@ require ( github.com/aws/aws-sdk-go-v2/config v1.32.1 github.com/aws/aws-sdk-go-v2/service/cloudformation v1.69.0 github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.39.9 - github.com/aws/aws-sdk-go-v2/service/ssm v1.66.2 github.com/aws/smithy-go v1.23.2 github.com/dave/jennifer v1.7.1 github.com/getkin/kin-openapi v0.133.0 From 9bdce5c816c005e1c1154e1a311a3c0385397a91 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Wed, 26 Nov 2025 00:11:48 +0100 Subject: [PATCH 20/22] d to m --- .../database-user/cmd/resource/resource.go | 8 ++++---- .../cmd/resource/resource.go | 12 +++++++----- .../cmd/resource/resource.go | 8 ++++---- .../cmd/resource/resource.go | 10 +++++----- .../cmd/resource/resource.go | 14 ++++++++------ .../cmd/resource/resource.go | 18 +++++++++--------- .../cmd/resource/resource.go | 8 ++++---- .../cmd/resource/resource.go | 8 ++++---- 8 files changed, 45 insertions(+), 41 deletions(-) diff --git a/cfn-resources/database-user/cmd/resource/resource.go b/cfn-resources/database-user/cmd/resource/resource.go index 661be4ff8..6b3b2d0a7 100644 --- a/cfn-resources/database-user/cmd/resource/resource.go +++ b/cfn-resources/database-user/cmd/resource/resource.go @@ -19,8 +19,8 @@ import ( "fmt" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" @@ -63,7 +63,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: fmt.Sprintf("Error Creating resource: %s", err.Error()), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } groupID := *currentModel.ProjectId @@ -172,7 +172,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: fmt.Sprintf("Error Creating resource: %s", err.Error()), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } groupID := *currentModel.ProjectId diff --git a/cfn-resources/encryption-at-rest/cmd/resource/resource.go b/cfn-resources/encryption-at-rest/cmd/resource/resource.go index 0543f88f5..796ff9945 100644 --- a/cfn-resources/encryption-at-rest/cmd/resource/resource.go +++ b/cfn-resources/encryption-at-rest/cmd/resource/resource.go @@ -22,14 +22,16 @@ import ( "math/big" "strconv" + admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" ) var ( @@ -174,13 +176,13 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P } func validateExist(info *admin20231115002.EncryptionAtRest) *handler.ProgressEvent { - if info != nil && info.AwsKms != nil && aws.BoolValue(info.AwsKms.Enabled) { + if info != nil && info.AwsKms != nil && aws.ToBool(info.AwsKms.Enabled) { return nil } return &handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource Not Found", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound} + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)} } func randInt64() int64 { diff --git a/cfn-resources/federated-database-instance/cmd/resource/resource.go b/cfn-resources/federated-database-instance/cmd/resource/resource.go index d8fee7fc6..b19c079da 100644 --- a/cfn-resources/federated-database-instance/cmd/resource/resource.go +++ b/cfn-resources/federated-database-instance/cmd/resource/resource.go @@ -20,8 +20,8 @@ import ( "net/http" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -231,13 +231,13 @@ func handleError(response *http.Response, method string, err error) (handler.Pro return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: fmt.Sprintf("%s:%s", method, err.Error()), - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil } if response.StatusCode == http.StatusNotFound { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: fmt.Sprintf("%s:%s", method, err.Error()), - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } return progress_events.GetFailedEventByResponse(fmt.Sprintf("Error during execution : %s", err.Error()), diff --git a/cfn-resources/federated-query-limit/cmd/resource/resource.go b/cfn-resources/federated-query-limit/cmd/resource/resource.go index 2ccca8870..a7cf3c7e9 100644 --- a/cfn-resources/federated-query-limit/cmd/resource/resource.go +++ b/cfn-resources/federated-query-limit/cmd/resource/resource.go @@ -20,8 +20,8 @@ import ( "net/http" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -74,7 +74,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: AlreadyExists, - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil } // create and update uses same PATCH API return createOrUpdateQueryLimit(currentModel, atlas, CREATE) @@ -136,7 +136,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: DoesntExists, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } return createOrUpdateQueryLimit(currentModel, atlas, UPDATE) } @@ -224,7 +224,7 @@ func handleError(response *http.Response, method string, err error) (handler.Pro return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errMsg, - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil } return progress_events.GetFailedEventByResponse(errMsg, response), nil } diff --git a/cfn-resources/federated-settings-org-role-mapping/cmd/resource/resource.go b/cfn-resources/federated-settings-org-role-mapping/cmd/resource/resource.go index 47f0d4b7f..97180b0d0 100644 --- a/cfn-resources/federated-settings-org-role-mapping/cmd/resource/resource.go +++ b/cfn-resources/federated-settings-org-role-mapping/cmd/resource/resource.go @@ -21,13 +21,15 @@ import ( "net/http" "strings" + admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" ) var CreateRequiredFields = []string{constants.FederationSettingsID, constants.OrgID, constants.ExternalGroupName, constants.RoleAssignments} @@ -70,7 +72,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler if err != nil { if resp.StatusCode == http.StatusBadRequest && strings.Contains(err.Error(), "DUPLICATE_ROLE_MAPPING") { return progressevent.GetFailedEventByCode("Resource already exists", - cloudformation.HandlerErrorCodeAlreadyExists), nil + string(types.HandlerErrorCodeAlreadyExists)), nil } return progressevent.GetFailedEventByResponse(fmt.Sprintf("Error getting resource : %s", err.Error()), resp), nil @@ -132,7 +134,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler roleMappingID := currentModel.Id if !isRoleMappingExists(currentModel, client) { - return progressevent.GetFailedEventByCode("Not Found", cloudformation.HandlerErrorCodeNotFound), nil + return progressevent.GetFailedEventByCode("Not Found", string(types.HandlerErrorCodeNotFound)), nil } if (currentModel.RoleAssignments) == nil || len(currentModel.RoleAssignments) == 0 { @@ -140,7 +142,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } // preparing model request requestBody, _, _ := modelToRoleMappingRequest(currentModel) @@ -175,7 +177,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler // Check if already exist if !isRoleMappingExists(currentModel, client) { - return progressevent.GetFailedEventByCode("Not Found", cloudformation.HandlerErrorCodeNotFound), nil + return progressevent.GetFailedEventByCode("Not Found", string(types.HandlerErrorCodeNotFound)), nil } federationSettingsID := currentModel.FederationSettingsId diff --git a/cfn-resources/global-cluster-config/cmd/resource/resource.go b/cfn-resources/global-cluster-config/cmd/resource/resource.go index 3772e0c64..71de7a58e 100644 --- a/cfn-resources/global-cluster-config/cmd/resource/resource.go +++ b/cfn-resources/global-cluster-config/cmd/resource/resource.go @@ -21,7 +21,7 @@ import ( "net/http" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" @@ -57,7 +57,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeServiceInternalError, + HandlerErrorCode: string(types.HandlerErrorCodeServiceInternalError), }, nil } @@ -66,7 +66,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeServiceInternalError, + HandlerErrorCode: string(types.HandlerErrorCodeServiceInternalError), }, nil } @@ -94,7 +94,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P config, event, err := ReadConfig(client, currentModel) if err != nil { if config == nil { - return progressevent.GetFailedEventByCode("Resource Not Found", cloudformation.HandlerErrorCodeNotFound), nil + return progressevent.GetFailedEventByCode("Resource Not Found", string(types.HandlerErrorCodeNotFound)), nil } return event, nil @@ -116,7 +116,7 @@ func ReadConfig(client *util.MongoDBClient, currentModel *Model) (*Model, handle return nil, handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } return nil, progressevent.GetFailedEventByResponse(fmt.Sprintf("Failed to fetch managed namespace : %s", err.Error()), @@ -129,7 +129,7 @@ func ReadConfig(client *util.MongoDBClient, currentModel *Model) (*Model, handle return nil, handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "resource Not Found", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, errors.New("resource not found") + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, errors.New("resource not found") } readModel := newModel(globalCluster, currentModel) return readModel, handler.ProgressEvent{}, nil @@ -184,7 +184,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler } if !isExist(client, currentModel) { - return progressevent.GetFailedEventByCode("Resource Not Found", cloudformation.HandlerErrorCodeNotFound), nil + return progressevent.GetFailedEventByCode("Resource Not Found", string(types.HandlerErrorCodeNotFound)), nil } projectID := *currentModel.ProjectId @@ -197,7 +197,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "request doest not contain any item to remove", - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } if len(remove) > 0 { @@ -207,7 +207,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler _, _, err := client.Atlas20231115002.GlobalClustersApi.DeleteAllCustomZoneMappings(context.Background(), projectID, clusterName).Execute() if err != nil { return progressevent.GetFailedEventByCode(fmt.Sprintf("Failed to remove custom zones : %s", err.Error()), - cloudformation.HandlerErrorCodeInvalidRequest), nil + string(types.HandlerErrorCodeInvalidRequest)), nil } } return handler.ProgressEvent{ diff --git a/cfn-resources/ldap-configuration/cmd/resource/resource.go b/cfn-resources/ldap-configuration/cmd/resource/resource.go index 48032dfa6..2a04d8f55 100644 --- a/cfn-resources/ldap-configuration/cmd/resource/resource.go +++ b/cfn-resources/ldap-configuration/cmd/resource/resource.go @@ -19,8 +19,8 @@ import ( "errors" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" @@ -64,7 +64,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler } if isResourceEnabled(ldapConf) { - return progressevent.GetFailedEventByCode("Authentication is already enabled for the selected project", cloudformation.HandlerErrorCodeAlreadyExists), nil + return progressevent.GetFailedEventByCode("Authentication is already enabled for the selected project", string(types.HandlerErrorCodeAlreadyExists)), nil } currentModel.AuthenticationEnabled = aws.Bool(true) @@ -206,7 +206,7 @@ func get(client *util.MongoDBClient, groupID string) (*admin20231115002.UserSecu } if !isResourceEnabled(ldapConf) { - errPe := progressevent.GetFailedEventByCode("LDAP Authentication is disabled for the selected project", cloudformation.HandlerErrorCodeNotFound) + errPe := progressevent.GetFailedEventByCode("LDAP Authentication is disabled for the selected project", string(types.HandlerErrorCodeNotFound)) return nil, &errPe } diff --git a/cfn-resources/maintenance-window/cmd/resource/resource.go b/cfn-resources/maintenance-window/cmd/resource/resource.go index e9160031c..135aaa072 100644 --- a/cfn-resources/maintenance-window/cmd/resource/resource.go +++ b/cfn-resources/maintenance-window/cmd/resource/resource.go @@ -19,8 +19,8 @@ import ( "errors" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -53,7 +53,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler maintenanceWindow, _ := get(client, *currentModel) if maintenanceWindow != nil { - return progress_events.GetFailedEventByCode("resource already exists", cloudformation.HandlerErrorCodeAlreadyExists), nil + return progress_events.GetFailedEventByCode("resource already exists", string(types.HandlerErrorCodeAlreadyExists)), nil } atlasModel := currentModel.toAtlasModel() @@ -188,7 +188,7 @@ func get(client *util.MongoDBClient, currentModel Model) (*admin20231115002.Grou if isResponseEmpty(maintenanceWindow) { _, _ = logger.Warnf("Read - resource is empty: %+v", err) - ev := progress_events.GetFailedEventByCode("resource not found", cloudformation.HandlerErrorCodeNotFound) + ev := progress_events.GetFailedEventByCode("resource not found", string(types.HandlerErrorCodeNotFound)) return nil, &ev } From f6a3a5fa0e381b0c706f56ce6033e83d089e963c Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Thu, 27 Nov 2025 02:36:57 +0100 Subject: [PATCH 21/22] init --- cfn-resources/go.mod | 3 ++- cfn-resources/go.sum | 2 ++ .../network-container/cmd/resource/delete.go | 6 +++--- .../network-peering/cmd/resource/resource.go | 16 +++++++++------- .../online-archive/cmd/resource/resource.go | 14 +++++++------- .../organization/cmd/resource/resource.go | 8 ++++---- .../cmd/resource/resource.go | 12 ++++++------ .../cmd/resource/resource.go | 8 ++++---- .../cmd/resource/resource.go | 8 ++++---- .../project-invitation/cmd/resource/create.go | 2 +- .../project-invitation/cmd/resource/delete.go | 2 +- .../project-invitation/cmd/resource/read.go | 2 +- .../project-invitation/cmd/resource/update.go | 2 +- .../cmd/resource/create.go | 12 ++++++------ .../cmd/resource/delete.go | 2 +- .../project-ip-access-list/cmd/resource/list.go | 2 +- .../project-ip-access-list/cmd/resource/read.go | 6 +++--- .../cmd/resource/update.go | 12 ++++++------ .../resource-policy/cmd/resource/resource.go | 4 ++-- 19 files changed, 64 insertions(+), 59 deletions(-) diff --git a/cfn-resources/go.mod b/cfn-resources/go.mod index 84657f404..85e562ba1 100644 --- a/cfn-resources/go.mod +++ b/cfn-resources/go.mod @@ -10,8 +10,8 @@ require ( github.com/aws/aws-sdk-go v1.55.7 github.com/aws/aws-sdk-go-v2 v1.40.0 github.com/aws/aws-sdk-go-v2/config v1.32.1 - github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.39.9 github.com/aws/aws-sdk-go-v2/service/cloudformation v1.71.1 + github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.39.9 github.com/aws/smithy-go v1.23.2 github.com/dave/jennifer v1.7.1 github.com/getkin/kin-openapi v0.133.0 @@ -34,6 +34,7 @@ require ( github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.14 // indirect github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.14 // indirect github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 // indirect + github.com/aws/aws-sdk-go-v2/service/ec2 v1.275.0 // indirect github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3 // indirect github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.14 // indirect github.com/aws/aws-sdk-go-v2/service/signin v1.0.1 // indirect diff --git a/cfn-resources/go.sum b/cfn-resources/go.sum index 27fa3291a..50fdffe24 100644 --- a/cfn-resources/go.sum +++ b/cfn-resources/go.sum @@ -20,6 +20,8 @@ github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4 h1:WKuaxf++XKWlHWu9ECbMlha8WOEG github.com/aws/aws-sdk-go-v2/internal/ini v1.8.4/go.mod h1:ZWy7j6v1vWGmPReu0iSGvRiise4YI5SkR3OHKTZ6Wuc= github.com/aws/aws-sdk-go-v2/service/cloudformation v1.71.1 h1:YA9axGdmN8mAnG3uxredzWXFN/x1IiCbseFqU30ZXog= github.com/aws/aws-sdk-go-v2/service/cloudformation v1.71.1/go.mod h1:AIfiLeQfCO8suB3zxZp155Sv9KfiDhPyF+SSIRLEUYk= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.275.0 h1:ymusjrsOjrcVBQNQXYFIQEHJIJ17/m+VoDSmWIMjGe0= +github.com/aws/aws-sdk-go-v2/service/ec2 v1.275.0/go.mod h1:QrV+/GjhSrJh6MRRuTO6ZEg4M2I0nwPakf0lZHSrE1o= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3 h1:x2Ibm/Af8Fi+BH+Hsn9TXGdT+hKbDd5XOTZxTMxDk7o= github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.3/go.mod h1:IW1jwyrQgMdhisceG8fQLmQIydcT/jWY21rFhzgaKwo= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.14 h1:FIouAnCE46kyYqyhs0XEBDFFSREtdnr8HQuLPQPLCrY= diff --git a/cfn-resources/network-container/cmd/resource/delete.go b/cfn-resources/network-container/cmd/resource/delete.go index 1981d490e..bdead8a7e 100644 --- a/cfn-resources/network-container/cmd/resource/delete.go +++ b/cfn-resources/network-container/cmd/resource/delete.go @@ -21,7 +21,7 @@ import ( "time" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" @@ -59,7 +59,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler OperationStatus: handler.Failed, Message: `You are trying to delete a container that is in use. (container.provisioned = true) Please, make sure to delete the network peering and the atlas cluster before deleting the container`, - HandlerErrorCode: cloudformation.HandlerErrorCodeResourceConflict, + HandlerErrorCode: string(types.HandlerErrorCodeResourceConflict), }, nil } @@ -95,7 +95,7 @@ func retryDeleteIfRequired(client *util.MongoDBClient, response *http.Response, return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: fmt.Sprintf("Please, make sure to delete the network peering and the atlas cluster before deleting the container: %s", errSecondCall.Error()), - HandlerErrorCode: cloudformation.HandlerErrorCodeResourceConflict, + HandlerErrorCode: string(types.HandlerErrorCodeResourceConflict), }, nil } diff --git a/cfn-resources/network-peering/cmd/resource/resource.go b/cfn-resources/network-peering/cmd/resource/resource.go index b1e6ddaf6..db9fb3ec6 100644 --- a/cfn-resources/network-peering/cmd/resource/resource.go +++ b/cfn-resources/network-peering/cmd/resource/resource.go @@ -20,14 +20,16 @@ import ( "fmt" "net/http" + admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" + "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" - admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" ) func setup() { @@ -179,7 +181,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ Message: fmt.Sprintf("No Id found in model:%+v for Update", currentModel), OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } peerID := *currentModel.Id @@ -294,7 +296,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P func validateDeletionProcess(client *util.MongoDBClient, currentModel *Model) handler.ProgressEvent { state, err := getStatus(client, *currentModel.ProjectId, *currentModel.Id) if err != nil { - return progressevent.GetFailedEventByCode(err.Error(), cloudformation.HandlerErrorCodeInvalidRequest) + return progressevent.GetFailedEventByCode(err.Error(), string(types.HandlerErrorCodeInvalidRequest)) } if state == StatusDeleted { @@ -316,10 +318,10 @@ func validateDeletionProcess(client *util.MongoDBClient, currentModel *Model) ha func validateCreationProcess(client *util.MongoDBClient, currentModel *Model) handler.ProgressEvent { state, err := getStatus(client, *currentModel.ProjectId, *currentModel.Id) if err != nil { - return progressevent.GetFailedEventByCode(err.Error(), cloudformation.HandlerErrorCodeInvalidRequest) + return progressevent.GetFailedEventByCode(err.Error(), string(types.HandlerErrorCodeInvalidRequest)) } if state == StatusFailed { - return progressevent.GetFailedEventByCode("Creation failed", cloudformation.HandlerErrorCodeInternalFailure) + return progressevent.GetFailedEventByCode("Creation failed", string(types.HandlerErrorCodeInternalFailure)) } if state == StatusPendingAcceptance || state == StatusAvailable { diff --git a/cfn-resources/online-archive/cmd/resource/resource.go b/cfn-resources/online-archive/cmd/resource/resource.go index 509d5c8a5..8bb0c105a 100644 --- a/cfn-resources/online-archive/cmd/resource/resource.go +++ b/cfn-resources/online-archive/cmd/resource/resource.go @@ -19,8 +19,8 @@ import ( "net/http" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" @@ -93,7 +93,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "no Id found in currentModel", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } if err := validator.ValidateModel(ReadRequiredFields, currentModel); err != nil { return *err, nil @@ -125,7 +125,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "no Id found in currentModel", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } if err := validator.ValidateModel(UpdateRequiredFields, currentModel); err != nil { return *err, nil @@ -335,12 +335,12 @@ func validateProgress(ctx context.Context, client *util.MongoDBClient, currentMo return handler.ProgressEvent{ Message: err.Error(), OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeServiceInternalError}, nil + HandlerErrorCode: string(types.HandlerErrorCodeServiceInternalError)}, nil } if *archive.State == targetState { p := handler.NewProgressEvent() p.ResourceModel = currentModel - p.OperationStatus = cloudformation.OperationStatusInProgress + p.OperationStatus = handler.InProgress p.CallbackDelaySeconds = 60 p.Message = "Pending" p.CallbackContext = map[string]interface{}{ @@ -350,7 +350,7 @@ func validateProgress(ctx context.Context, client *util.MongoDBClient, currentMo return p, nil } p := handler.NewProgressEvent() - p.OperationStatus = cloudformation.OperationStatusSuccess + p.OperationStatus = handler.Success p.Message = "Complete" if *archive.State != "DELETED" { p.ResourceModel = currentModel diff --git a/cfn-resources/organization/cmd/resource/resource.go b/cfn-resources/organization/cmd/resource/resource.go index f170d868d..2af0177e2 100644 --- a/cfn-resources/organization/cmd/resource/resource.go +++ b/cfn-resources/organization/cmd/resource/resource.go @@ -24,7 +24,7 @@ import ( "go.mongodb.org/atlas-sdk/v20250312006/admin" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -326,21 +326,21 @@ func handleError(response *http.Response, method constants.CfnFunctions, err err return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errMsg, - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil } if response.StatusCode == http.StatusUnauthorized { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Not found", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } if response.StatusCode == http.StatusBadRequest { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: errMsg, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } return progress_events.GetFailedEventByResponse(errMsg, response), nil } diff --git a/cfn-resources/private-endpoint-aws/cmd/resource/resource.go b/cfn-resources/private-endpoint-aws/cmd/resource/resource.go index 81665dd26..1dfb7e66e 100644 --- a/cfn-resources/private-endpoint-aws/cmd/resource/resource.go +++ b/cfn-resources/private-endpoint-aws/cmd/resource/resource.go @@ -21,10 +21,9 @@ import ( "net/http" "strings" - "github.com/aws/aws-sdk-go/service/cloudformation" - "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" @@ -125,9 +124,10 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler defer response.Body.Close() if err != nil { if response.StatusCode == http.StatusConflict { - return progress_events.GetFailedEventByCode(fmt.Sprintf("error creating Serverless Private Endpoint %s", - err.Error()), cloudformation.HandlerErrorCodeAlreadyExists), - nil + return progress_events.GetFailedEventByCode( + fmt.Sprintf("error creating Serverless Private Endpoint %s", err.Error()), + string(types.HandlerErrorCodeAlreadyExists), + ), nil } return progress_events.GetFailedEventByResponse(fmt.Sprintf("error creating Serverless Private Endpoint %s", err.Error()), response), diff --git a/cfn-resources/private-endpoint-regional-mode/cmd/resource/resource.go b/cfn-resources/private-endpoint-regional-mode/cmd/resource/resource.go index 0c66c43ac..877a79c3d 100644 --- a/cfn-resources/private-endpoint-regional-mode/cmd/resource/resource.go +++ b/cfn-resources/private-endpoint-regional-mode/cmd/resource/resource.go @@ -20,7 +20,7 @@ import ( "fmt" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" @@ -53,7 +53,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler if isRegModeSettingExists(currentModel, mongodbClient) { return progressevent.GetFailedEventByCode(fmt.Sprintf("Regionalized Setting for Private Endpoint already enabled for : %s", *currentModel.ProjectId), - cloudformation.HandlerErrorCodeAlreadyExists), nil + string(types.HandlerErrorCodeAlreadyExists)), nil } // API call to Add Regional Mode for Private Endpoint @@ -80,7 +80,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P enabled := regPrivateEndpointSetting.Enabled if !enabled { return progressevent.GetFailedEventByCode(fmt.Sprintf("Regionalized Setting for Private Endpoint not found for Project : %s", *currentModel.ProjectId), - cloudformation.HandlerErrorCodeNotFound), nil + string(types.HandlerErrorCodeNotFound)), nil } return handler.ProgressEvent{ @@ -125,7 +125,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler } return progressevent.GetFailedEventByCode(fmt.Sprintf("Error in disabling regionalized mode for private endpoint for Project : %s", *currentModel.ProjectId), - cloudformation.HandlerErrorCodeNotFound), nil + string(types.HandlerErrorCodeNotFound)), nil } // List handles the List event from the Cloudformation service. diff --git a/cfn-resources/privatelink-endpoint-service-data-federation-online-archive/cmd/resource/resource.go b/cfn-resources/privatelink-endpoint-service-data-federation-online-archive/cmd/resource/resource.go index a3db6bc6d..d29290689 100644 --- a/cfn-resources/privatelink-endpoint-service-data-federation-online-archive/cmd/resource/resource.go +++ b/cfn-resources/privatelink-endpoint-service-data-federation-online-archive/cmd/resource/resource.go @@ -20,8 +20,8 @@ import ( "net/http" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -69,7 +69,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: AlreadyExists, - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil } response, err := createOrUpdate(currentModel, atlas) @@ -288,7 +288,7 @@ func handleError(response *http.Response, err error) (handler.ProgressEvent, err return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil } return progress_events.GetFailedEventByResponse(fmt.Sprintf("Error during execution : %s", err.Error()), response), nil } diff --git a/cfn-resources/project-invitation/cmd/resource/create.go b/cfn-resources/project-invitation/cmd/resource/create.go index 5ba88c3bb..d59357246 100644 --- a/cfn-resources/project-invitation/cmd/resource/create.go +++ b/cfn-resources/project-invitation/cmd/resource/create.go @@ -18,7 +18,7 @@ import ( "context" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" log "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" diff --git a/cfn-resources/project-invitation/cmd/resource/delete.go b/cfn-resources/project-invitation/cmd/resource/delete.go index 1ada8a50f..269a5ea4a 100644 --- a/cfn-resources/project-invitation/cmd/resource/delete.go +++ b/cfn-resources/project-invitation/cmd/resource/delete.go @@ -18,7 +18,7 @@ import ( "context" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" log "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" diff --git a/cfn-resources/project-invitation/cmd/resource/read.go b/cfn-resources/project-invitation/cmd/resource/read.go index 39b8f5e83..5562d03b7 100644 --- a/cfn-resources/project-invitation/cmd/resource/read.go +++ b/cfn-resources/project-invitation/cmd/resource/read.go @@ -18,7 +18,7 @@ import ( "context" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" log "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" diff --git a/cfn-resources/project-invitation/cmd/resource/update.go b/cfn-resources/project-invitation/cmd/resource/update.go index bc389eb9f..74fc7e4dd 100644 --- a/cfn-resources/project-invitation/cmd/resource/update.go +++ b/cfn-resources/project-invitation/cmd/resource/update.go @@ -18,7 +18,7 @@ import ( "context" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" log "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" diff --git a/cfn-resources/project-ip-access-list/cmd/resource/create.go b/cfn-resources/project-ip-access-list/cmd/resource/create.go index f607b1887..c6bfa3aef 100644 --- a/cfn-resources/project-ip-access-list/cmd/resource/create.go +++ b/cfn-resources/project-ip-access-list/cmd/resource/create.go @@ -19,7 +19,7 @@ import ( "fmt" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" progressevents "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" @@ -33,7 +33,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler } if len(currentModel.AccessList) == 0 { - return progressevents.GetFailedEventByCode("AccessList must not be empty", cloudformation.HandlerErrorCodeInvalidRequest), nil + return progressevents.GetFailedEventByCode("AccessList must not be empty", string(types.HandlerErrorCodeInvalidRequest)), nil } util.SetDefaultProfileIfNotDefined(¤tModel.Profile) @@ -62,7 +62,7 @@ func createEntries(model *Model, client *util.MongoDBClient) (handler.ProgressEv return handler.ProgressEvent{ Message: "Error in parsing the resource schema", OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, err + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, err } projectID := *model.ProjectId @@ -72,12 +72,12 @@ func createEntries(model *Model, client *util.MongoDBClient) (handler.ProgressEv return handler.ProgressEvent{ Message: fmt.Sprintf("Error validating entries: %s", err.Error()), OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeInternalFailure}, err + HandlerErrorCode: string(types.HandlerErrorCodeInternalFailure)}, err } return handler.ProgressEvent{ Message: "Entry already exists in the access list", OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, err + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, err } if _, _, err := client.Atlas20231115002.ProjectIPAccessListApi.CreateProjectIpAccessList(context.Background(), projectID, &request.Results).Execute(); err != nil { @@ -85,7 +85,7 @@ func createEntries(model *Model, client *util.MongoDBClient) (handler.ProgressEv return handler.ProgressEvent{ Message: err.Error(), OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, err + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, err } return handler.ProgressEvent{}, nil diff --git a/cfn-resources/project-ip-access-list/cmd/resource/delete.go b/cfn-resources/project-ip-access-list/cmd/resource/delete.go index 6ca35f03e..feb3a8735 100644 --- a/cfn-resources/project-ip-access-list/cmd/resource/delete.go +++ b/cfn-resources/project-ip-access-list/cmd/resource/delete.go @@ -16,7 +16,7 @@ package resource import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" ) diff --git a/cfn-resources/project-ip-access-list/cmd/resource/list.go b/cfn-resources/project-ip-access-list/cmd/resource/list.go index fbf09ac9e..622138bda 100644 --- a/cfn-resources/project-ip-access-list/cmd/resource/list.go +++ b/cfn-resources/project-ip-access-list/cmd/resource/list.go @@ -19,7 +19,7 @@ import ( "fmt" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" progressevents "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" diff --git a/cfn-resources/project-ip-access-list/cmd/resource/read.go b/cfn-resources/project-ip-access-list/cmd/resource/read.go index 6ff12e03b..8881484a2 100644 --- a/cfn-resources/project-ip-access-list/cmd/resource/read.go +++ b/cfn-resources/project-ip-access-list/cmd/resource/read.go @@ -19,8 +19,8 @@ import ( "fmt" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" progressevents "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" @@ -53,7 +53,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ Message: "The entry to read is not in the access list", OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } currentModel.TotalCount = result.TotalCount diff --git a/cfn-resources/project-ip-access-list/cmd/resource/update.go b/cfn-resources/project-ip-access-list/cmd/resource/update.go index 8ddac9f36..84e3b9c90 100644 --- a/cfn-resources/project-ip-access-list/cmd/resource/update.go +++ b/cfn-resources/project-ip-access-list/cmd/resource/update.go @@ -16,8 +16,8 @@ package resource import ( "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/aws" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" ) @@ -42,7 +42,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ Message: "The previous model does not have entry. You should use CREATE instead of UPDATE", OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } existingEntries, err := getAllEntries(client, *currentModel.ProjectId) @@ -50,21 +50,21 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ Message: "Error in retrieving the existing entries", OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, err + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, err } if *existingEntries.TotalCount == 0 { return handler.ProgressEvent{ Message: "You have no entry in the accesslist. You should use CREATE instead of UPDATE", OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } if len(currentModel.AccessList) == 0 { return handler.ProgressEvent{ Message: "You cannot have an empty accesslist. You shoud use DELETE instead of UPDATE", OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } // We need to make sure that the entries in the previous and current model are not in the accesslist. diff --git a/cfn-resources/resource-policy/cmd/resource/resource.go b/cfn-resources/resource-policy/cmd/resource/resource.go index 752537cff..26598a020 100644 --- a/cfn-resources/resource-policy/cmd/resource/resource.go +++ b/cfn-resources/resource-policy/cmd/resource/resource.go @@ -22,7 +22,7 @@ import ( "go.mongodb.org/atlas-sdk/v20250312006/admin" "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - "github.com/aws/aws-sdk-go/service/cloudformation" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -113,7 +113,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Update failed", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound, + HandlerErrorCode: string(types.HandlerErrorCodeNotFound), }, nil } resourcePolicyReq := NewResourcePolicyUpdateReq(currentModel) From 57a1b3b0a7dd164900af28593b11e6b81cad1912 Mon Sep 17 00:00:00 2001 From: Aastha Mahendru Date: Thu, 27 Nov 2025 02:39:00 +0100 Subject: [PATCH 22/22] remove mdb version --- .../cloud-backup-schedule/test/cfn-test-create-inputs.sh | 2 +- .../cloud-backup-snapshot/test/cfn-test-create-inputs.sh | 2 +- .../test/cfn-test-create-inputs-with-clusters.sh | 4 ++-- .../global-cluster-config/test/cfn-test-create-inputs.sh | 2 +- cfn-resources/ldap-verify/test/cfn-test-create-inputs.sh | 2 +- .../online-archive/test/cfn-test-create-inputs.sh | 2 +- cfn-resources/search-index/test/cfn-test-create-inputs.sh | 8 ++++---- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/cfn-resources/cloud-backup-schedule/test/cfn-test-create-inputs.sh b/cfn-resources/cloud-backup-schedule/test/cfn-test-create-inputs.sh index a4196dded..9b9953f3c 100755 --- a/cfn-resources/cloud-backup-schedule/test/cfn-test-create-inputs.sh +++ b/cfn-resources/cloud-backup-schedule/test/cfn-test-create-inputs.sh @@ -33,7 +33,7 @@ export MCLI_PROJECT_ID=$projectId clusterId=$(atlas clusters list --projectId "${projectId}" --output json | jq --arg NAME "${clusterName}" -r '.results[]? | select(.name==$NAME) | .id') if [ -z "$clusterId" ]; then echo "creating cluster.." - atlas clusters create "${clusterName}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --mdbVersion 5.0 --diskSizeGB 10 --output=json + atlas clusters create "${clusterName}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --diskSizeGB 10 --output=json atlas clusters watch "${clusterName}" --projectId "${projectId}" echo -e "Created Cluster \"${clusterName}\"" fi diff --git a/cfn-resources/cloud-backup-snapshot/test/cfn-test-create-inputs.sh b/cfn-resources/cloud-backup-snapshot/test/cfn-test-create-inputs.sh index 2526405b7..f7ac42017 100755 --- a/cfn-resources/cloud-backup-snapshot/test/cfn-test-create-inputs.sh +++ b/cfn-resources/cloud-backup-snapshot/test/cfn-test-create-inputs.sh @@ -43,7 +43,7 @@ if [ -z "$projectId" ]; then echo -e "Cant find project \"${projectName}\"\n" fi -atlas clusters create "${clusterName}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --mdbVersion 5.0 --diskSizeGB 10 --output=json +atlas clusters create "${clusterName}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --diskSizeGB 10 --output=json atlas clusters watch "${clusterName}" --projectId "${projectId}" echo -e "Created Cluster \"${clusterName}\"" diff --git a/cfn-resources/federated-database-instance/test/cfn-test-create-inputs-with-clusters.sh b/cfn-resources/federated-database-instance/test/cfn-test-create-inputs-with-clusters.sh index 678e0e94d..7aa135a33 100755 --- a/cfn-resources/federated-database-instance/test/cfn-test-create-inputs-with-clusters.sh +++ b/cfn-resources/federated-database-instance/test/cfn-test-create-inputs-with-clusters.sh @@ -54,7 +54,7 @@ if atlas clusters describe "${cluster1}" --projectId "${projectId}"; then echo "Cluster found" else echo "Cluster1 not found, creating..." - atlas clusters create "${cluster1}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --mdbVersion 5.0 --diskSizeGB 10 --output=json + atlas clusters create "${cluster1}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --diskSizeGB 10 --output=json atlas clusters watch "${cluster1}" --projectId "${projectId}" echo -e "Created Cluster \"${cluster1}\"" fi @@ -63,7 +63,7 @@ if atlas clusters describe "${cluster2}" --projectId "${projectId}"; then echo "Cluster found" else echo "Cluster2 not found, creating..." - atlas clusters create "${cluster2}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --mdbVersion 5.0 --diskSizeGB 10 --output=json + atlas clusters create "${cluster2}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --diskSizeGB 10 --output=json atlas clusters watch "${cluster2}" --projectId "${projectId}" echo -e "Created Cluster \"${cluster2}\"" fi diff --git a/cfn-resources/global-cluster-config/test/cfn-test-create-inputs.sh b/cfn-resources/global-cluster-config/test/cfn-test-create-inputs.sh index b262431d8..189f9d22c 100755 --- a/cfn-resources/global-cluster-config/test/cfn-test-create-inputs.sh +++ b/cfn-resources/global-cluster-config/test/cfn-test-create-inputs.sh @@ -46,7 +46,7 @@ echo -e "=====\nrun this command to clean up\n=====\nmongocli iam projects delet ClusterName="${projectName}" -atlas clusters create "${ClusterName}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M30 --mdbVersion 5.0 --diskSizeGB 10 --output=json +atlas clusters create "${ClusterName}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M30 --diskSizeGB 10 --output=json atlas clusters watch "${ClusterName}" --projectId "${projectId}" echo -e "Created Cluster \"${ClusterName}\"" diff --git a/cfn-resources/ldap-verify/test/cfn-test-create-inputs.sh b/cfn-resources/ldap-verify/test/cfn-test-create-inputs.sh index b9aefed08..06e574894 100755 --- a/cfn-resources/ldap-verify/test/cfn-test-create-inputs.sh +++ b/cfn-resources/ldap-verify/test/cfn-test-create-inputs.sh @@ -39,7 +39,7 @@ ClusterName="${projectName}" clusterId=$(atlas clusters list --projectId "${projectId}" --output json | jq --arg NAME "${ClusterName}" -r '.results[]? | select(.name==$NAME) | .id') if [ -z "$clusterId" ]; then echo "creating cluster.." - clusterId=$(atlas clusters create "${ClusterName}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --mdbVersion 5.0 --diskSizeGB 10 --output=json | jq -r '.id') + clusterId=$(atlas clusters create "${ClusterName}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --diskSizeGB 10 --output=json | jq -r '.id') fi status=$(atlas clusters describe "${ClusterName}" --projectId "${projectId}" --output=json | jq -r '.stateName') diff --git a/cfn-resources/online-archive/test/cfn-test-create-inputs.sh b/cfn-resources/online-archive/test/cfn-test-create-inputs.sh index 4dd01a4dc..c36c141ab 100755 --- a/cfn-resources/online-archive/test/cfn-test-create-inputs.sh +++ b/cfn-resources/online-archive/test/cfn-test-create-inputs.sh @@ -33,7 +33,7 @@ echo -e "=====\nrun this command to clean up\n=====\nmongocli iam projects delet ClusterName="${projectName}" # shellcheck disable=SC2086 -atlas clusters create "${ClusterName}" --projectId ${projectId} --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --mdbVersion 5.0 --diskSizeGB 10 --output=json +atlas clusters create "${ClusterName}" --projectId ${projectId} --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --diskSizeGB 10 --output=json atlas clusters watch "${ClusterName}" --projectId "${projectId}" echo -e "Created Cluster \"${ClusterName}\"" diff --git a/cfn-resources/search-index/test/cfn-test-create-inputs.sh b/cfn-resources/search-index/test/cfn-test-create-inputs.sh index 64e5e2afe..d87a13efa 100755 --- a/cfn-resources/search-index/test/cfn-test-create-inputs.sh +++ b/cfn-resources/search-index/test/cfn-test-create-inputs.sh @@ -33,11 +33,11 @@ echo -e "=====\nrun this command to clean up\n=====\nmongocli iam projects delet ClusterName="${projectName}" clusterId=$(atlas clusters list --projectId "${projectId}" --output json | jq --arg NAME "${ClusterName}" -r '.results[]? | select(.name==$NAME) | .id') if [ -z "$clusterId" ]; then - atlas clusters create "${ClusterName}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --mdbVersion 5.0 --diskSizeGB 10 --output=json - atlas clusters watch "${ClusterName}" --projectId "${projectId}" - echo -e "Created Cluster \"${ClusterName}\"" + atlas clusters create "${ClusterName}" --projectId "${projectId}" --backup --provider AWS --region US_EAST_1 --members 3 --tier M10 --diskSizeGB 10 --output=json + atlas clusters watch "${ClusterName}" --projectId "${projectId}" + echo -e "Created Cluster \"${ClusterName}\"" - atlas clusters loadSampleData "${ClusterName}" --projectId "${projectId}" + atlas clusters loadSampleData "${ClusterName}" --projectId "${projectId}" fi cluster_name=${ClusterName}