|
1 | | -import { Client } from "../../apiv2"; |
| 1 | +import { Client, ClientResponse } from "../../apiv2"; |
2 | 2 | import { cloudSQLAdminOrigin } from "../../api"; |
3 | 3 | import * as operationPoller from "../../operation-poller"; |
4 | 4 | import { Instance, Database, User, UserType, DatabaseFlag } from "./types"; |
@@ -47,27 +47,33 @@ export async function createInstance( |
47 | 47 | if (enableGoogleMlIntegration) { |
48 | 48 | databaseFlags.push({ name: "cloudsql.enable_google_ml_integration", value: "on" }); |
49 | 49 | } |
50 | | - const op = await client.post<Partial<Instance>, Operation>(`projects/${projectId}/instances`, { |
51 | | - name: instanceId, |
52 | | - region: location, |
53 | | - databaseVersion: "POSTGRES_15", |
54 | | - settings: { |
55 | | - tier: "db-f1-micro", |
56 | | - edition: "ENTERPRISE", |
57 | | - ipConfiguration: { |
58 | | - authorizedNetworks: [], |
59 | | - }, |
60 | | - enableGoogleMlIntegration, |
61 | | - databaseFlags, |
62 | | - storageAutoResize: false, |
63 | | - userLabels: { "firebase-data-connect": "ft" }, |
64 | | - insightsConfig: { |
65 | | - queryInsightsEnabled: true, |
66 | | - queryPlansPerMinute: 5, // Match the default settings |
67 | | - queryStringLength: 1024, // Match the default settings |
| 50 | + let op: ClientResponse<Operation>; |
| 51 | + try { |
| 52 | + op = await client.post<Partial<Instance>, Operation>(`projects/${projectId}/instances`, { |
| 53 | + name: instanceId, |
| 54 | + region: location, |
| 55 | + databaseVersion: "POSTGRES_15", |
| 56 | + settings: { |
| 57 | + tier: "db-f1-micro", |
| 58 | + edition: "ENTERPRISE", |
| 59 | + ipConfiguration: { |
| 60 | + authorizedNetworks: [], |
| 61 | + }, |
| 62 | + enableGoogleMlIntegration, |
| 63 | + databaseFlags, |
| 64 | + storageAutoResize: false, |
| 65 | + userLabels: { "firebase-data-connect": "ft" }, |
| 66 | + insightsConfig: { |
| 67 | + queryInsightsEnabled: true, |
| 68 | + queryPlansPerMinute: 5, // Match the default settings |
| 69 | + queryStringLength: 1024, // Match the default settings |
| 70 | + }, |
68 | 71 | }, |
69 | | - }, |
70 | | - }); |
| 72 | + }); |
| 73 | + } catch (err: any) { |
| 74 | + handleAllowlistError(err, location); |
| 75 | + throw err; |
| 76 | + } |
71 | 77 | if (!waitForCreation) { |
72 | 78 | return; |
73 | 79 | } |
@@ -123,6 +129,14 @@ export async function updateInstanceForDataConnect( |
123 | 129 | return pollRes; |
124 | 130 | } |
125 | 131 |
|
| 132 | +function handleAllowlistError(err: any, region: string) { |
| 133 | + if (err.message.includes("Not allowed to set system label: firebase-data-connect")) { |
| 134 | + throw new FirebaseError( |
| 135 | + `Cloud SQL free trial instances are not yet available in ${region}. Please check https://firebase.google.com/docs/data-connect/ for a full list of available regions.`, |
| 136 | + ); |
| 137 | + } |
| 138 | +} |
| 139 | + |
126 | 140 | function setDatabaseFlag(flag: DatabaseFlag, flags: DatabaseFlag[] = []): DatabaseFlag[] { |
127 | 141 | const temp = flags.filter((f) => f.name !== flag.name); |
128 | 142 | temp.push(flag); |
|
0 commit comments