Skip to content

Commit 18f8556

Browse files
sivaram-mongodbsivaram-mongodboutcomes-winter-rakhulsprakashParthasarathyV
authored
feat: Backup Compliance Policy CloudFormation Resource (#1535)
Co-authored-by: sivaram-mongodb <sivaram@mongodb.com> Co-authored-by: Rakhul S Prakash <rakhul.s.prakash@peerislands.io> Co-authored-by: ParthasarathyV <parthasarathy.varadhan@mongodb.com>
1 parent 96caea4 commit 18f8556

27 files changed

Lines changed: 2189 additions & 1 deletion

.github/workflows/contract-testing.yaml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
alert-configuration: ${{ steps.filter.outputs.alert-configuration }}
1616
api-key: ${{ steps.filter.outputs.api-key }}
1717
auditing: ${{ steps.filter.outputs.auditing }}
18+
backup-compliance-policy: ${{ steps.filter.outputs.backup-compliance-policy }}
1819
cloud-backup-restore-jobs: ${{ steps.filter.outputs.cloud-backup-restore-jobs }}
1920
cluster-outage-simulation: ${{ steps.filter.outputs.cluster-outage-simulation }}
2021
federated-database-instance: ${{ steps.filter.outputs.federated-database-instance }}
@@ -48,6 +49,8 @@ jobs:
4849
- 'cfn-resources/api-key/**'
4950
auditing:
5051
- 'cfn-resources/auditing/**'
52+
backup-compliance-policy:
53+
- 'cfn-resources/backup-compliance-policy/**'
5154
cloud-backup-restore-jobs:
5255
- 'cfn-resources/cloud-backup-restore-jobs/**'
5356
cluster-outage-simulation:
@@ -243,7 +246,48 @@ jobs:
243246
cat inputs/inputs_1_update.json
244247
cat inputs/inputs_2_create.json
245248
cat inputs/inputs_2_update.json
246-
249+
250+
make run-contract-testing
251+
make delete-test-resources
252+
backup-compliance-policy:
253+
needs: change-detection
254+
if: ${{ needs.change-detection.outputs.backup-compliance-policy == 'true' }}
255+
runs-on: ubuntu-latest
256+
steps:
257+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
258+
- uses: actions/setup-go@7a3fe6cf4cb3a834922a1244abfce67bcef6a0c5
259+
with:
260+
go-version-file: 'cfn-resources/go.mod'
261+
- name: setup Atlas CLI
262+
uses: mongodb/atlas-github-action@e3c9e0204659bafbb3b65e1eb1ee745cca0e9f3b
263+
- uses: aws-actions/setup-sam@c2a20b1822cc4a6bc594ff7f1dbb658758e383c3
264+
with:
265+
use-installer: true
266+
- uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708
267+
with:
268+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID_TEST_ENV }}
269+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY_TEST_ENV }}
270+
aws-region: eu-west-1
271+
- uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548
272+
with:
273+
python-version: '3.9'
274+
cache: 'pip' # caching pip dependencies
275+
- run: pip install cloudformation-cli cloudformation-cli-go-plugin
276+
- name: Run the Contract test
277+
shell: bash
278+
env:
279+
MONGODB_ATLAS_PUBLIC_API_KEY: ${{ secrets.CLOUD_DEV_PUBLIC_KEY }}
280+
MONGODB_ATLAS_PRIVATE_API_KEY: ${{ secrets.CLOUD_DEV_PRIVATE_KEY }}
281+
MONGODB_ATLAS_ORG_ID: ${{ secrets.CLOUD_DEV_ORG_ID }}
282+
MONGODB_ATLAS_OPS_MANAGER_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
283+
MONGODB_ATLAS_PROFILE: cfn-cloud-dev-github-action
284+
run: |
285+
cd cfn-resources/backup-compliance-policy
286+
make create-test-resources
287+
288+
cat inputs/inputs_1_create.json
289+
cat inputs/inputs_1_update.json
290+
247291
make run-contract-testing
248292
make delete-test-resources
249293
cloud-backup-restore-jobs:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"typeName": "MongoDB::Atlas::BackupCompliancePolicy",
3+
"language": "go",
4+
"runtime": "provided.al2",
5+
"entrypoint": "bootstrap",
6+
"testEntrypoint": "bootstrap",
7+
"settings": {
8+
"import_path": "github.com/mongodb/mongodbatlas-cloudformation-resources/backup-compliance-policy",
9+
"protocolVersion": "2.0.0",
10+
"pluginVersion": "2.0.4"
11+
}
12+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
.PHONY: build test clean
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+
create-test-resources:
22+
@echo "==> Creating test files for contract testing"
23+
./test/contract-testing/cfn-test-create.sh
24+
25+
delete-test-resources:
26+
@echo "==> Delete test resources used for contract testing"
27+
./test/contract-testing/cfn-test-delete.sh
28+
29+
run-contract-testing:
30+
@echo "==> Run contract testing"
31+
make build
32+
sam local start-lambda &
33+
cfn test --function-name TestEntrypoint --verbose
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# MongoDB::Atlas::BackupCompliancePolicy
2+
3+
## Description
4+
5+
Resource for managing [Backup Compliance Policy](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-cloud-backups/operation/updateCompliancePolicy). Backup Compliance Policy prevents any user, regardless of role, from modifying or deleting specific cluster settings, backups, and backup configurations. When enabled, the Backup Compliance Policy will be applied as the minimum policy for all clusters and backups in the project.
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/backup-compliance-policy/README.md) for example resource.

cfn-resources/backup-compliance-policy/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/backup-compliance-policy/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)