Skip to content

Commit 0cd8576

Browse files
authored
Adding better handling for CloudSQl allowlist errors (#7770)
1 parent 85d7c27 commit 0cd8576

File tree

1 file changed

+35
-21
lines changed

1 file changed

+35
-21
lines changed

src/gcp/cloudsql/cloudsqladmin.ts

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Client } from "../../apiv2";
1+
import { Client, ClientResponse } from "../../apiv2";
22
import { cloudSQLAdminOrigin } from "../../api";
33
import * as operationPoller from "../../operation-poller";
44
import { Instance, Database, User, UserType, DatabaseFlag } from "./types";
@@ -47,27 +47,33 @@ export async function createInstance(
4747
if (enableGoogleMlIntegration) {
4848
databaseFlags.push({ name: "cloudsql.enable_google_ml_integration", value: "on" });
4949
}
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+
},
6871
},
69-
},
70-
});
72+
});
73+
} catch (err: any) {
74+
handleAllowlistError(err, location);
75+
throw err;
76+
}
7177
if (!waitForCreation) {
7278
return;
7379
}
@@ -123,6 +129,14 @@ export async function updateInstanceForDataConnect(
123129
return pollRes;
124130
}
125131

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+
126140
function setDatabaseFlag(flag: DatabaseFlag, flags: DatabaseFlag[] = []): DatabaseFlag[] {
127141
const temp = flags.filter((f) => f.name !== flag.name);
128142
temp.push(flag);

0 commit comments

Comments
 (0)