Skip to content

Commit e19a54e

Browse files
sivaram-mongodbsivaram-mongodb
andauthored
feat: CLOUDP-380107 add project service account resource (#1579)
Co-authored-by: sivaram-mongodb <sivaram@mongodb.com>
1 parent 47e0479 commit e19a54e

26 files changed

Lines changed: 1572 additions & 0 deletions

.github/workflows/contract-testing.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
privatelink-endpoint-service-data-federation-online-archive: ${{ steps.filter.outputs.privatelink-endpoint-service-data-federation-online-archive }}
3737
project: ${{ steps.filter.outputs.project }}
3838
project-service-account-secret: ${{ steps.filter.outputs.project-service-account-secret }}
39+
project-service-account: ${{ steps.filter.outputs.project-service-account }}
3940
resource-policy: ${{ steps.filter.outputs.resource-policy }}
4041
search-deployment: ${{ steps.filter.outputs.search-deployment }}
4142
search-index: ${{ steps.filter.outputs.search-index }}
@@ -102,6 +103,8 @@ jobs:
102103
- 'cfn-resources/project/**'
103104
project-service-account-secret:
104105
- 'cfn-resources/project-service-account-secret/**'
106+
project-service-account:
107+
- 'cfn-resources/project-service-account/**'
105108
resource-policy:
106109
- 'cfn-resources/resource-policy/**'
107110
search-deployment:
@@ -1105,6 +1108,7 @@ jobs:
11051108
11061109
make run-contract-testing
11071110
make delete-test-resources
1111+
11081112
project-service-account-secret:
11091113
needs: change-detection
11101114
if: ${{ needs.change-detection.outputs.project-service-account-secret == 'true' }}
@@ -1145,6 +1149,48 @@ jobs:
11451149
11461150
make run-contract-testing
11471151
make delete-test-resources
1152+
1153+
project-service-account:
1154+
needs: change-detection
1155+
if: ${{ needs.change-detection.outputs.project-service-account == 'true' }}
1156+
runs-on: ubuntu-latest
1157+
steps:
1158+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
1159+
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5
1160+
with:
1161+
go-version-file: 'cfn-resources/go.mod'
1162+
- name: setup Atlas CLI
1163+
uses: mongodb/atlas-github-action@e3c9e0204659bafbb3b65e1eb1ee745cca0e9f3b
1164+
- uses: aws-actions/setup-sam@d78e1a4a9656d3b223e59b80676a797f20093133
1165+
with:
1166+
use-installer: true
1167+
- uses: aws-actions/configure-aws-credentials@8df5847569e6427dd6c4fb1cf565c83acfa8afa7
1168+
with:
1169+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST_ENV }}
1170+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST_ENV }}
1171+
aws-region: eu-west-1
1172+
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405
1173+
with:
1174+
python-version: '3.9'
1175+
cache: 'pip' # caching pip dependencies
1176+
- run: pip install cloudformation-cli cloudformation-cli-go-plugin
1177+
- name: Run the Contract test
1178+
shell: bash
1179+
env:
1180+
MONGODB_ATLAS_PUBLIC_API_KEY: ${{ secrets.CLOUD_DEV_PUBLIC_KEY }}
1181+
MONGODB_ATLAS_PRIVATE_API_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }}
1182+
MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }}
1183+
MONGODB_ATLAS_OPS_MANAGER_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
1184+
MONGODB_ATLAS_PROFILE: cfn-cloud-dev-github-action
1185+
run: |
1186+
pushd cfn-resources/project-service-account
1187+
make create-test-resources
1188+
1189+
cat inputs/*
1190+
1191+
make run-contract-testing
1192+
make delete-test-resources
1193+
11481194
resource-policy:
11491195
needs: change-detection
11501196
if: ${{ needs.change-detection.outputs.resource-policy == 'true' }}
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::ProjectServiceAccount",
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/project-service-account",
20+
"protocolVersion": "2.0.0"
21+
},
22+
"canarySettings": {
23+
"contract_test_file_names": [
24+
"inputs_1.json"
25+
]
26+
}
27+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
clean:
19+
rm -rf bin
20+
21+
submit: clean build # submit to private registry must use release build not debug build
22+
@echo "==> Submitting to private registry for testing"
23+
cfn submit --set-default --region us-east-1
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
38+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# MongoDB::Atlas::ProjectServiceAccount
2+
3+
## Description
4+
5+
Resource for managing [Project Service Accounts](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/operation/operation-createprojectserviceaccount) for a MongoDB Atlas project. Project service accounts provide programmatic access to project-level resources and are used for automation, CI/CD pipelines, and service-to-service authentication within a specific project scope.
6+
7+
**Note:** Deleting this resource only unassigns the Service Account from the project, but doesn't delete it from the organization.
8+
9+
## Requirements
10+
11+
To securely give CloudFormation access to your Atlas credentials, you must
12+
set up an [AWS Profile](/README.md#mongodb-atlas-api-keys-credential-management).
13+
14+
## Attributes and Parameters
15+
16+
See the [resource docs](docs/README.md).
17+
18+
## Cloudformation Examples
19+
20+
See the examples [CFN Template](/examples/project-service-account/README.md) for example resource.

cfn-resources/project-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/project-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)