Edits history of script submission #14836 for ' Create and initialize a new cluster (cockroachdb)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Cockroachdb = {
      token: string;
    };
    /**
     * Create and initialize a new cluster
     * Can be used by the following roles assigned at the organization scope:
    - CLUSTER_ADMIN
    - CLUSTER_CREATOR
    
     */
    export async function main(
      auth: Cockroachdb,
      body: {
        name: string;
        provider: "GCP" | "AWS" | "AZURE";
        spec: {
          dedicated?: {
            cidr_range?: string;
            cockroach_version?: string;
            hardware: {
              disk_iops?: number;
              machine_spec: { machine_type?: string; num_virtual_cpus?: number };
              storage_gib: number;
            };
            network_visibility?: "PUBLIC" | "PRIVATE";
            region_nodes: {};
            restrict_egress_traffic?: false | true;
            support_physical_cluster_replication?: false | true;
          };
          delete_protection?: "ENABLED" | "DISABLED";
          labels?: {};
          parent_id?: string;
          plan?: "BASIC" | "STANDARD" | "ADVANCED";
          serverless?: {
            primary_region?: string;
            regions: string[];
            upgrade_type?: "MANUAL" | "AUTOMATIC";
            usage_limits?: {
              provisioned_virtual_cpus?: string;
              request_unit_limit?: string;
              storage_mib_limit?: string;
            };
            with_empty_ip_allowlist?: false | true;
          };
        };
      },
    ) {
      const url = new URL(`https://cockroachlabs.cloud/api/v1/clusters`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago