1 | |
2 | type Cockroachdb = { |
3 | token: string; |
4 | }; |
5 | |
6 | * Create and initialize a new cluster |
7 | * Can be used by the following roles assigned at the organization scope: |
8 | - CLUSTER_ADMIN |
9 | - CLUSTER_CREATOR |
10 |
|
11 | */ |
12 | export async function main( |
13 | auth: Cockroachdb, |
14 | body: { |
15 | name: string; |
16 | provider: "GCP" | "AWS" | "AZURE"; |
17 | spec: { |
18 | dedicated?: { |
19 | cidr_range?: string; |
20 | cockroach_version?: string; |
21 | hardware: { |
22 | disk_iops?: number; |
23 | machine_spec: { machine_type?: string; num_virtual_cpus?: number }; |
24 | storage_gib: number; |
25 | }; |
26 | network_visibility?: "PUBLIC" | "PRIVATE"; |
27 | region_nodes: {}; |
28 | restrict_egress_traffic?: false | true; |
29 | support_physical_cluster_replication?: false | true; |
30 | }; |
31 | delete_protection?: "ENABLED" | "DISABLED"; |
32 | labels?: {}; |
33 | parent_id?: string; |
34 | plan?: "BASIC" | "STANDARD" | "ADVANCED"; |
35 | serverless?: { |
36 | primary_region?: string; |
37 | regions: string[]; |
38 | upgrade_type?: "MANUAL" | "AUTOMATIC"; |
39 | usage_limits?: { |
40 | provisioned_virtual_cpus?: string; |
41 | request_unit_limit?: string; |
42 | storage_mib_limit?: string; |
43 | }; |
44 | with_empty_ip_allowlist?: false | true; |
45 | }; |
46 | }; |
47 | }, |
48 | ) { |
49 | const url = new URL(`https://cockroachlabs.cloud/api/v1/clusters`); |
50 |
|
51 | const response = await fetch(url, { |
52 | method: "POST", |
53 | headers: { |
54 | "Content-Type": "application/json", |
55 | Authorization: "Bearer " + auth.token, |
56 | }, |
57 | body: JSON.stringify(body), |
58 | }); |
59 | if (!response.ok) { |
60 | const text = await response.text(); |
61 | throw new Error(`${response.status} ${text}`); |
62 | } |
63 | return await response.json(); |
64 | } |
65 |
|