Skip to content
Draft
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
52 changes: 51 additions & 1 deletion .github/workflows/contract-testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
serverless-private-endpoint: ${{ steps.filter.outputs.serverless-private-endpoint }}
stream-connection: ${{ steps.filter.outputs.stream-connection }}
stream-instance: ${{ steps.filter.outputs.stream-instance }}
trigger: ${{ steps.filter.outputs.trigger }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
if: ${{ github.event_name == 'push' }}
Expand Down Expand Up @@ -75,6 +76,8 @@ jobs:
- 'cfn-resources/stream-connection/**'
stream-instance:
- 'cfn-resources/stream-instance/**'
trigger:
- 'cfn-resources/trigger/**'
access-list-api-key:
needs: change-detection
if: ${{ needs.change-detection.outputs.access-list-api-key == 'true' }}
Expand Down Expand Up @@ -853,4 +856,51 @@ jobs:
make create-test-resources
cat inputs/inputs_1_create.json
make run-contract-testing
make delete-test-resources
make delete-test-resources
trigger:
needs: change-detection
if: ${{ needs.change-detection.outputs.trigger == 'true' }}
runs-on: ubuntu-latest
env:
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.CLOUD_DEV_PUBLIC_KEY }}
MONGODB_ATLAS_PRIVATE_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }}
MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }}
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}

FOLDER_PATH: cfn-resources/trigger
# Atlas Init CLI Terminal formatting
COLUMNS: 140
FORCE_COLOR: "yes"
TF_INPUT: "false"
NON_INTERACTIVE: "true"
# Atlas Init CLI Variables
ATLAS_INIT_CFN_PROFILE: profile-${{ github.run_id }}
ATLAS_INIT_CFN_REGION: "us-east-1"
ATLAS_INIT_CFN_USE_KMS_KEY: "false"
ATLAS_INIT_PROFILE: ${{ format('profile-{0}',github.run_id) }}
ATLAS_INIT_PROJECT_NAME: ${{ format('gh-ci-{0}', github.run_id) }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: aws-actions/setup-sam@2360ef6d90015369947b45b496193ab9976a9b04
with:
use-installer: true
- uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
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: us-east-1
- name: setup-atlas-init
uses: "EspenAlbert/atlas-init/.github/templates/external-setup@6ec12c3992b57f62e400bd8cdf98697fe244b532"
with:
version: "0.4.1"
tf-version: "1.10.2"
extra-pypi-packages: "cloudformation-cli cloudformation-cli-go-plugin setuptools"
go-version-file: 'cfn-resources/go.mod'
- name: run-atlas-init
uses: "EspenAlbert/atlas-init/.github/templates/external-run-with-tf@6ec12c3992b57f62e400bd8cdf98697fe244b532"
with:
cli-command: "cfn contract-test"
step-name: contract-test
cwd: ${{ env.FOLDER_PATH}}
profile-name: ${{ env.ATLAS_INIT_PROFILE }}
dry-run-first: "true"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ update.json
**/functions/packages
**/taskcat_outputs/
**/inputs/**
**/samples/**
pytestdebug.log
!/cdk/**/.*
*.DS_Store
Expand Down
10 changes: 10 additions & 0 deletions cfn-resources/trigger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ See the [resource docs](docs/README.md).
## Cloudformation Examples

See the examples [CFN Template](../../examples/trigger/trigger.json) for example resource.

## Development
```shell
uvx [email protected]
atlas-init init
cd cfn-resources/trigger
atlas-init apply
atlas-init cfn contract-test # use --help to see more options
atlas-init destroy
```
36 changes: 17 additions & 19 deletions cfn-resources/trigger/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,28 +229,26 @@ func newEventTrigger(model *Model) (*realm.EventTriggerRequest, error) {
conf.Database = *model.DatabaseTrigger.Database
}
dTrigger := model.DatabaseTrigger

if dTrigger.Match != nil {
jsonData := []byte(*dTrigger.Match)
// convert the JSON string to a map
var m interface{}
if err := json.Unmarshal(jsonData, &m); err != nil {
return nil, errors.New("error unmarshalling Match field - " + err.Error())
if dTrigger != nil {
if dTrigger.Match != nil {
jsonData := []byte(*dTrigger.Match)
// convert the JSON string to a map
var m interface{}
if err := json.Unmarshal(jsonData, &m); err != nil {
return nil, errors.New("error unmarshalling Match field - " + err.Error())
}
conf.Match = m
}
conf.Match = m
}

if dTrigger.Project != nil {
jsonData := []byte(*dTrigger.Project)
// convert the JSON string to a map
var m interface{}
if err := json.Unmarshal(jsonData, &m); err != nil {
return nil, errors.New("error unmarshalling Project field - " + err.Error())
if dTrigger.Project != nil {
jsonData := []byte(*dTrigger.Project)
// convert the JSON string to a map
var m interface{}
if err := json.Unmarshal(jsonData, &m); err != nil {
return nil, errors.New("error unmarshalling Project field - " + err.Error())
}
conf.Project = m
}
conf.Project = m
}

if dTrigger != nil {
conf.Collection = aws.StringValue(dTrigger.Collection)
conf.ServiceID = aws.StringValue(dTrigger.ServiceId)
conf.OperationTypes = dTrigger.OperationTypes
Expand Down
25 changes: 0 additions & 25 deletions cfn-resources/trigger/index.html

This file was deleted.

14 changes: 7 additions & 7 deletions cfn-resources/trigger/test/inputs_1_create.template.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"Name": "materializeMonthlyProductSales46",
"Name": "cfn-test-trigger-${RANDOM_INT_100K}",
"Type": "DATABASE",
"Profile": "default",
"Profile": "${MONGODB_ATLAS_PROFILE}",
"DatabaseTrigger": {
"OperationTypes": [
"INSERT"
],
"Database": "store",
"Collection": "sales",
"ServiceId": "6387aee08659af5254b0a51e",
"ServiceId": "${MONGODB_REALM_SERVICE_ID}",
"FullDocument": "true",
"FullDocumentBeforeChange": "false",
"Unordered": "false",
Expand All @@ -19,14 +19,14 @@
"EventProcessors": {
"FUNCTION": {
"FuncConfig": {
"FunctionName": "cfn_func",
"FunctionId": "63862553ac0702272aa701ba"
"FunctionName": "${MONGODB_REALM_FUNCTION_NAME}",
"FunctionId": "${MONGODB_REALM_FUNCTION_ID}"
}
},
"AWSEVENTBRIDGE": {
"AWSConfig": {}
}
},
"AppId": "638624a5167f5659feb75971",
"ProjectId": "625454459c4e6108393d650d"
"AppId": "${MONGODB_REALM_APP_ID}",
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}"
}
14 changes: 7 additions & 7 deletions cfn-resources/trigger/test/inputs_1_update.template.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"Name": "materializeMonthlyProductSales46",
"Name": "cfn-test-trigger-${RANDOM_INT_100K}",
"Type": "DATABASE",
"Profile": "default",
"Profile": "${MONGODB_ATLAS_PROFILE}",
"DatabaseTrigger": {
"OperationTypes": [
"INSERT"
],
"Database": "store",
"Collection": "sales",
"ServiceId": "6387aee08659af5254b0a51e",
"ServiceId": "${MONGODB_REALM_SERVICE_ID}",
"FullDocument": "true",
"FullDocumentBeforeChange": "false",
"Unordered": "false",
Expand All @@ -19,14 +19,14 @@
"EventProcessors": {
"FUNCTION": {
"FuncConfig": {
"FunctionName": "cfn_func",
"FunctionId": "63862553ac0702272aa701ba"
"FunctionName": "${MONGODB_REALM_FUNCTION_NAME}",
"FunctionId": "${MONGODB_REALM_FUNCTION_ID}"
}
},
"AWSEVENTBRIDGE": {
"AWSConfig": {}
}
},
"AppId": "638624a5167f5659feb75971",
"ProjectId": "625454459c4e6108393d650d"
"AppId": "${MONGODB_REALM_APP_ID}",
"ProjectId": "${MONGODB_ATLAS_PROJECT_ID}"
}
10 changes: 10 additions & 0 deletions cfn-resources/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"log"
"net/http"
"net/url"
"os"
"runtime"
"strconv"
Expand Down Expand Up @@ -109,6 +110,15 @@ func GetRealmClient(ctx context.Context, req handler.Request, profileName *strin

optsRealm := []realm.ClientOpt{realm.SetUserAgent(userAgent)}
authConfig := realmAuth.NewConfig(nil)

if p.BaseURL != "" {
if strings.Contains(p.BaseURL, "-dev.") {
adminURL := "https://services.cloud-dev.mongodb.com/api/admin/v3.0/"
optsRealm = append(optsRealm, realm.SetBaseURL(adminURL))
authConfig.AuthURL, _ = url.Parse(adminURL + "auth/providers/mongodb-cloud/login")
}
}

token, err := authConfig.NewTokenFromCredentials(ctx, p.PublicKey, p.PrivateKey)
if err != nil {
return nil, err
Expand Down
Loading