From 0cd8576a584bbc1dae4ff8a79f5bfdd5020b316b Mon Sep 17 00:00:00 2001 From: joehan Date: Mon, 30 Sep 2024 15:50:15 -0400 Subject: [PATCH] Adding better handling for CloudSQl allowlist errors (#7770) --- src/gcp/cloudsql/cloudsqladmin.ts | 56 +++++++++++++++++++------------ 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/gcp/cloudsql/cloudsqladmin.ts b/src/gcp/cloudsql/cloudsqladmin.ts index be440084c1d..c6460fe2eae 100755 --- a/src/gcp/cloudsql/cloudsqladmin.ts +++ b/src/gcp/cloudsql/cloudsqladmin.ts @@ -1,4 +1,4 @@ -import { Client } from "../../apiv2"; +import { Client, ClientResponse } from "../../apiv2"; import { cloudSQLAdminOrigin } from "../../api"; import * as operationPoller from "../../operation-poller"; import { Instance, Database, User, UserType, DatabaseFlag } from "./types"; @@ -47,27 +47,33 @@ export async function createInstance( if (enableGoogleMlIntegration) { databaseFlags.push({ name: "cloudsql.enable_google_ml_integration", value: "on" }); } - const op = await client.post, Operation>(`projects/${projectId}/instances`, { - name: instanceId, - region: location, - databaseVersion: "POSTGRES_15", - settings: { - tier: "db-f1-micro", - edition: "ENTERPRISE", - ipConfiguration: { - authorizedNetworks: [], - }, - enableGoogleMlIntegration, - databaseFlags, - storageAutoResize: false, - userLabels: { "firebase-data-connect": "ft" }, - insightsConfig: { - queryInsightsEnabled: true, - queryPlansPerMinute: 5, // Match the default settings - queryStringLength: 1024, // Match the default settings + let op: ClientResponse; + try { + op = await client.post, Operation>(`projects/${projectId}/instances`, { + name: instanceId, + region: location, + databaseVersion: "POSTGRES_15", + settings: { + tier: "db-f1-micro", + edition: "ENTERPRISE", + ipConfiguration: { + authorizedNetworks: [], + }, + enableGoogleMlIntegration, + databaseFlags, + storageAutoResize: false, + userLabels: { "firebase-data-connect": "ft" }, + insightsConfig: { + queryInsightsEnabled: true, + queryPlansPerMinute: 5, // Match the default settings + queryStringLength: 1024, // Match the default settings + }, }, - }, - }); + }); + } catch (err: any) { + handleAllowlistError(err, location); + throw err; + } if (!waitForCreation) { return; } @@ -123,6 +129,14 @@ export async function updateInstanceForDataConnect( return pollRes; } +function handleAllowlistError(err: any, region: string) { + if (err.message.includes("Not allowed to set system label: firebase-data-connect")) { + throw new FirebaseError( + `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.`, + ); + } +} + function setDatabaseFlag(flag: DatabaseFlag, flags: DatabaseFlag[] = []): DatabaseFlag[] { const temp = flags.filter((f) => f.name !== flag.name); temp.push(flag);