diff --git a/.github/workflows/contract-testing.yaml b/.github/workflows/contract-testing.yaml index bcfc691cb..743d09e5a 100644 --- a/.github/workflows/contract-testing.yaml +++ b/.github/workflows/contract-testing.yaml @@ -28,7 +28,6 @@ jobs: project: ${{ steps.filter.outputs.project }} resource-policy: ${{ steps.filter.outputs.resource-policy }} search-deployment: ${{ steps.filter.outputs.search-deployment }} - serverless-private-endpoint: ${{ steps.filter.outputs.serverless-private-endpoint }} stream-connection: ${{ steps.filter.outputs.stream-connection }} stream-instance: ${{ steps.filter.outputs.stream-instance }} steps: @@ -72,8 +71,6 @@ jobs: - 'cfn-resources/resource-policy/**' search-deployment: - 'cfn-resources/search-deployment/**' - serverless-private-endpoint: - - 'cfn-resources/serverless-private-endpoint/**' stream-connection: - 'cfn-resources/stream-connection/**' stream-instance: @@ -774,48 +771,6 @@ jobs: cat inputs/inputs_1_create.json - make run-contract-testing - make delete-test-resources - serverless-private-endpoint: - needs: change-detection - if: ${{ needs.change-detection.outputs. serverless-private-endpoint == 'true' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 - - uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c - with: - go-version-file: 'cfn-resources/go.mod' - - name: setup Atlas CLI - uses: mongodb/atlas-github-action@e3c9e0204659bafbb3b65e1eb1ee745cca0e9f3b - - uses: aws-actions/setup-sam@c71dd89d980e49367c70391e8ada4353f52f2800 - with: - use-installer: true - - uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST_ENV }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST_ENV }} - aws-region: eu-west-1 - - uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 - with: - python-version: '3.9' - cache: 'pip' # caching pip dependencies - - run: pip install cloudformation-cli cloudformation-cli-go-plugin - - name: Run the Contract test - shell: bash - env: - MONGODB_ATLAS_PUBLIC_API_KEY: ${{ secrets.CLOUD_DEV_PUBLIC_KEY }} - MONGODB_ATLAS_PRIVATE_API_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }} - MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }} - MONGODB_ATLAS_TEAM_ID: 641490b0207f4d22f4d8f2fd - MONGODB_ATLAS_OPS_MANAGER_URL: https://cloud-dev.mongodb.com/ - MONGODB_ATLAS_PROFILE: cfn-cloud-dev-github-action - run: | - pushd cfn-resources/serverless-private-endpoint - make create-test-resources - - cat inputs/inputs_1_create.json - cat inputs/inputs_1_update.json - make run-contract-testing make delete-test-resources stream-connection: diff --git a/cfn-resources/autogen/main.go b/cfn-resources/autogen/main.go index 1fedc8ac3..2f68dda22 100644 --- a/cfn-resources/autogen/main.go +++ b/cfn-resources/autogen/main.go @@ -43,7 +43,7 @@ const ( deleteReqFields = "DeleteRequiredFields" listReqFields = "ListRequiredFields" handler = "github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler" - cloudformation = "github.com/aws/aws-sdk-go/service/cloudformation" + cloudformation = "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" util = "github.com/mongodb/mongodbatlas-cloudformation-resources/util" validator = "github.com/mongodb/mongodbatlas-cloudformation-resources/util/validator" progressEvent = "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" 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/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-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/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/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/go.mod b/cfn-resources/go.mod index 84657f404..4351840e4 100644 --- a/cfn-resources/go.mod +++ b/cfn-resources/go.mod @@ -7,11 +7,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.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/ec2 v1.275.0 + 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 @@ -29,6 +29,7 @@ require ( require ( github.com/aws/aws-lambda-go v1.37.0 // indirect + github.com/aws/aws-sdk-go v1.55.7 // indirect github.com/aws/aws-sdk-go-v2/credentials v1.19.1 // indirect github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.14 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.14 // 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/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/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/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 } 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/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/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..9da66335a 100644 --- a/cfn-resources/private-endpoint-aws/cmd/resource/resource.go +++ b/cfn-resources/private-endpoint-aws/cmd/resource/resource.go @@ -21,16 +21,17 @@ import ( "net/http" "strings" - "github.com/aws/aws-sdk-go/service/cloudformation" + 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-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" 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" ) func setup() { @@ -125,9 +126,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/private-endpoint-service/cmd/resource/resource.go b/cfn-resources/private-endpoint-service/cmd/resource/resource.go index a84dbaa91..6ad0fb9cd 100644 --- a/cfn-resources/private-endpoint-service/cmd/resource/resource.go +++ b/cfn-resources/private-endpoint-service/cmd/resource/resource.go @@ -21,15 +21,14 @@ import ( "fmt" "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/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" "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 ( @@ -152,7 +151,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler if privateEndpointResponse == nil { return progressevent.GetFailedEventByCode("Error deleting resource, private Endpoint Response is null", - cloudformation.HandlerErrorCodeNotFound), nil + string(types.HandlerErrorCodeNotFound)), nil } deletePrivateEndpointRequest := client.Atlas20231115014.PrivateEndpointServicesApi.DeletePrivateEndpointService(context.Background(), *currentModel.ProjectId, @@ -268,7 +267,7 @@ func create(client *util.MongoDBClient, currentModel *Model) handler.ProgressEve return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource already exists", - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists} + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)} } if err != nil { @@ -284,7 +283,7 @@ func create(client *util.MongoDBClient, currentModel *Model) handler.ProgressEve callBackMap, err := callBackContext.convertToInterface() if err != nil { return progressevent.GetFailedEventByCode(fmt.Sprintf("Error Unmarshalling callback map : %s", err.Error()), - cloudformation.HandlerErrorCodeServiceInternalError) + string(types.HandlerErrorCodeServiceInternalError)) } currentModel.completeByConnection(*createPrivateEndpointResponse) @@ -307,7 +306,7 @@ func validateCreationCompletion(client *util.MongoDBClient, currentModel *Model, currentModel.completeByConnection(*privateEndpointResponse) if privateEndpointResponse.Status == nil { - return progressevent.GetFailedEventByCode("Error getting private endpoint status : status null", cloudformation.HandlerErrorCodeServiceInternalError) + return progressevent.GetFailedEventByCode("Error getting private endpoint status : status null", string(types.HandlerErrorCodeServiceInternalError)) } switch *privateEndpointResponse.Status { @@ -320,7 +319,7 @@ func validateCreationCompletion(client *util.MongoDBClient, currentModel *Model, callBackMap, err := callBackContext.convertToInterface() if err != nil { return progressevent.GetFailedEventByCode(fmt.Sprintf("Error Unmarshalling callback map : %s", err.Error()), - cloudformation.HandlerErrorCodeServiceInternalError) + string(types.HandlerErrorCodeServiceInternalError)) } return progressevent.GetInProgressProgressEvent("Private endpoint service initiating", callBackMap, @@ -333,7 +332,7 @@ func validateCreationCompletion(client *util.MongoDBClient, currentModel *Model, default: return progressevent.GetFailedEventByCode(fmt.Sprintf("Error creating private endpoint in status : %s", *privateEndpointResponse.Status), - cloudformation.HandlerErrorCodeInvalidRequest) + string(types.HandlerErrorCodeInvalidRequest)) } } diff --git a/cfn-resources/private-endpoint/cmd/resource/resource.go b/cfn-resources/private-endpoint/cmd/resource/resource.go index c6271f97b..f083d333d 100644 --- a/cfn-resources/private-endpoint/cmd/resource/resource.go +++ b/cfn-resources/private-endpoint/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" resource_constats "github.com/mongodb/mongodbatlas-cloudformation-resources/private-endpoint/cmd/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/private-endpoint/cmd/resource/steps/awsvpcendpoint" "github.com/mongodb/mongodbatlas-cloudformation-resources/private-endpoint/cmd/resource/steps/privateendpoint" @@ -216,7 +216,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler if privateEndpointResponse == nil { return progressevent.GetFailedEventByCode("Error deleting resource, private Endpoint Response is null", - cloudformation.HandlerErrorCodeNotFound), nil + string(types.HandlerErrorCodeNotFound)), nil } privateEndpoint := *privateEndpointResponse @@ -323,7 +323,7 @@ func getProcessStatus(req handler.Request) (resource_constats.EventStatus, *hand eventStatus, err := resource_constats.ParseEventStatus(fmt.Sprintf("%v", callback)) if err != nil { pe := progressevent.GetFailedEventByCode(fmt.Sprintf("Error parsing callback status : %s", err.Error()), - cloudformation.HandlerErrorCodeServiceInternalError) + string(types.HandlerErrorCodeServiceInternalError)) return "", &pe } diff --git a/cfn-resources/private-endpoint/cmd/resource/steps/awsvpcendpoint/aws_vpc_endpoint.go b/cfn-resources/private-endpoint/cmd/resource/steps/awsvpcendpoint/aws_vpc_endpoint.go index e3a8c578a..29ba77fc2 100644 --- a/cfn-resources/private-endpoint/cmd/resource/steps/awsvpcendpoint/aws_vpc_endpoint.go +++ b/cfn-resources/private-endpoint/cmd/resource/steps/awsvpcendpoint/aws_vpc_endpoint.go @@ -15,18 +15,24 @@ package awsvpcendpoint import ( + "context" "fmt" "strings" "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/service/ec2" + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" + "github.com/aws/aws-sdk-go-v2/service/ec2" + ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util/awsconfig" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" ) -func newEc2Client(region string, req handler.Request) *ec2.EC2 { - return ec2.New(req.Session, aws.NewConfig().WithRegion(region)) +func newEc2Client(region string, req handler.Request) *ec2.Client { + cfg := awsconfig.FromHandlerRequest(&req) + if region != "" { + cfg.Region = region + } + return ec2.NewFromConfig(cfg) } type AwsPrivateEndpointInput struct { @@ -48,28 +54,20 @@ func convertToAWSRegion(region string) string { func Create(req handler.Request, endpointServiceName string, region string, privateEndpointInputs []AwsPrivateEndpointInput) ([]AwsPrivateEndpointOutput, *handler.ProgressEvent) { svc := newEc2Client(convertToAWSRegion(region), req) - vcpType := "Interface" - subnetIDs := make([]AwsPrivateEndpointOutput, len(privateEndpointInputs)) for i, pe := range privateEndpointInputs { - subnetIDsIn := make([]*string, len(pe.SubnetIDs)) - - for i := range pe.SubnetIDs { - subnetIDsIn[i] = &(pe.SubnetIDs[i]) - } - - connection := ec2.CreateVpcEndpointInput{ + connection := &ec2.CreateVpcEndpointInput{ VpcId: &pe.VpcID, ServiceName: &endpointServiceName, - VpcEndpointType: &vcpType, - SubnetIds: subnetIDsIn, + VpcEndpointType: ec2types.VpcEndpointTypeInterface, + SubnetIds: pe.SubnetIDs, } - vpcE, err := svc.CreateVpcEndpoint(&connection) + vpcE, err := svc.CreateVpcEndpoint(context.Background(), connection) if err != nil { fpe := progressevent.GetFailedEventByCode(fmt.Sprintf("Error creating vcp Endpoint: %s", err.Error()), - cloudformation.HandlerErrorCodeGeneralServiceException) + string(types.HandlerErrorCodeGeneralServiceException)) return nil, &fpe } @@ -86,20 +84,14 @@ func Create(req handler.Request, endpointServiceName string, region string, priv func Delete(req handler.Request, interfaceEndpoints []string, region string) *handler.ProgressEvent { svc := newEc2Client(convertToAWSRegion(region), req) - vpcEndpointIDs := make([]*string, 0) - for i := range interfaceEndpoints { - vpcEndpointIDs = append(vpcEndpointIDs, &interfaceEndpoints[i]) - } - - connection := ec2.DeleteVpcEndpointsInput{ - DryRun: nil, - VpcEndpointIds: vpcEndpointIDs, + connection := &ec2.DeleteVpcEndpointsInput{ + VpcEndpointIds: interfaceEndpoints, } - _, err := svc.DeleteVpcEndpoints(&connection) + _, err := svc.DeleteVpcEndpoints(context.Background(), connection) if err != nil { fpe := progressevent.GetFailedEventByCode(fmt.Sprintf("Error deleting vcp Endpoint: %s", err.Error()), - cloudformation.HandlerErrorCodeGeneralServiceException) + string(types.HandlerErrorCodeGeneralServiceException)) return &fpe } diff --git a/cfn-resources/private-endpoint/cmd/resource/steps/privateendpoint/private_endpoint.go b/cfn-resources/private-endpoint/cmd/resource/steps/privateendpoint/private_endpoint.go index 7d53a4c5f..385a2519b 100644 --- a/cfn-resources/private-endpoint/cmd/resource/steps/privateendpoint/private_endpoint.go +++ b/cfn-resources/private-endpoint/cmd/resource/steps/privateendpoint/private_endpoint.go @@ -22,7 +22,7 @@ import ( "strings" "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/private-endpoint/cmd/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" @@ -160,7 +160,7 @@ func Create(client *util.MongoDBClient, groupID string, privateEndpointInput []A callBackMap, err := GetCallback(privateEndpointInput, endpointServiceID, constants.CreatingPrivateEndpoint) if err != nil { return progressevent.GetFailedEventByCode(fmt.Sprintf("Error Unmarshalling callback map : %s", err.Error()), - cloudformation.HandlerErrorCodeInvalidRequest) + string(types.HandlerErrorCodeInvalidRequest)) } return progressevent.GetInProgressProgressEvent("Adding private endpoint", callBackMap, nil, 20) @@ -171,7 +171,7 @@ func ValidateCreationCompletion(client *util.MongoDBClient, groupID string, req err := callBackContext.FillStruct(req.CallbackContext) if err != nil { - pe := progressevent.GetFailedEventByCode(fmt.Sprintf("Error parsing PrivateEndpointCallBackContext : %s", err.Error()), cloudformation.HandlerErrorCodeServiceInternalError) + pe := progressevent.GetFailedEventByCode(fmt.Sprintf("Error parsing PrivateEndpointCallBackContext : %s", err.Error()), string(types.HandlerErrorCodeServiceInternalError)) return nil, &pe } @@ -199,7 +199,7 @@ func ValidateCreationCompletion(client *util.MongoDBClient, groupID string, req continue default: pe := progressevent.GetFailedEventByCode(fmt.Sprintf("Resource is in status : %s", *privateEndpointResponse.Status), - cloudformation.HandlerErrorCodeInternalFailure) + string(types.HandlerErrorCodeInternalFailure)) return nil, &pe } } diff --git a/cfn-resources/private-endpoint/cmd/resource/steps/privateendpointservice/private_endpoint_service.go b/cfn-resources/private-endpoint/cmd/resource/steps/privateendpointservice/private_endpoint_service.go index fbbbd2ba8..b9e110595 100644 --- a/cfn-resources/private-endpoint/cmd/resource/steps/privateendpointservice/private_endpoint_service.go +++ b/cfn-resources/private-endpoint/cmd/resource/steps/privateendpointservice/private_endpoint_service.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/private-endpoint/cmd/constants" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" @@ -67,7 +67,7 @@ func Create(client util.MongoDBClient, region string, groupID string) handler.Pr return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Resource already exists", - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists} + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)} } if err != nil { @@ -98,7 +98,7 @@ func ValidateCreationCompletion(client *util.MongoDBClient, groupID string, req err := PrivateEndpointCallBackContext.FillStruct(req.CallbackContext) if err != nil { ev := progressevent.GetFailedEventByCode(fmt.Sprintf("Error parsing PrivateEndpointCallBackContext : %s", err.Error()), - cloudformation.HandlerErrorCodeServiceInternalError) + string(types.HandlerErrorCodeServiceInternalError)) return nil, &ev } @@ -134,7 +134,7 @@ func ValidateCreationCompletion(client *util.MongoDBClient, groupID string, req default: ev := progressevent.GetFailedEventByCode(fmt.Sprintf("Error creating private endpoint in status : %s", *privateEndpointResponse.Status), - cloudformation.HandlerErrorCodeInvalidRequest) + string(types.HandlerErrorCodeInvalidRequest)) return nil, &ev } } 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/profile/profile.go b/cfn-resources/profile/profile.go index aa06bb21f..539acf581 100644 --- a/cfn-resources/profile/profile.go +++ b/cfn-resources/profile/profile.go @@ -44,7 +44,11 @@ func NewProfile(req *handler.Request, profileName *string, prefixRequired bool) profileName = aws.String(DefaultProfile) } - // Create AWS SDK v2 config using CloudFormation handler's SDK v1 session credentials + // When migrating to AWS SDK v2, we can't use config.LoadDefaultConfig() directly in CloudFormation resource handlers. + // The cloudformation-cli-go-plugin provides credentials via handler.Request.Session, which is an AWS SDK v1 session. + // These credentials have the permissions defined in our resource execution roles (e.g., Secrets Manager access). + // Using LoadDefaultConfig() would use the Lambda's base execution role instead, which lacks these permissions. + // See: https://github.com/aws-cloudformation/cloudformation-cli-go-plugin/issues/237 cfg := awsconfig.FromHandlerRequest(req) secretsManagerClient := secretsmanager.NewFromConfig(cfg) secretID := *profileName diff --git a/cfn-resources/project-invitation/cmd/resource/create.go b/cfn-resources/project-invitation/cmd/resource/create.go index 5ba88c3bb..5e3407f14 100644 --- a/cfn-resources/project-invitation/cmd/resource/create.go +++ b/cfn-resources/project-invitation/cmd/resource/create.go @@ -17,13 +17,15 @@ package resource import ( "context" + 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-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" progressevents "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" - admin20231115002 "go.mongodb.org/atlas-sdk/v20231115002/admin" ) func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler.ProgressEvent, error) { 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/list.go b/cfn-resources/project-invitation/cmd/resource/list.go index 9c606754c..c5baae7f5 100644 --- a/cfn-resources/project-invitation/cmd/resource/list.go +++ b/cfn-resources/project-invitation/cmd/resource/list.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/project/cmd/resource/resource_test.go b/cfn-resources/project/cmd/resource/resource_test.go index c42ec3914..a354874d6 100644 --- a/cfn-resources/project/cmd/resource/resource_test.go +++ b/cfn-resources/project/cmd/resource/resource_test.go @@ -18,7 +18,7 @@ import ( "reflect" "testing" - "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go-v2/aws" "github.com/mongodb/mongodbatlas-cloudformation-resources/project/cmd/resource" ) 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) diff --git a/cfn-resources/search-index/cmd/resource/resource.go b/cfn-resources/search-index/cmd/resource/resource.go index bac625072..238c9f9a1 100644 --- a/cfn-resources/search-index/cmd/resource/resource.go +++ b/cfn-resources/search-index/cmd/resource/resource.go @@ -21,8 +21,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/logger" @@ -67,7 +67,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest, + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest), ResourceModel: currentModel, }, nil } @@ -76,8 +76,8 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler if err != nil { return handler.ProgressEvent{ Message: err.Error(), - OperationStatus: cloudformation.OperationStatusFailed, - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil + OperationStatus: handler.Failed, + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil } currentModel.Status = newSearchIndex.Status @@ -100,9 +100,9 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P if currentModel.IndexId == nil { err := errors.New("no Id found in currentModel") return handler.ProgressEvent{ - OperationStatus: cloudformation.OperationStatusFailed, + OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } if errEvent := validator.ValidateModel(ReadRequiredFields, currentModel); errEvent != nil { return *errEvent, nil @@ -121,13 +121,13 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ Message: err.Error(), OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } } currentModel.Status = searchIndex.Status currentModel.Type = searchIndex.Type return handler.ProgressEvent{ - OperationStatus: cloudformation.OperationStatusSuccess, + OperationStatus: handler.Success, Message: "Read Complete", ResourceModel: currentModel, }, nil @@ -141,7 +141,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } if errEvent := validator.ValidateModel(UpdateRequiredFields, currentModel); errEvent != nil { @@ -167,7 +167,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest, + HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest), ResourceModel: currentModel, }, nil } @@ -180,12 +180,12 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeServiceInternalError}, nil + HandlerErrorCode: string(types.HandlerErrorCodeServiceInternalError)}, nil } currentModel.Status = updatedSearchIndex.Status return handler.ProgressEvent{ @@ -206,9 +206,9 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler if currentModel.IndexId == nil { err := errors.New("no Id found in currentModel") return handler.ProgressEvent{ - OperationStatus: cloudformation.OperationStatusFailed, + OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } if errEvent := validator.ValidateModel(DeleteRequiredFields, currentModel); errEvent != nil { @@ -235,17 +235,17 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler if err != nil { if resp != nil && (resp.StatusCode == http.StatusInternalServerError || resp.StatusCode == http.StatusNotFound) { return handler.ProgressEvent{ - OperationStatus: cloudformation.OperationStatusFailed, - Message: cloudformation.HandlerErrorCodeNotFound, - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + OperationStatus: handler.Failed, + Message: string(types.HandlerErrorCodeNotFound), + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } return handler.ProgressEvent{ - OperationStatus: cloudformation.OperationStatusFailed, + OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } return handler.ProgressEvent{ - OperationStatus: cloudformation.OperationStatusInProgress, + OperationStatus: handler.InProgress, Message: "Delete in progress", CallbackContext: map[string]any{ "stateName": handler.InProgress, @@ -282,7 +282,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ Message: err.Error(), OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeServiceInternalError}, nil + HandlerErrorCode: string(types.HandlerErrorCodeServiceInternalError)}, nil } response := make([]any, 0, len(indices)) for i := range indices { @@ -298,10 +298,10 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P func newSearchIndex(currentModel *Model) (*admin20231115002.ClusterSearchIndex, error) { searchIndex := &admin20231115002.ClusterSearchIndex{ Analyzer: currentModel.Analyzer, - CollectionName: aws.StringValue(currentModel.CollectionName), - Database: aws.StringValue(currentModel.Database), + CollectionName: aws.ToString(currentModel.CollectionName), + Database: aws.ToString(currentModel.Database), IndexID: currentModel.IndexId, - Name: aws.StringValue(currentModel.Name), + Name: aws.ToString(currentModel.Name), SearchAnalyzer: currentModel.SearchAnalyzer, Status: currentModel.Status, Type: currentModel.Type, @@ -428,13 +428,13 @@ func convertStringToInterfaceMap(fields *string) ([]map[string]any, error) { func status(currentModel *Model) handler.Status { switch *currentModel.Status { case string(handler.Success): - return cloudformation.OperationStatusSuccess + return handler.Success case string(handler.Failed): - return cloudformation.OperationStatusFailed + return handler.Failed case string(handler.InProgress): - return cloudformation.OperationStatusInProgress + return handler.InProgress } - return cloudformation.OperationStatusPending + return handler.InProgress } func validateProgress(ctx context.Context, client *admin20231115002.APIClient, currentModel *Model, targetState string) (event handler.ProgressEvent, err error) { @@ -444,12 +444,12 @@ func validateProgress(ctx context.Context, client *admin20231115002.APIClient, c return handler.ProgressEvent{ Message: err.Error(), OperationStatus: handler.Failed, - HandlerErrorCode: cloudformation.HandlerErrorCodeServiceInternalError}, nil + HandlerErrorCode: string(types.HandlerErrorCodeServiceInternalError)}, nil } if util.AreStringPtrEqual(index.Status, &targetState) { p := handler.NewProgressEvent() p.ResourceModel = currentModel - p.OperationStatus = cloudformation.OperationStatusInProgress + p.OperationStatus = handler.InProgress p.CallbackDelaySeconds = 120 p.Message = "Pending" p.CallbackContext = map[string]any{ @@ -459,14 +459,14 @@ func validateProgress(ctx context.Context, client *admin20231115002.APIClient, c return p, nil } p := handler.NewProgressEvent() - if util.AreStringPtrEqual(index.Status, admin20231115002.PtrString(cloudformation.OperationStatusFailed)) { - p.OperationStatus = cloudformation.OperationStatusFailed + if util.AreStringPtrEqual(index.Status, admin20231115002.PtrString(string(handler.Failed))) { + p.OperationStatus = handler.Failed p.Message = "Failed" - p.HandlerErrorCode = cloudformation.HandlerErrorCodeInvalidRequest + p.HandlerErrorCode = string(types.HandlerErrorCodeInvalidRequest) p.ResourceModel = currentModel return p, nil } - p.OperationStatus = cloudformation.OperationStatusSuccess + p.OperationStatus = handler.Success p.Message = "Complete" if util.IsStringPresent(index.Status) && *index.Status != "DELETED" { p.ResourceModel = currentModel 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} diff --git a/cfn-resources/serverless-instance/cmd/resource/resource.go b/cfn-resources/serverless-instance/cmd/resource/resource.go index 1c7d7b651..a2a430485 100644 --- a/cfn-resources/serverless-instance/cmd/resource/resource.go +++ b/cfn-resources/serverless-instance/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" + "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" @@ -84,7 +84,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: err.Error(), - HandlerErrorCode: cloudformation.HandlerErrorCodeAlreadyExists}, nil + HandlerErrorCode: string(types.HandlerErrorCodeAlreadyExists)}, nil } return progressevent.GetFailedEventByResponse(err.Error(), res), nil diff --git a/cfn-resources/serverless-private-endpoint/cmd/resource/resource.go b/cfn-resources/serverless-private-endpoint/cmd/resource/resource.go index 3c48dd5a3..1efcf815e 100644 --- a/cfn-resources/serverless-private-endpoint/cmd/resource/resource.go +++ b/cfn-resources/serverless-private-endpoint/cmd/resource/resource.go @@ -22,8 +22,8 @@ import ( "strings" "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/serverless-private-endpoint/cmd/resource/enums" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" @@ -149,7 +149,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P defer response.Body.Close() if err != nil { if isTenantPrivateEndpointNotFound(response) { - return progressevents.GetFailedEventByCode(fmt.Sprintf("error getting Serverless Private Endpoint %s", err.Error()), cloudformation.HandlerErrorCodeNotFound), nil + return progressevents.GetFailedEventByCode(fmt.Sprintf("error getting Serverless Private Endpoint %s", err.Error()), string(types.HandlerErrorCodeNotFound)), nil } return progressevents.GetFailedEventByResponse(fmt.Sprintf("error getting Serverless Private Endpoint %s", err.Error()), response), nil @@ -157,7 +157,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P if serverlessPrivateEndpoint == nil { return progressevents.GetFailedEventByCode(fmt.Sprintf("Error while trying to make api call, CreateServerlessPrivateEndpoint returned status %d, and the response is NULL", response.StatusCode), - cloudformation.HandlerErrorCodeInternalFailure), nil + string(types.HandlerErrorCodeInternalFailure)), nil } currentModel.completeWithAtlasModel(*serverlessPrivateEndpoint) @@ -206,7 +206,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler defer response.Body.Close() if err != nil { if isTenantPrivateEndpointNotFound(response) { - return progressevents.GetFailedEventByCode(fmt.Sprintf("error updating Serverless Private Endpoint %s", err.Error()), cloudformation.HandlerErrorCodeNotFound), nil + return progressevents.GetFailedEventByCode(fmt.Sprintf("error updating Serverless Private Endpoint %s", err.Error()), string(types.HandlerErrorCodeNotFound)), nil } return progressevents.GetFailedEventByResponse(fmt.Sprintf("error updating Serverless Private Endpoint %s", err.Error()), response), nil @@ -214,7 +214,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler if serverlessPrivateEndpoint == nil { return progressevents.GetFailedEventByCode(fmt.Sprintf("Error while trying to make api call, CreateServerlessPrivateEndpoint returned status %d, and the response is NULL", response.StatusCode), - cloudformation.HandlerErrorCodeInternalFailure), nil + string(types.HandlerErrorCodeInternalFailure)), nil } currentModel.completeWithAtlasModel(*serverlessPrivateEndpoint) @@ -255,7 +255,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler createAndAssignAWSPrivateEndpoint, region := unmarshallAwsMetadata(*currentModel.AwsPrivateEndpointMetaData) if !isRequestInProgress(req) && createAndAssignAWSPrivateEndpoint { if region == nil { - return progressevents.GetFailedEventByCode("Error deleting aws private Endpoint region is null", cloudformation.HandlerErrorCodeServiceInternalError), nil + return progressevents.GetFailedEventByCode("Error deleting aws private Endpoint region is null", string(types.HandlerErrorCodeServiceInternalError)), nil } errPe := deleteAwsPrivateEndpoint(currentModel, *region, client, req) if errPe != nil { @@ -275,7 +275,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler Message: fmt.Sprintf("%s Completed", string(constants.DELETE)), }, nil } - return progressevents.GetFailedEventByCode(fmt.Sprintf("error deleting Serverless Private Endpoint %s", err.Error()), cloudformation.HandlerErrorCodeNotFound), nil + return progressevents.GetFailedEventByCode(fmt.Sprintf("error deleting Serverless Private Endpoint %s", err.Error()), string(types.HandlerErrorCodeNotFound)), nil } return progressevents.GetFailedEventByResponse(fmt.Sprintf("error deleting Serverless Private Endpoint %s", err.Error()), response), nil } @@ -338,7 +338,7 @@ func deleteAwsPrivateEndpoint(currentModel *Model, region string, client *util.M defer response.Body.Close() if err != nil { if isTenantPrivateEndpointNotFound(response) { - pe := progressevents.GetFailedEventByCode(fmt.Sprintf("error getting Serverless Private Endpoint %s", err.Error()), cloudformation.HandlerErrorCodeNotFound) + pe := progressevents.GetFailedEventByCode(fmt.Sprintf("error getting Serverless Private Endpoint %s", err.Error()), string(types.HandlerErrorCodeNotFound)) return &pe } pe := progressevents.GetFailedEventByResponse(fmt.Sprintf("error getting Serverless Private Endpoint %s", @@ -376,7 +376,7 @@ func createAtlasPrivateEndpoint(currentModel *Model, client *util.MongoDBClient) errPe := progressevents.GetFailedEventByCode( fmt.Sprintf("Error while trying to make api call, CreateServerlessPrivateEndpoint returned status %d, and the response is NULL", response.StatusCode), - cloudformation.HandlerErrorCodeInternalFailure) + string(types.HandlerErrorCodeInternalFailure)) return nil, &errPe } @@ -397,7 +397,7 @@ func assignAwsPrivateEndpoint(req handler.Request, client *util.MongoDBClient, a if err != nil { if isTenantPrivateEndpointNotFound(response) { - return progressevents.GetFailedEventByCode(fmt.Sprintf("error updating Serverless Private Endpoint %s", err.Error()), cloudformation.HandlerErrorCodeNotFound) + return progressevents.GetFailedEventByCode(fmt.Sprintf("error updating Serverless Private Endpoint %s", err.Error()), string(types.HandlerErrorCodeNotFound)) } return progressevents.GetFailedEventByResponse(fmt.Sprintf("error updating Serverless Private Endpoint %s", err.Error()), response) @@ -405,7 +405,7 @@ func assignAwsPrivateEndpoint(req handler.Request, client *util.MongoDBClient, a if serverlessPrivateEndpoint == nil { return progressevents.GetFailedEventByCode(fmt.Sprintf("Error while trying to make api call, CreateServerlessPrivateEndpoint returned status %d, and the response is NULL", response.StatusCode), - cloudformation.HandlerErrorCodeInternalFailure) + string(types.HandlerErrorCodeInternalFailure)) } callbackContext := req.CallbackContext @@ -467,12 +467,12 @@ func validateCompletion(req handler.Request, currentModel *Model, client *util.M if serverlessPrivateEndpoint == nil { return progressevents.GetFailedEventByCode(fmt.Sprintf("%s: Error while trying to make api call, CreateServerlessPrivateEndpoint returned status %d, and the response is NULL", string(cfnFunction), response.StatusCode), - cloudformation.HandlerErrorCodeInternalFailure) + string(types.HandlerErrorCodeInternalFailure)) } if serverlessPrivateEndpoint.Status == nil { return progressevents.GetFailedEventByCode(fmt.Sprintf("%s: Error while trying to get Serverless Private Endpoint, Private endpoint AtlasPrivateEndpointStatus is null", string(cfnFunction)), - cloudformation.HandlerErrorCodeServiceInternalError) + string(types.HandlerErrorCodeServiceInternalError)) } switch *serverlessPrivateEndpoint.Status { @@ -484,7 +484,7 @@ func validateCompletion(req handler.Request, currentModel *Model, client *util.M ResourceModel: currentModel} case string(enums.Failed): return progressevents.GetFailedEventByCode(fmt.Sprintf("%s : the serverless private endpoint is in a Failed AtlasPrivateEndpointStatus, error: %s", string(cfnFunction), - *serverlessPrivateEndpoint.ErrorMessage), cloudformation.HandlerErrorCodeServiceInternalError) + *serverlessPrivateEndpoint.ErrorMessage), string(types.HandlerErrorCodeServiceInternalError)) default: return progressevents.GetInProgressProgressEvent(fmt.Sprintf("%s in progress", string(cfnFunction)), getCallbackContext(privateEndpointID, serverlessPrivateEndpoint.EndpointServiceName), currentModel, callbackDelayInSeconds) @@ -521,22 +521,22 @@ func (currentModel *Model) validateAwsPrivateEndpointProperties() *handler.Progr if currentModel.AwsPrivateEndpointConfigurationProperties == nil { pe := progressevents.GetFailedEventByCode( "Validation failed: AwsPrivateEndpointConfigurationProperties must be present when CreateAndAssignAWSPrivateEndpoint is true", - cloudformation.HandlerErrorCodeInvalidRequest) + string(types.HandlerErrorCodeInvalidRequest)) return &pe } if currentModel.AwsPrivateEndpointConfigurationProperties.VpcId == nil { - pe := progressevents.GetFailedEventByCode("Validation failed: VpcId must be present when CreateAndAssignAWSPrivateEndpoint is true", cloudformation.HandlerErrorCodeInvalidRequest) + pe := progressevents.GetFailedEventByCode("Validation failed: VpcId must be present when CreateAndAssignAWSPrivateEndpoint is true", string(types.HandlerErrorCodeInvalidRequest)) return &pe } if currentModel.AwsPrivateEndpointConfigurationProperties.Region == nil { - pe := progressevents.GetFailedEventByCode("Validation failed: REgion must be present when CreateAndAssignAWSPrivateEndpoint is true", cloudformation.HandlerErrorCodeInvalidRequest) + pe := progressevents.GetFailedEventByCode("Validation failed: Region must be present when CreateAndAssignAWSPrivateEndpoint is true", string(types.HandlerErrorCodeInvalidRequest)) return &pe } if len(currentModel.AwsPrivateEndpointConfigurationProperties.SubnetIds) == 0 { - pe := progressevents.GetFailedEventByCode("Validation failed: SubnetIds must be present when CreateAndAssignAWSPrivateEndpoint is true", cloudformation.HandlerErrorCodeInvalidRequest) + pe := progressevents.GetFailedEventByCode("Validation failed: SubnetIds must be present when CreateAndAssignAWSPrivateEndpoint is true", string(types.HandlerErrorCodeInvalidRequest)) return &pe } } @@ -554,7 +554,7 @@ func getProcessStatus(req handler.Request) (enums.EventStatus, *handler.Progress if err != nil { pe := progressevents.GetFailedEventByCode(fmt.Sprintf("Error parsing callback status : %s", err.Error()), - cloudformation.HandlerErrorCodeServiceInternalError) + string(types.HandlerErrorCodeServiceInternalError)) return "", &pe } diff --git a/cfn-resources/stream-instance/cmd/resource/resource.go b/cfn-resources/stream-instance/cmd/resource/resource.go index e9eb3422c..e03d319d6 100644 --- a/cfn-resources/stream-instance/cmd/resource/resource.go +++ b/cfn-resources/stream-instance/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" @@ -220,7 +220,7 @@ 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 } return progressevent.GetFailedEventByResponse(errMsg, response), nil } diff --git a/cfn-resources/teams/cmd/resource/resource.go b/cfn-resources/teams/cmd/resource/resource.go index 4051a0999..5ffe46e1c 100644 --- a/cfn-resources/teams/cmd/resource/resource.go +++ b/cfn-resources/teams/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" teamuser "github.com/mongodb/mongodbatlas-cloudformation-resources/teams/cmd/resource/team-user" "github.com/mongodb/mongodbatlas-cloudformation-resources/util" "github.com/mongodb/mongodbatlas-cloudformation-resources/util/constants" @@ -202,7 +202,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(types.HandlerErrorCodeNotFound)}, nil } teamID := cast.ToString(currentModel.TeamId) @@ -246,7 +246,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Unable to update users", - HandlerErrorCode: cloudformation.HandlerErrorCodeInternalFailure, + HandlerErrorCode: string(types.HandlerErrorCodeInternalFailure), }, nil } @@ -340,14 +340,14 @@ 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(types.HandlerErrorCodeNotFound)}, nil } if currentModel.ProjectId != nil { if err := removeFromProject(atlasV2, currentModel); err != nil { return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Unable to Delete", - HandlerErrorCode: cloudformation.HandlerErrorCodeInternalFailure, + HandlerErrorCode: string(types.HandlerErrorCodeInternalFailure), }, nil } } @@ -359,7 +359,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Unable to Delete", - HandlerErrorCode: cloudformation.HandlerErrorCodeInternalFailure, + HandlerErrorCode: string(types.HandlerErrorCodeInternalFailure), }, nil } @@ -368,7 +368,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Unable to Delete from organization but successfully removed from project", - HandlerErrorCode: cloudformation.HandlerErrorCodeInternalFailure, + HandlerErrorCode: string(types.HandlerErrorCodeInternalFailure), }, nil } } diff --git a/cfn-resources/third-party-integration/cmd/resource/resource.go b/cfn-resources/third-party-integration/cmd/resource/resource.go index eafb37307..2b46f3b99 100644 --- a/cfn-resources/third-party-integration/cmd/resource/resource.go +++ b/cfn-resources/third-party-integration/cmd/resource/resource.go @@ -19,7 +19,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" log "github.com/mongodb/mongodbatlas-cloudformation-resources/util/logger" @@ -79,7 +79,7 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler integrations, resModel, err := client.Atlas20231115002.ThirdPartyIntegrationsApi.CreateThirdPartyIntegration(context.Background(), *IntegrationType, *ProjectID, requestBody).Execute() if err != nil { if apiError, ok := admin20231115002.AsError(err); ok && *apiError.Error == http.StatusConflict { - return progressevent.GetFailedEventByCode("INTEGRATION_ALREADY_CONFIGURED.", cloudformation.HandlerErrorCodeAlreadyExists), nil + return progressevent.GetFailedEventByCode("INTEGRATION_ALREADY_CONFIGURED.", string(types.HandlerErrorCodeAlreadyExists)), nil } return progressevent.GetFailedEventByResponse(err.Error(), resModel), nil diff --git a/cfn-resources/trigger/cmd/resource/resource.go b/cfn-resources/trigger/cmd/resource/resource.go index f630994e1..4c08d9fe6 100644 --- a/cfn-resources/trigger/cmd/resource/resource.go +++ b/cfn-resources/trigger/cmd/resource/resource.go @@ -22,8 +22,8 @@ import ( "log" "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-labs/go-client-mongodb-atlas-app-services/appservices" "github.com/mongodb/mongodbatlas-cloudformation-resources/profile" @@ -67,13 +67,13 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler client, err := util.GetAppServicesClient(ctx, req, currentModel.Profile) if err != nil { return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating App Services client : %s", err.Error()), - cloudformation.HandlerErrorCodeInvalidRequest), nil + string(types.HandlerErrorCodeInvalidRequest)), nil } eventTrigger, err := newEventTrigger(currentModel) if err != nil { return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating event trigger request : %s", err.Error()), - cloudformation.HandlerErrorCodeInvalidRequest), nil + string(types.HandlerErrorCodeInvalidRequest)), nil } et, resp, err := client.EventTriggers.Create(ctx, *currentModel.ProjectId, *currentModel.AppId, eventTrigger) if err != nil { @@ -92,7 +92,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P if currentModel.Id == nil { err := errors.New("no Id found in currentModel") return progressevents.GetFailedEventByCode(err.Error(), - cloudformation.HandlerErrorCodeNotFound), nil + string(types.HandlerErrorCodeNotFound)), nil } if errEvent := validateModel(ReadRequiredFields, currentModel); errEvent != nil { return *errEvent, nil @@ -103,7 +103,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P client, err := util.GetAppServicesClient(ctx, req, currentModel.Profile) if err != nil { return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating App Services client : %s", err.Error()), - cloudformation.HandlerErrorCodeInvalidRequest), nil + string(types.HandlerErrorCodeInvalidRequest)), nil } trigger, resp, err := client.EventTriggers.Get(ctx, *currentModel.ProjectId, *currentModel.AppId, *currentModel.Id) @@ -123,7 +123,7 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler if currentModel.Id == nil { err := errors.New("no Id found in currentModel") return progressevents.GetFailedEventByCode(err.Error(), - cloudformation.HandlerErrorCodeNotFound), nil + string(types.HandlerErrorCodeNotFound)), nil } if errEvent := validateModel(UpdateRequiredFields, currentModel); errEvent != nil { return *errEvent, nil @@ -134,13 +134,13 @@ func Update(req handler.Request, prevModel *Model, currentModel *Model) (handler client, err := util.GetAppServicesClient(ctx, req, currentModel.Profile) if err != nil { return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating App Services client : %s", err.Error()), - cloudformation.HandlerErrorCodeInvalidRequest), nil + string(types.HandlerErrorCodeInvalidRequest)), nil } eventTrigger, err := newEventTrigger(currentModel) if err != nil { return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating trigger request : %s", err.Error()), - cloudformation.HandlerErrorCodeInvalidRequest), nil + string(types.HandlerErrorCodeInvalidRequest)), nil } _, resp, err := client.EventTriggers.Update(ctx, *currentModel.ProjectId, *currentModel.AppId, *currentModel.Id, eventTrigger) if err != nil { @@ -158,7 +158,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler if currentModel.Id == nil { err := errors.New("no Id found in currentModel") return progressevents.GetFailedEventByCode(err.Error(), - cloudformation.HandlerErrorCodeNotFound), nil + string(types.HandlerErrorCodeNotFound)), nil } if errEvent := validateModel(DeleteRequiredFields, currentModel); errEvent != nil { return *errEvent, nil @@ -169,7 +169,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler client, err := util.GetAppServicesClient(ctx, req, currentModel.Profile) if err != nil { return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating App Services client : %s", err.Error()), - cloudformation.HandlerErrorCodeInvalidRequest), nil + string(types.HandlerErrorCodeInvalidRequest)), nil } resp, err := client.EventTriggers.Delete(ctx, *currentModel.ProjectId, *currentModel.AppId, *currentModel.Id) @@ -193,7 +193,7 @@ func List(req handler.Request, prevModel *Model, currentModel *Model) (handler.P client, err := util.GetAppServicesClient(ctx, req, currentModel.Profile) if err != nil { return progressevents.GetFailedEventByCode(fmt.Sprintf("Error creating App Services client : %s", err.Error()), - cloudformation.HandlerErrorCodeInvalidRequest), nil + string(types.HandlerErrorCodeInvalidRequest)), nil } triggers, resp, err := client.EventTriggers.List(ctx, *currentModel.ProjectId, *currentModel.AppId) @@ -250,8 +250,8 @@ func newEventTrigger(model *Model) (*appservices.EventTriggerRequest, error) { } conf.Project = m } - conf.Collection = aws.StringValue(dTrigger.Collection) - conf.ServiceID = aws.StringValue(dTrigger.ServiceId) + conf.Collection = aws.ToString(dTrigger.Collection) + conf.ServiceID = aws.ToString(dTrigger.ServiceId) conf.OperationTypes = dTrigger.OperationTypes conf.FullDocument = dTrigger.FullDocument conf.FullDocumentBeforeChange = dTrigger.FullDocumentBeforeChange diff --git a/cfn-resources/util/aws/utils.go b/cfn-resources/util/aws/utils.go index fab47b2e3..82e9d4515 100644 --- a/cfn-resources/util/aws/utils.go +++ b/cfn-resources/util/aws/utils.go @@ -15,18 +15,23 @@ package aws import ( + "context" "fmt" "strings" "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/service/cloudformation/types" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/ec2" + "github.com/aws/aws-sdk-go-v2/service/ec2" + ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util/awsconfig" progress_events "github.com/mongodb/mongodbatlas-cloudformation-resources/util/progressevent" ) -func newEc2Client(region string, req handler.Request) *ec2.EC2 { - return ec2.New(req.Session, aws.NewConfig().WithRegion(region)) +func newEc2Client(region string, req handler.Request) *ec2.Client { + cfg := awsconfig.FromHandlerRequest(&req) + cfg.Region = convertToAWSRegion(region) + return ec2.NewFromConfig(cfg) } type PrivateEndpointInput struct { @@ -49,25 +54,17 @@ func convertToAWSRegion(region string) string { func CreatePrivateEndpoint(req handler.Request, endpointServiceName string, region string, privateEndpointInputs []PrivateEndpointInput) ([]PrivateEndpointOutput, *handler.ProgressEvent) { svc := newEc2Client(convertToAWSRegion(region), req) - vcpType := "Interface" - subnetIDs := make([]PrivateEndpointOutput, len(privateEndpointInputs)) for i, pe := range privateEndpointInputs { - subnetIDsIn := make([]*string, len(pe.SubnetIDs)) - - for i := range pe.SubnetIDs { - subnetIDsIn[i] = &(pe.SubnetIDs[i]) - } - - connection := ec2.CreateVpcEndpointInput{ - VpcId: &pe.VpcID, - ServiceName: &endpointServiceName, - VpcEndpointType: &vcpType, - SubnetIds: subnetIDsIn, + connection := &ec2.CreateVpcEndpointInput{ + VpcId: aws.String(pe.VpcID), + ServiceName: aws.String(endpointServiceName), + VpcEndpointType: ec2types.VpcEndpointTypeInterface, + SubnetIds: pe.SubnetIDs, } - vpcE, err := svc.CreateVpcEndpoint(&connection) + vpcE, err := svc.CreateVpcEndpoint(context.Background(), connection) if err != nil { fpe := progress_events.GetFailedEventByCode(fmt.Sprintf("Error creating vcp Endpoint: %s", err.Error()), string(types.HandlerErrorCodeGeneralServiceException)) @@ -87,17 +84,11 @@ func CreatePrivateEndpoint(req handler.Request, endpointServiceName string, regi func DeletePrivateEndpoint(req handler.Request, interfaceEndpoints []string, region string) *handler.ProgressEvent { svc := newEc2Client(convertToAWSRegion(region), req) - vpcEndpointIDs := make([]*string, 0) - for i := range interfaceEndpoints { - vpcEndpointIDs = append(vpcEndpointIDs, &interfaceEndpoints[i]) - } - - connection := ec2.DeleteVpcEndpointsInput{ - DryRun: nil, - VpcEndpointIds: vpcEndpointIDs, + connection := &ec2.DeleteVpcEndpointsInput{ + VpcEndpointIds: interfaceEndpoints, } - _, err := svc.DeleteVpcEndpoints(&connection) + _, err := svc.DeleteVpcEndpoints(context.Background(), connection) if err != nil { fpe := progress_events.GetFailedEventByCode(fmt.Sprintf("Error deleting vcp Endpoint: %s", err.Error()), diff --git a/cfn-resources/util/secrets/secret_manager.go b/cfn-resources/util/secrets/secret_manager.go index 60a44638b..667478193 100644 --- a/cfn-resources/util/secrets/secret_manager.go +++ b/cfn-resources/util/secrets/secret_manager.go @@ -15,13 +15,15 @@ package secrets import ( + "context" "encoding/json" "log" "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" + "github.com/mongodb/mongodbatlas-cloudformation-resources/util/awsconfig" ) func Create(req *handler.Request, secretName string, data interface{}, description *string) (name *string, arn *string, err error) { @@ -32,14 +34,16 @@ func Create(req *handler.Request, secretName string, data interface{}, descripti // Create service client value configured for credentials // from assumed role. - svc := secretsmanager.New(req.Session) + cfg := awsconfig.FromHandlerRequest(req) + svc := secretsmanager.NewFromConfig(cfg) + input := &secretsmanager.CreateSecretInput{ Description: description, Name: aws.String(secretName), SecretString: aws.String(string(secretString)), } - 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. @@ -58,13 +62,15 @@ func PutSecret(req *handler.Request, secretName string, data interface{}, descri // Create service client value configured for credentials // from assumed role. - svc := secretsmanager.New(req.Session) + cfg := awsconfig.FromHandlerRequest(req) + svc := secretsmanager.NewFromConfig(cfg) + input := &secretsmanager.PutSecretValueInput{ SecretId: aws.String(secretName), SecretString: aws.String(string(secretString)), } - result, err := svc.PutSecretValue(input) + result, err := svc.PutSecretValue(context.Background(), input) if err != nil { // Print the error, cast err to awserr. Error to get the Code and // Message from an error. @@ -76,8 +82,10 @@ func PutSecret(req *handler.Request, secretName string, data interface{}, descri } func Get(req *handler.Request, secretName string) (name *string, arn *string, err 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: aws.String(secretName)}) if err != nil { log.Printf("Error --- %v", err.Error()) return nil, nil, err @@ -87,8 +95,13 @@ func Get(req *handler.Request, secretName string) (name *string, arn *string, er } func Delete(req *handler.Request, secretName string) (err error) { - sm := secretsmanager.New(req.Session) - _, err = sm.DeleteSecret(&secretsmanager.DeleteSecretInput{SecretId: &secretName, ForceDeleteWithoutRecovery: util.Pointer(true)}) + cfg := awsconfig.FromHandlerRequest(req) + sm := secretsmanager.NewFromConfig(cfg) + + _, err = sm.DeleteSecret(context.Background(), &secretsmanager.DeleteSecretInput{ + SecretId: aws.String(secretName), + ForceDeleteWithoutRecovery: util.Pointer(true), + }) if err != nil { log.Printf("error delete secret: %v", err.Error()) return err diff --git a/cfn-resources/x509-authentication-database-user/cmd/resource/resource.go b/cfn-resources/x509-authentication-database-user/cmd/resource/resource.go index c3f19b7b0..11d21cd6a 100644 --- a/cfn-resources/x509-authentication-database-user/cmd/resource/resource.go +++ b/cfn-resources/x509-authentication-database-user/cmd/resource/resource.go @@ -18,14 +18,15 @@ import ( "context" "errors" + 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/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.ProjectID, constants.UserID} @@ -56,10 +57,11 @@ 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(types.HandlerErrorCodeAlreadyExists)}, nil } - if expirationMonths := aws.IntValue(currentModel.MonthsUntilExpiration); expirationMonths > 0 { + if currentModel.MonthsUntilExpiration != nil && *currentModel.MonthsUntilExpiration > 0 { + expirationMonths := *currentModel.MonthsUntilExpiration cert := admin20231115002.NewUserCert() cert.MonthsUntilExpiration = &expirationMonths res, _, err := client.Atlas20231115002.X509AuthenticationApi.CreateDatabaseUserCertificate(context.Background(), *currentModel.ProjectId, *currentModel.UserName, cert).Execute() @@ -67,7 +69,7 @@ func Create(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 } if res != "" { currentModel.CustomerX509 = &CustomerX509{ @@ -81,7 +83,7 @@ func Create(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 } } @@ -114,7 +116,7 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "config is not available", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } currentModel.CustomerX509 = &CustomerX509{ @@ -153,7 +155,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "config is not available", - HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil + HandlerErrorCode: string(types.HandlerErrorCodeNotFound)}, nil } _, _, err = client.Atlas20231115002.X509AuthenticationApi.DisableCustomerManagedX509(context.Background(), *currentModel.ProjectId).Execute() @@ -161,7 +163,7 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler return handler.ProgressEvent{ OperationStatus: handler.Failed, Message: "Unable to Delete", - HandlerErrorCode: cloudformation.HandlerErrorCodeInternalFailure, + HandlerErrorCode: string(types.HandlerErrorCodeInternalFailure), }, nil }