Skip to content

Commit 34ad12b

Browse files
sivaram-mongodbsivaram-mongodboutcomes-winter-rakhulsprakashParthasarathyV
authored
feat: Service Account CloudFormation Resource (#1525)
Co-authored-by: sivaram-mongodb <sivaram@mongodb.com> Co-authored-by: Rakhul S Prakash <rakhul.s.prakash@peerislands.io> Co-authored-by: ParthasarathyV <114770988+ParthasarathyV@users.noreply.github.com> Co-authored-by: ParthasarathyV <parthasarathy.varadhan@mongodb.com>
1 parent b075c56 commit 34ad12b

24 files changed

Lines changed: 1550 additions & 1 deletion

.github/workflows/contract-testing.yaml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ jobs:
2222
flex-cluster: ${{ steps.filter.outputs.flex-cluster }}
2323
online-archive: ${{ steps.filter.outputs.online-archive }}
2424
organization: ${{ steps.filter.outputs.organization }}
25+
service-account: ${{ steps.filter.outputs.service-account }}
2526
private-endpoint-aws: ${{ steps.filter.outputs.private-endpoint-aws }}
2627
private-endpoint-service: ${{ steps.filter.outputs.private-endpoint-service }}
2728
privatelink-endpoint-service-data-federation-online-archive: ${{ steps.filter.outputs.privatelink-endpoint-service-data-federation-online-archive }}
@@ -61,6 +62,8 @@ jobs:
6162
- 'cfn-resources/online-archive/**'
6263
organization:
6364
- 'cfn-resources/organization/**'
65+
service-account:
66+
- 'cfn-resources/service-account/**'
6467
private-endpoint-aws:
6568
- 'cfn-resources/private-endpoint-aws/**'
6669
private-endpoint-service:
@@ -525,7 +528,48 @@ jobs:
525528
run: |
526529
pushd cfn-resources/organization
527530
make create-test-resources
528-
531+
532+
cat inputs/inputs_1_create.json
533+
cat inputs/inputs_1_update.json
534+
535+
make run-contract-testing
536+
make delete-test-resources
537+
service-account:
538+
needs: change-detection
539+
if: ${{ needs.change-detection.outputs.service-account == 'true' }}
540+
runs-on: ubuntu-latest
541+
steps:
542+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
543+
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5
544+
with:
545+
go-version-file: 'cfn-resources/go.mod'
546+
- name: setup Atlas CLI
547+
uses: mongodb/atlas-github-action@e3c9e0204659bafbb3b65e1eb1ee745cca0e9f3b
548+
- uses: aws-actions/setup-sam@c2a20b1822cc4a6bc594ff7f1dbb658758e383c3
549+
with:
550+
use-installer: true
551+
- uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708
552+
with:
553+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST_ENV }}
554+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST_ENV }}
555+
aws-region: eu-west-1
556+
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548
557+
with:
558+
python-version: '3.9'
559+
cache: 'pip' # caching pip dependencies
560+
- run: pip install cloudformation-cli cloudformation-cli-go-plugin
561+
- name: Run the Contract test
562+
shell: bash
563+
env:
564+
MONGODB_ATLAS_PUBLIC_API_KEY: ${{ secrets.CLOUD_DEV_PUBLIC_KEY }}
565+
MONGODB_ATLAS_PRIVATE_API_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }}
566+
MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }}
567+
MONGODB_ATLAS_OPS_MANAGER_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
568+
MONGODB_ATLAS_PROFILE: cfn-cloud-dev-github-action
569+
run: |
570+
cd cfn-resources/service-account
571+
make create-test-resources
572+
529573
cat inputs/inputs_1_create.json
530574
cat inputs/inputs_1_update.json
531575
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"artifact_type": "RESOURCE",
3+
"typeName": "MongoDB::Atlas::ServiceAccount",
4+
"language": "go",
5+
"runtime": "provided.al2",
6+
"entrypoint": "bootstrap",
7+
"testEntrypoint": "bootstrap",
8+
"settings": {
9+
"version": false,
10+
"subparser_name": null,
11+
"verbose": 0,
12+
"force": false,
13+
"type_name": null,
14+
"artifact_type": null,
15+
"endpoint_url": null,
16+
"region": null,
17+
"target_schemas": [],
18+
"profile": null,
19+
"import_path": "github.com/mongodb/mongodbatlas-cloudformation-resources/service-account",
20+
"protocolVersion": "2.0.0"
21+
},
22+
"canarySettings": {
23+
"contract_test_file_names": [
24+
"inputs_1.json"
25+
]
26+
}
27+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
.PHONY: build test clean debug create-test-resources delete-test-resources run-contract-testing
2+
tags=logging callback metrics scheduler
3+
cgo=0
4+
goos=linux
5+
goarch=amd64
6+
CFNREP_GIT_SHA?=$(shell git rev-parse HEAD)
7+
ldXflags=-s -w -X github.com/mongodb/mongodbatlas-cloudformation-resources/util.defaultLogLevel=info -X github.com/mongodb/mongodbatlas-cloudformation-resources/version.Version=${CFNREP_GIT_SHA}
8+
ldXflagsD=-X github.com/mongodb/mongodbatlas-cloudformation-resources/util.defaultLogLevel=debug -X github.com/mongodb/mongodbatlas-cloudformation-resources/version.Version=${CFNREP_GIT_SHA}
9+
10+
build:
11+
cfn generate
12+
env GOOS=$(goos) CGO_ENABLED=$(cgo) GOARCH=$(goarch) go build -ldflags="$(ldXflags)" -tags="$(tags)" -o bin/bootstrap cmd/main.go
13+
14+
debug:
15+
cfn generate
16+
env GOOS=$(goos) CGO_ENABLED=$(cgo) GOARCH=$(goarch) go build -ldflags="$(ldXflagsD)" -tags="$(tags)" -o bin/bootstrap cmd/main.go
17+
18+
test:
19+
cfn generate
20+
env GOOS=$(goos) go build -ldflags="-s -w" -tags="$(tags)" -o bin/bootstrap cmd/main.go
21+
22+
clean:
23+
rm -rf bin
24+
25+
create-test-resources:
26+
@echo "==> Creating test files and resources for contract testing"
27+
./test/contract-testing/cfn-test-create.sh
28+
29+
delete-test-resources:
30+
@echo "==> Delete test resources used for contract testing"
31+
./test/contract-testing/cfn-test-delete.sh
32+
33+
run-contract-testing:
34+
@echo "==> Run contract testing"
35+
make build
36+
sam local start-lambda &
37+
cfn test --function-name TestEntrypoint --verbose
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# MongoDB::Atlas::ServiceAccount
2+
3+
## Description
4+
5+
Resource for managing [Service Accounts](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-service-accounts) for a MongoDB Atlas organization. Service accounts provide programmatic access to MongoDB Atlas resources and are used for automation, CI/CD pipelines, and service-to-service authentication.
6+
7+
## Requirements
8+
9+
To securely give CloudFormation access to your Atlas credentials, you must
10+
set up an [AWS Profile](/README.md#mongodb-atlas-api-keys-credential-management).
11+
12+
## Attributes and Parameters
13+
14+
See the [resource docs](docs/README.md).
15+
16+
## Cloudformation Examples
17+
18+
See the examples [CFN Template](/examples/service-account/README.md) for example resource.
19+

cfn-resources/service-account/cmd/main.go

Lines changed: 85 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cfn-resources/service-account/cmd/resource/config.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)