Skip to content

Commit 8fb5863

Browse files
committed
Confirm user is happy to deploy free/paid cluster
1 parent 3ec0d15 commit 8fb5863

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

docs/commands/clusters.adoc

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ If used with no definition or flag values provided a free tier cluster with sens
4848
```
4949
👤 Charlie 🏠 remote in ☁️ default._default._default
5050
> clusters create
51-
[INFO] 2025-07-04 11:35:41.392 provider not specified, defaulting to aws
52-
[INFO] 2025-07-04 11:35:41.392 cluster name not specified, a randomly generated name will be used
53-
[INFO] 2025-07-04 11:35:41.392 region not specified, defaulting to us-east-2
51+
[INFO] 2025-07-07 09:11:21.628 provider not specified, defaulting to aws
52+
[INFO] 2025-07-07 09:11:21.628 cluster name not specified, a randomly generated name will be used
53+
[INFO] 2025-07-07 09:11:21.628 region not specified, defaulting to us-east-2
54+
[WARN] 2025-07-07 09:11:21.628 this configuration will create a FREE cluster, is this okay? (y/n)
55+
y
5456
👤 Charlie 🏠 remote in ☁️ default._default._default
5557
> clusters
5658
╭───┬────────────────────────┬──────────────────────────────────────┬───────────┬───────────────────────────╮
@@ -64,16 +66,26 @@ If used with no definition or flag values provided a free tier cluster with sens
6466
╰───┴────────────────────────┴──────────────────────────────────────┴───────────┴───────────────────────────╯
6567
```
6668
67-
Free clusters clusters are limited in how they can be customised, and only the name, description, cloud provider, region and cidr can be configured.
69+
Before your cluster is created cbshell will tell you if the configuration will result in a free-tier or paid cluster, and as for confirmation:
70+
71+
```
72+
[WARN] 2025-07-07 09:11:21.628 this configuration will create a FREE cluster, is this okay? (y/n)
73+
y
74+
```
75+
76+
Free clusters are limited in how they can be customised, and only the name, description, cloud provider, region and cidr can be configured.
6877
Check the https://docs.couchbase.com/cloud/management-api-reference/index.html#tag/Free-Tier[Capella API docs] for more information.
6978
You can configure all of these fields with the relevant flags:
7079
7180
```
7281
👤 Charlie 🏠 remote in ☁️ default._default._default
7382
> clusters create --name free-gcp --description "My first couchbase cluster" --cidr 10.0.0.0/24 --provider gcp --region us-central1
83+
[WARN] 2025-07-07 09:13:32.545 this configuration will create a FREE cluster, is this okay? (y/n)
84+
y
7485
```
7586
76-
Getting the cluster details shows that this has still deployed a free tier cluster:
87+
We can see from the warning that we will still deploy a free tier cluster.
88+
This can be double checked by getting the full details of the cluster being deployed:
7789
7890
```
7991
> clusters get free-gcp
@@ -121,6 +133,7 @@ For example the following will create a paid cluster because the number of nodes
121133
122134
```
123135
> clusters create --name paid-azure --description "My first couchbase cluster" --cidr 10.0.2.0/24 --provider azure --region eastus --nodes 3
136+
[WARN] 2025-07-07 09:15:36.022 this configuration will create a PAID cluster, is this okay? (y/n)
124137
👤 Charlie 🏠 remote in ☁️ default._default._default
125138
> clusters get paid-azure
126139
╭────────────────────┬───────────────────────────────────────────────────────────────────────────────╮
@@ -164,8 +177,17 @@ For example the following will create a paid cluster because the number of nodes
164177
╰────────────────────┴───────────────────────────────────────────────────────────────────────────────╯
165178
```
166179
167-
The created cluster can be configured using flags:
180+
If you need to skip this confirmation step then the `--confirm` or `-c` flag for short can be used:
181+
182+
```
183+
👤 Charlie 🏠 remote in ☁️ default._default._default
184+
> clusters create --name paid-azure --description "My first couchbase cluster" --cidr 10.0.2.0/24 --provider azure --region eastus --nodes 3 -c
185+
👤 Charlie 🏠 remote in ☁️ default._default._default
186+
```
187+
188+
The full set of flags for `clusters create` is:
168189
```
190+
-h, --help: Display the help message for this command
169191
--name <string>: the name of the cluster
170192
--provider <string>: the cloud provider
171193
--version <string>: the couchbase server version
@@ -175,6 +197,7 @@ The created cluster can be configured using flags:
175197
--description <string>: description for the cluster
176198
--region <string>: cloud provider region for the cluster
177199
--cidr <string>: cider block for the cluster
200+
-c, --confirm: skip confirmation of the cluster creation
178201
```
179202
180203
If you want complete control over the structure of the cluster then you can pipe a JSON cluster definition into the command:

src/cli/clusters_create.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use crate::client::cloud_json::{ClusterCreateRequest, FreeTierClusterCreateRequest, Provider};
22
use crate::state::State;
3-
use log::{debug, info};
3+
use log::{debug, info, warn};
44
use std::convert::TryFrom;
55
use std::sync::{Arc, Mutex};
66

77
use crate::cli::error::{client_error_to_shell_error, serialize_error};
88
use crate::cli::generic_error;
99
use crate::cli::util::{find_org_id, find_project_id};
10+
use crate::read_input;
1011
use nu_engine::command_prelude::Call;
1112
use nu_engine::CallExt;
1213
use nu_protocol::engine::{Command, EngineState, Stack};
@@ -75,6 +76,11 @@ impl Command for ClustersCreate {
7576
"cider block for the cluster",
7677
None,
7778
)
79+
.switch(
80+
"confirm",
81+
"skip confirmation of the cluster creation",
82+
Some('c'),
83+
)
7884
.category(Category::Custom("couchbase".to_string()))
7985
}
8086

@@ -187,10 +193,23 @@ fn clusters_create(
187193
}
188194
};
189195

190-
let capella = call.get_flag(engine_state, stack, "capella")?;
196+
if !call.has_flag(engine_state, stack, "confirm")? {
197+
if free_tier {
198+
warn!("this configuration will create a FREE cluster, is this okay? (y/n)")
199+
} else {
200+
warn!("this configuration will create a PAID cluster, is this okay? (y/n)")
201+
}
202+
203+
let confirmation = read_input().unwrap_or("y".to_string());
204+
if confirmation != "y" {
205+
info!("cluster creation canceled");
206+
return Ok(PipelineData::empty());
207+
}
208+
}
191209

192210
debug!("Running clusters create for {:?}", definition);
193211

212+
let capella: Option<String> = call.get_flag(engine_state, stack, "capella")?;
194213
let guard = state.lock().unwrap();
195214
let control = guard.named_or_active_org(capella)?;
196215
let client = control.client();

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ fn maybe_write_config_file(opt: CliOptions, password: Option<String>) -> PathBuf
487487
path
488488
}
489489

490-
fn read_input() -> Option<String> {
490+
pub fn read_input() -> Option<String> {
491491
let mut answer = String::new();
492492
std::io::stdin()
493493
.read_line(&mut answer)

0 commit comments

Comments
 (0)