Skip to content

Commit 736315c

Browse files
author
Ciprian Tibulca
authored
CLOUDP-186602: add --tag flag to quickstart and setup commands (#2050)
1 parent ca01579 commit 736315c

File tree

9 files changed

+51
-0
lines changed

9 files changed

+51
-0
lines changed

docs/atlascli/command/atlas-quickstart.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Options
8989
-
9090
- false
9191
- Indicates whether to skip loading sample data into your Atlas cluster.
92+
* - --tag
93+
- stringToString
94+
- false
95+
- List that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the cluster. This value defaults to [].
9296
* - --tier
9397
- string
9498
- false

docs/atlascli/command/atlas-setup.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Options
8989
-
9090
- false
9191
- Indicates whether to skip loading sample data into your Atlas cluster.
92+
* - --tag
93+
- stringToString
94+
- false
95+
- List that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the cluster. This value defaults to [].
9296
* - --tier
9397
- string
9498
- false

docs/mongocli/command/mongocli-atlas-quickstart.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ Options
8989
-
9090
- false
9191
- Indicates whether to skip loading sample data into your Atlas cluster.
92+
* - --tag
93+
- stringToString
94+
- false
95+
- List that contains key-value pairs between 1 to 255 characters in length for tagging and categorizing the cluster. This value defaults to [].
9296
* - --tier
9397
- string
9498
- false

internal/cli/atlas/quickstart/cluster_setup.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func (opts *Opts) newCluster() *atlasv2.AdvancedClusterDescription {
112112
TerminationProtectionEnabled: &opts.EnableTerminationProtection,
113113
}
114114

115+
for k, v := range opts.Tag {
116+
cluster.Tags = append(cluster.Tags, atlasv2.ResourceTag{Key: pointer.Get(k), Value: pointer.Get(v)})
117+
}
118+
115119
if opts.providerName() != tenant {
116120
diskSizeGB := defaultDiskSizeGB(opts.providerName(), opts.Tier)
117121
mdbVersion, _ := cli.DefaultMongoDBMajorVersion()

internal/cli/atlas/quickstart/quick_start.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ type Opts struct {
118118
Confirm bool
119119
CurrentIP bool
120120
EnableTerminationProtection bool
121+
Tag map[string]string
121122
store store.AtlasClusterQuickStarter
122123
shouldRunLogin bool
123124
flags *pflag.FlagSet
@@ -135,6 +136,7 @@ type quickstart struct {
135136
EnableTerminationProtection bool
136137
SkipSampleData bool
137138
SkipMongosh bool
139+
Tag map[string]string
138140
}
139141

140142
type Flow interface {
@@ -456,6 +458,7 @@ func (opts *Opts) newDefaultValues() (*quickstart, error) {
456458

457459
values.Tier = opts.Tier
458460
values.EnableTerminationProtection = opts.EnableTerminationProtection
461+
values.Tag = opts.Tag
459462

460463
return values, nil
461464
}
@@ -488,6 +491,7 @@ func (opts *Opts) replaceWithDefaultSettings(values *quickstart) {
488491
opts.EnableTerminationProtection = values.EnableTerminationProtection
489492
opts.SkipSampleData = values.SkipSampleData
490493
opts.SkipMongosh = values.SkipMongosh
494+
opts.Tag = values.Tag
491495
}
492496

493497
func (opts *Opts) interactiveSetup() error {
@@ -565,6 +569,7 @@ func Builder() *cobra.Command {
565569
cmd.Flags().BoolVar(&opts.Confirm, flag.Force, false, usage.ForceQuickstart)
566570
cmd.Flags().BoolVar(&opts.CurrentIP, flag.CurrentIP, false, usage.CurrentIPSimplified)
567571
cmd.Flags().BoolVar(&opts.EnableTerminationProtection, flag.EnableTerminationProtection, false, usage.EnableTerminationProtection)
572+
cmd.Flags().StringToStringVar(&opts.Tag, flag.Tag, nil, usage.Tag)
568573

569574
cmd.Flags().StringVar(&opts.ProjectID, flag.ProjectID, "", usage.ProjectID)
570575

internal/cli/atlas/quickstart/quick_start_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func TestBuilder(t *testing.T) {
4949
flag.EnableTerminationProtection,
5050
flag.SkipMongosh,
5151
flag.SkipSampleData,
52+
flag.Tag,
5253
},
5354
)
5455
}
@@ -81,6 +82,7 @@ func TestQuickstartOpts_Run(t *testing.T) {
8182
SkipMongosh: true,
8283
SkipSampleData: true,
8384
Confirm: true,
85+
Tag: map[string]string{"env": "test"},
8486
}
8587
opts.WithFlow(mockFlow)
8688

internal/cli/atlas/setup/setup_cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ func Builder() *cobra.Command {
195195
cmd.Flags().BoolVar(&qsOpts.SkipMongosh, flag.SkipMongosh, false, usage.SkipMongosh)
196196
cmd.Flags().BoolVar(&qsOpts.Confirm, flag.Force, false, usage.Force)
197197
cmd.Flags().BoolVar(&qsOpts.CurrentIP, flag.CurrentIP, false, usage.CurrentIPSimplified)
198+
cmd.Flags().StringToStringVar(&qsOpts.Tag, flag.Tag, nil, usage.Tag)
198199

199200
cmd.Flags().StringVar(&qsOpts.ProjectID, flag.ProjectID, "", usage.ProjectID)
200201
_ = cmd.Flags().MarkHidden(flag.ProjectID)

internal/cli/atlas/setup/setup_cmd_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func TestBuilder(t *testing.T) {
4444
flag.Password,
4545
flag.SkipMongosh,
4646
flag.SkipSampleData,
47+
flag.Tag,
4748
},
4849
)
4950
}

test/e2e/atlas/setup_force_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/mongodb/mongodb-atlas-cli/test/e2e"
2727
"github.com/stretchr/testify/assert"
2828
"github.com/stretchr/testify/require"
29+
atlasv2 "go.mongodb.org/atlas-sdk/admin"
2930
"go.mongodb.org/atlas/mongodbatlas"
3031
)
3132

@@ -43,6 +44,9 @@ func TestSetup(t *testing.T) {
4344
dbUserUsername, err := RandUsername()
4445
req.NoError(err)
4546

47+
tagKey := "env"
48+
tagValue := "e2etest"
49+
4650
t.Run("Run", func(t *testing.T) {
4751
cmd := exec.Command(cliPath,
4852
"setup",
@@ -51,6 +55,7 @@ func TestSetup(t *testing.T) {
5155
"--skipMongosh",
5256
"--skipSampleData",
5357
"--projectId", g.projectID,
58+
"--tag", tagKey+"="+tagValue,
5459
"--force")
5560
cmd.Env = os.Environ()
5661
resp, err := cmd.CombinedOutput()
@@ -88,6 +93,27 @@ func TestSetup(t *testing.T) {
8893
assert.Equal(t, dbUserUsername, user.Username)
8994
})
9095

96+
t.Run("Describe Cluster", func(t *testing.T) {
97+
cmd := exec.Command(cliPath,
98+
clustersEntity,
99+
"describe",
100+
clusterName,
101+
"-o=json",
102+
"--projectId", g.projectID,
103+
)
104+
cmd.Env = os.Environ()
105+
resp, err := cmd.CombinedOutput()
106+
require.NoError(t, err, string(resp))
107+
108+
var cluster atlasv2.AdvancedClusterDescription
109+
require.NoError(t, json.Unmarshal(resp, &cluster), string(resp))
110+
assert.Equal(t, clusterName, *cluster.Name)
111+
112+
assert.Len(t, cluster.Tags, 1)
113+
assert.Equal(t, tagKey, *cluster.Tags[0].Key)
114+
assert.Equal(t, tagValue, *cluster.Tags[0].Value)
115+
})
116+
91117
t.Run("Delete Cluster", func(t *testing.T) {
92118
cmd := exec.Command(cliPath,
93119
clustersEntity,

0 commit comments

Comments
 (0)