Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 0 additions & 45 deletions .github/workflows/contract-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion cfn-resources/autogen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
maastha marked this conversation as resolved.
atlas clusters watch "${clusterName}" --projectId "${projectId}"
echo -e "Created Cluster \"${clusterName}\""
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
maastha marked this conversation as resolved.
atlas clusters watch "${clusterName}" --projectId "${projectId}"
echo -e "Created Cluster \"${clusterName}\""

Expand Down
8 changes: 4 additions & 4 deletions cfn-resources/database-user/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions cfn-resources/encryption-at-rest/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
maastha marked this conversation as resolved.
atlas clusters watch "${cluster1}" --projectId "${projectId}"
echo -e "Created Cluster \"${cluster1}\""
fi
Expand All @@ -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
Comment thread
maastha marked this conversation as resolved.
atlas clusters watch "${cluster2}" --projectId "${projectId}"
echo -e "Created Cluster \"${cluster2}\""
fi
Expand Down
10 changes: 5 additions & 5 deletions cfn-resources/federated-query-limit/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -132,15 +134,15 @@ 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 {
err := errors.New(RoleAssignementShouldBeSet)
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: err.Error(),
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
HandlerErrorCode: string(types.HandlerErrorCodeInvalidRequest)}, nil
}
// preparing model request
requestBody, _, _ := modelToRoleMappingRequest(currentModel)
Expand Down Expand Up @@ -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
Expand Down
18 changes: 9 additions & 9 deletions cfn-resources/global-cluster-config/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand All @@ -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()),
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
maastha marked this conversation as resolved.
atlas clusters watch "${ClusterName}" --projectId "${projectId}"
echo -e "Created Cluster \"${ClusterName}\""

Expand Down
Loading
Loading