• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb / mongodb-atlas-cli / 26228926989

21 May 2026 01:27PM UTC coverage: 22.63% (-41.6%) from 64.198%
26228926989

push

github

apix-bot[bot]
Update compliance report for v1.55.0

8987 of 39713 relevant lines covered (22.63%)

0.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

29.03
/internal/cli/streams/instance/create.go
1
// Copyright 2023 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 instance
16

17
import (
18
        "context"
19
        "fmt"
20

21
        "github.com/mongodb/atlas-cli-core/config"
22
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
23
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli/require"
24
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/flag"
25
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/store"
26
        "github.com/mongodb/mongodb-atlas-cli/atlascli/internal/usage"
27
        "github.com/spf13/cobra"
28
        atlasv2 "go.mongodb.org/atlas-sdk/v20250312018/admin"
29
)
30

31
//go:generate go tool go.uber.org/mock/mockgen -typed -destination=create_mock_test.go -package=instance -source=create.go
32

33
type StreamsCreator interface {
34
        CreateStream(string, *atlasv2.StreamsTenant) (*atlasv2.StreamsTenant, error)
35
}
36

37
type CreateOpts struct {
38
        cli.ProjectOpts
39
        cli.OutputOpts
40
        cli.InputOpts
41
        name     string
42
        provider string
43
        region   string
44
        tier     string
45
        store    StreamsCreator
46
}
47

48
const (
49
        createTemplate = "Atlas Streams Processor Instance '{{.Name}}' successfully created.\n"
50
        defaultTier    = "SP30"
51
)
52

53
func (opts *CreateOpts) Run() error {
1✔
54
        streamProcessor := atlasv2.NewStreamsTenant()
1✔
55
        streamProcessor.Name = &opts.name
1✔
56
        streamProcessor.GroupId = &opts.ProjectID
1✔
57
        streamProcessor.DataProcessRegion = atlasv2.NewStreamsDataProcessRegion(opts.provider, opts.region)
1✔
58

1✔
59
        tierOrDefault := defaultTier
1✔
60
        if opts.tier != "" {
2✔
61
                tierOrDefault = opts.tier
1✔
62
        }
1✔
63
        streamConfig := streamProcessor.GetStreamConfig()
1✔
64
        streamConfig.Tier = &tierOrDefault
1✔
65
        streamProcessor.StreamConfig = &streamConfig
1✔
66

1✔
67
        r, err := opts.store.CreateStream(opts.ProjectID, streamProcessor)
1✔
68

1✔
69
        if err != nil {
1✔
70
                return err
×
71
        }
×
72

73
        return opts.Print(r)
1✔
74
}
75

76
func (opts *CreateOpts) initStore(ctx context.Context) func() error {
×
77
        return func() error {
×
78
                var err error
×
79
                opts.store, err = store.New(store.AuthenticatedPreset(config.Default()), store.WithContext(ctx))
×
80
                return err
×
81
        }
×
82
}
83

84
// CreateBuilder
85
// atlas streams instance create [name]
86
// --provider AWS
87
// --region VIRGINIA_USA.
88
func CreateBuilder() *cobra.Command {
×
89
        opts := &CreateOpts{}
×
90
        cmd := &cobra.Command{
×
91
                Use:   "create <name>",
×
92
                Short: "Create an Atlas Stream Processing instance for your project",
×
93
                Long:  `To get started quickly, specify a name, a cloud provider, and a region to configure an Atlas Stream Processing instance.` + fmt.Sprintf(usage.RequiredRole, "Project Owner"),
×
94
                Example: `  # Deploy an Atlas Stream Processing instance called myProcessor for the project with the ID 5e2211c17a3e5a48f5497de3:
×
95
  atlas streams instance create myProcessor --projectId 5e2211c17a3e5a48f5497de3 --provider AWS --region VIRGINIA_USA --tier SP30`,
×
96
                Args: require.ExactArgs(1),
×
97
                Annotations: map[string]string{
×
98
                        "nameDesc": "Name of the Atlas Stream Processing instance. After creation, you can't change the name of the instance. The name can contain ASCII letters, numbers, and hyphens.",
×
99
                        "output":   createTemplate,
×
100
                },
×
101
                PreRunE: func(cmd *cobra.Command, args []string) error {
×
102
                        opts.name = args[0]
×
103
                        return opts.PreRunE(
×
104
                                opts.ValidateProjectID,
×
105
                                opts.initStore(cmd.Context()),
×
106
                                opts.InitOutput(cmd.OutOrStdout(), createTemplate),
×
107
                        )
×
108
                },
×
109
                RunE: func(_ *cobra.Command, _ []string) error {
×
110
                        return opts.Run()
×
111
                },
×
112
        }
113

114
        cmd.Flags().StringVar(&opts.provider, flag.Provider, "AWS", usage.StreamsProvider)
×
115
        cmd.Flags().StringVarP(&opts.region, flag.Region, flag.RegionShort, "", usage.StreamsRegion)
×
116

×
117
        opts.AddProjectOptsFlags(cmd)
×
118
        opts.AddOutputOptFlags(cmd)
×
119

×
120
        cmd.Flags().StringVar(&opts.tier, flag.Tier, "SP30", usage.StreamsInstanceTier)
×
121

×
122
        _ = cmd.MarkFlagRequired(flag.Provider)
×
123
        _ = cmd.MarkFlagRequired(flag.Region)
×
124

×
125
        return cmd
×
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc