Skip to content

CLOUDP-333877: create stub for atlas cli commands streams workspaces and streams workspaces create #4057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 53 additions & 7 deletions internal/cli/streams/instance/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ type CreateOpts struct {
cli.ProjectOpts
cli.OutputOpts
cli.InputOpts
name string
provider string
region string
tier string
store StreamsCreator
name string
provider string
region string
tier string
defaultTier string
maxTierSize string
store StreamsCreator
}

const (
createTemplate = "Atlas Streams Processor Instance '{{.Name}}' successfully created.\n"
defaultTier = "SP30"
createTemplate = "Atlas Streams Processor Instance '{{.Name}}' successfully created.\n"
createWorkspace = "Atlas Streams Processor Workspace '{{.Name}}' successfully created.\n"
defaultTier = "SP30"
)

func (opts *CreateOpts) Run() error {
Expand Down Expand Up @@ -124,3 +127,46 @@ func CreateBuilder() *cobra.Command {

return cmd
}

func WorkspaceCreateBuilder() *cobra.Command {
opts := &CreateOpts{}
cmd := &cobra.Command{
Use: "create <name>",
Short: "Create an Atlas Stream Processing workspace for your project",
Long: `To get started quickly, specify a name, a cloud provider, and a region to configure an Atlas Stream Processing workspace.` + fmt.Sprintf(usage.RequiredRole, "Project Owner"),
Example: ` # Deploy an Atlas Stream Processing workspace called myProcessor for the project with the ID 5e2211c17a3e5a48f5497de3:
atlas streams instance create myProcessor --projectId 5e2211c17a3e5a48f5497de3 --provider AWS --region VIRGINIA_USA --tier SP10 --defaultTier SP30 --maxTierSize SP50`,
Args: require.ExactArgs(1),
Annotations: map[string]string{
"nameDesc": "Name of the Atlas Stream Processing workspace. After creation, you can't change the name of the workspace. The name can contain ASCII letters, numbers, and hyphens.",
"output": createWorkspace,
},
PreRunE: func(cmd *cobra.Command, args []string) error {
opts.name = args[0]

return opts.PreRunE(
opts.ValidateProjectID,
opts.initStore(cmd.Context()),
opts.InitOutput(cmd.OutOrStdout(), createWorkspace),
)
},
RunE: func(_ *cobra.Command, _ []string) error {
return opts.Run()
},
}

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

opts.AddProjectOptsFlags(cmd)
opts.AddOutputOptFlags(cmd)

cmd.Flags().StringVar(&opts.tier, flag.Tier, "SP30", usage.StreamsWorkspaceTier)
cmd.Flags().StringVar(&opts.defaultTier, flag.DefaultTier, "", usage.StreamsWorkspaceDefaultTier)
cmd.Flags().StringVar(&opts.maxTierSize, flag.MaxTierSize, "", usage.StreamsWorkspaceMaxTierSize)

_ = cmd.MarkFlagRequired(flag.Provider)
_ = cmd.MarkFlagRequired(flag.Region)

return cmd
}
69 changes: 69 additions & 0 deletions internal/cli/streams/instance/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,73 @@ func TestCreateOpts_Run(t *testing.T) {
t.Log(buf.String())
test.VerifyOutputTemplate(t, createTemplate, expected)
})

t.Run("stream workspaces create --tier", func(t *testing.T) {
buf := new(bytes.Buffer)
opts := &CreateOpts{
store: mockStore,
name: "ExampleStreamWorkspaces",
provider: "AWS",
region: "VIRGINIA_USA",
tier: "SP30",
}
opts.ProjectID = testProjectID

expected := &atlasv2.StreamsTenant{
Name: &opts.name,
GroupId: &opts.ProjectID,
DataProcessRegion: &atlasv2.StreamsDataProcessRegion{CloudProvider: "AWS", Region: "VIRGINIA_USA"},
StreamConfig: &atlasv2.StreamConfig{
Tier: &opts.tier,
},
}

mockStore.
EXPECT().
CreateStream(opts.ProjectID, expected).
Return(expected, nil).
Times(1)

if err := opts.Run(); err != nil {
t.Fatalf("Run() unexpected error: %v", err)
}
t.Log(buf.String())
test.VerifyOutputTemplate(t, createWorkspace, expected)
})

// Testing the parsing of flags but not passing into StreamConfig object
t.Run("stream workspaces create --tier --defaultTier --maxTierSize", func(t *testing.T) {
buf := new(bytes.Buffer)
opts := &CreateOpts{
store: mockStore,
name: "ExampleStreamWorkspaces",
provider: "AWS",
region: "VIRGINIA_USA",
tier: "SP30",
defaultTier: "SP30",
maxTierSize: "SP50",
}
opts.ProjectID = testProjectID

expected := &atlasv2.StreamsTenant{
Name: &opts.name,
GroupId: &opts.ProjectID,
DataProcessRegion: &atlasv2.StreamsDataProcessRegion{CloudProvider: "AWS", Region: "VIRGINIA_USA"},
StreamConfig: &atlasv2.StreamConfig{
Tier: &opts.tier,
},
}

mockStore.
EXPECT().
CreateStream(opts.ProjectID, expected).
Return(expected, nil).
Times(1)

if err := opts.Run(); err != nil {
t.Fatalf("Run() unexpected error: %v", err)
}
t.Log(buf.String())
test.VerifyOutputTemplate(t, createWorkspace, expected)
})
}
33 changes: 33 additions & 0 deletions internal/cli/streams/instance/workspaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2023 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package instance

import (
"github.com/mongodb/mongodb-atlas-cli/atlascli/internal/cli"
"github.com/spf13/cobra"
)

func WorkspaceBuilder() *cobra.Command {
const use = "workspaces"
cmd := &cobra.Command{
Use: use,
Aliases: cli.GenerateAliases(use),
Short: "Manage Atlas Stream Processing workspaces.",
Long: `Create, list, update, and delete your Atlas Stream Processing workspaces.`,
}
cmd.AddCommand(WorkspaceCreateBuilder())

return cmd
}
2 changes: 2 additions & 0 deletions internal/flag/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const (
MembersShort = "m" // MembersShort flag
ShardsShort = "s" // ShardsShort flag
Tier = "tier" // Tier flag
DefaultTier = "defaultTier" // DefaultTier flag
MaxTierSize = "maxTierSize" // MaxTierSize flag
Forever = "forever" // Forever flag
ForeverShort = "F" // ForeverShort flag
DiskSizeGB = "diskSizeGB" // DiskSizeGB flag
Expand Down
4 changes: 4 additions & 0 deletions internal/usage/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,13 @@ dbName and collection are required only for built-in roles.`
StreamsRegion = "Human-readable label that identifies the physical location of your Atlas Stream Processing instance. The region can affect network latency and performance if it is far from your source or sink. For AWS, region name must be in the following format: VIRGINIA_USA. For a list of valid values, see https://www.mongodb.com/docs/atlas/reference/amazon-aws/#std-label-aws-stream-processing-regions. For Azure, region name must be in the following format: eastus. For a list of valid values, see https://www.mongodb.com/docs/atlas/reference/microsoft-azure/#std-label-azure-stream-processing-regions."
StreamsProvider = "Cloud service provider that applies to the provisioned Atlas Stream Processing instance. Valid values are AWS or AZURE."
StreamsInstance = "Name of your Atlas Stream Processing instance."
StreamsWorkspace = "Name of your Atlas Stream Procesing workspace."
StreamsConnectionFilename = "Path to a JSON configuration file that defines an Atlas Stream Processing connection. Note: Unsupported fields in the JSON file are ignored."
StreamsPrivateLinkFilename = "Path to a JSON configuration file that defines an Atlas Stream Processing PrivateLink endpoint. Note: Unsupported fields in the JSON file are ignored."
StreamsInstanceTier = "Tier for your Stream Instance."
StreamsWorkspaceTier = "Tier for your Stream Workspace."
StreamsWorkspaceDefaultTier = "Default Tier for your Stream Workspace."
StreamsWorkspaceMaxTierSize = "Max Tier Size for your Stream Workspace."
WithoutDefaultAlertSettings = "Flag that creates the new project without the default alert settings enabled. This flag defaults to false. This option is useful if you create projects programmatically and want to create your own alerts instead of using the default alert settings."
FormatOut = "Output format. Valid values are json, json-path, go-template, or go-template-file. To see the full output, use the -o json option."
TargetClusterName = "Name of the target cluster. For use only with automated restore jobs. You must specify a targetClusterName for automated restores."
Expand Down
Loading