Skip to content

Commit

Permalink
Move list of available instance types to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrique Santos committed Feb 6, 2024
1 parent 0123978 commit 44a4d0a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/cmd/mongodbflex/instance/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func NewCmd() *cobra.Command {
}

func configureFlags(cmd *cobra.Command) {
typeFlagOptions := []string{"Single", "Replica", "Sharded"}
typeFlagOptions := mongodbflexUtils.AvailableInstanceTypes()

cmd.Flags().StringP(instanceNameFlag, "n", "", "Instance name")
cmd.Flags().Var(flags.CIDRSliceFlag(), aclFlag, "The access control list (ACL). Must contain at least one valid subnet, for instance '0.0.0.0/0' for open access (discouraged), '1.2.3.0/24 for a public IP range of an organization, '1.2.3.4/32' for a single IP range, etc.")
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/mongodbflex/instance/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func NewCmd() *cobra.Command {
}

func configureFlags(cmd *cobra.Command) {
typeFlagOptions := []string{"Single", "Replica", "Sharded"}
typeFlagOptions := mongodbflexUtils.AvailableInstanceTypes()

cmd.Flags().StringP(instanceNameFlag, "n", "", "Instance name")
cmd.Flags().Var(flags.CIDRSliceFlag(), aclFlag, "List of IP networks in CIDR notation which are allowed to access this instance")
Expand Down
10 changes: 10 additions & 0 deletions internal/pkg/services/mongodbflex/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ func GetUserName(ctx context.Context, apiClient MongoDBFlexClient, projectId, in
return *resp.Item.Username, nil
}

func AvailableInstanceTypes() []string {
instanceTypes := make([]string, len(instanceTypeToReplicas))
i := 0
for k := range instanceTypeToReplicas {
instanceTypes[i] = k
i++
}
return instanceTypes
}

func GetInstanceReplicas(instanceType string) (int64, error) {
numReplicas, ok := instanceTypeToReplicas[instanceType]
if !ok {
Expand Down

0 comments on commit 44a4d0a

Please sign in to comment.