Skip to content

Commit be161ea

Browse files
author
sivaram-mongodb
committed
feat: Add StreamWorkspace ClooudFormation resource
1 parent 6fd44b2 commit be161ea

28 files changed

+2435
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"artifact_type": "RESOURCE",
3+
"typeName": "MongoDB::Atlas::StreamWorkspace",
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": "MongoDB::Atlas::StreamWorkspace",
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/stream-workspace",
20+
"protocolVersion": "2.0.0"
21+
}
22+
}
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-inputs.sh
24+
25+
delete-test-resources:
26+
@echo "==> Delete test resources used for contract testing"
27+
./test/cfn-test-delete-inputs.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::StreamWorkspace
2+
3+
## Description
4+
5+
Resource for managing [Stream Workspaces](https://www.mongodb.com/docs/api/doc/atlas-admin-api-v2/group/endpoint-streams).
6+
7+
## Requirements
8+
9+
Set up an AWS profile to securely give CloudFormation access to your Atlas credentials.
10+
For instructions on setting up a profile, [see here](/README.md#mongodb-atlas-api-keys-credential-management).
11+
12+
## Attributes and Parameters
13+
14+
See the [resource docs](docs/README.md). Also refer [AWS security best practices for CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/security-best-practices.html#creds) to manage credentials.
15+
16+
## CloudFormation Examples
17+
18+
See the examples [CFN Template](/examples/stream-workspace/stream-workspace.json) for example resource.

cfn-resources/stream-workspace/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/stream-workspace/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.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
// Copyright 2025 MongoDB Inc
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package resource
16+
17+
import "go.mongodb.org/atlas-sdk/v20250312010/admin"
18+
19+
func NewStreamWorkspaceCreateReq(model *Model) *admin.StreamsTenant {
20+
if model == nil {
21+
return nil
22+
}
23+
dataProcessRegion := *model.DataProcessRegion
24+
streamTenant := &admin.StreamsTenant{
25+
Name: model.WorkspaceName,
26+
GroupId: model.ProjectId,
27+
DataProcessRegion: &admin.StreamsDataProcessRegion{
28+
CloudProvider: *dataProcessRegion.CloudProvider,
29+
Region: *dataProcessRegion.Region,
30+
},
31+
}
32+
if streamConfig := model.StreamConfig; streamConfig != nil {
33+
streamTenant.StreamConfig = &admin.StreamConfig{}
34+
if tier := streamConfig.Tier; tier != nil {
35+
streamTenant.StreamConfig.Tier = tier
36+
}
37+
if maxTierSize := streamConfig.MaxTierSize; maxTierSize != nil {
38+
streamTenant.StreamConfig.MaxTierSize = maxTierSize
39+
}
40+
}
41+
return streamTenant
42+
}
43+
44+
func newModelDataRegion(dataProcessRegion *admin.StreamsDataProcessRegion) *StreamsDataProcessRegion {
45+
return &StreamsDataProcessRegion{
46+
CloudProvider: &dataProcessRegion.CloudProvider,
47+
Region: &dataProcessRegion.Region,
48+
}
49+
}
50+
51+
func newModelStreamConfig(streamConfig *admin.StreamConfig) *StreamConfig {
52+
if streamConfig == nil {
53+
return nil
54+
}
55+
modelConfig := &StreamConfig{}
56+
if streamConfig.Tier != nil {
57+
modelConfig.Tier = streamConfig.Tier
58+
}
59+
if streamConfig.MaxTierSize != nil {
60+
modelConfig.MaxTierSize = streamConfig.MaxTierSize
61+
}
62+
return modelConfig
63+
}
64+
65+
func newModelDBRoleToExecute(dbRole *admin.DBRoleToExecute) *DBRoleToExecute {
66+
return &DBRoleToExecute{
67+
Role: dbRole.Role,
68+
Type: dbRole.Type,
69+
}
70+
}
71+
72+
func newModelAuthentication(authentication *admin.StreamsKafkaAuthentication) *StreamsKafkaAuthentication {
73+
return &StreamsKafkaAuthentication{
74+
Mechanism: authentication.Mechanism,
75+
Username: authentication.Username,
76+
}
77+
}
78+
79+
func newModelSecurity(security *admin.StreamsKafkaSecurity) *StreamsKafkaSecurity {
80+
return &StreamsKafkaSecurity{
81+
BrokerPublicCertificate: security.BrokerPublicCertificate,
82+
Protocol: security.Protocol,
83+
}
84+
}
85+
86+
func NewModelConnections(streamConfig *[]admin.StreamsConnection) []StreamsConnection {
87+
if streamConfig == nil || len(*streamConfig) == 0 {
88+
return nil
89+
}
90+
91+
connections := make([]StreamsConnection, 0)
92+
for _, connection := range *streamConfig {
93+
modelConnection := StreamsConnection{
94+
Name: connection.Name,
95+
Type: connection.Type,
96+
}
97+
if connection.GetType() == Kafka {
98+
modelConnection.BootstrapServers = connection.BootstrapServers
99+
modelConnection.Authentication = newModelAuthentication(connection.Authentication)
100+
modelConnection.Security = newModelSecurity(connection.Security)
101+
} else if connection.GetType() == Cluster {
102+
modelConnection.ClusterName = connection.ClusterName
103+
modelConnection.DbRoleToExecute = newModelDBRoleToExecute(connection.DbRoleToExecute)
104+
}
105+
connections = append(connections, modelConnection)
106+
}
107+
return connections
108+
}
109+
110+
func GetStreamWorkspaceModel(streamTenant *admin.StreamsTenant, currentModel *Model) *Model {
111+
model := new(Model)
112+
113+
if currentModel != nil {
114+
model = currentModel
115+
}
116+
117+
if streamTenant != nil {
118+
model.WorkspaceName = streamTenant.Name
119+
model.DataProcessRegion = newModelDataRegion(streamTenant.DataProcessRegion)
120+
model.StreamConfig = newModelStreamConfig(streamTenant.StreamConfig)
121+
model.ProjectId = streamTenant.GroupId
122+
model.Id = streamTenant.Id
123+
model.Hostnames = streamTenant.GetHostnames()
124+
model.Connections = NewModelConnections(streamTenant.Connections)
125+
}
126+
127+
return model
128+
}

0 commit comments

Comments
 (0)