@@ -29,6 +29,8 @@ import {
2929 promiseWithSpinner ,
3030 logLabeledError ,
3131 newUniqueId ,
32+ logLabeledWarning ,
33+ logLabeledSuccess ,
3234} from "../../../utils" ;
3335import { isBillingEnabled } from "../../../gcp/cloudbilling" ;
3436import * as sdk from "./sdk" ;
@@ -40,6 +42,7 @@ import {
4042} from "../../../gemini/fdcExperience" ;
4143import { configstore } from "../../../configstore" ;
4244import { trackGA4 } from "../../../track" ;
45+ import { isEnabled } from "../../../experiments" ;
4346
4447// Default GCP region for Data Connect
4548export const FDC_DEFAULT_REGION = "us-east4" ;
@@ -126,7 +129,6 @@ export async function askQuestions(setup: Setup): Promise<void> {
126129 shouldProvisionCSQL : false ,
127130 } ;
128131 if ( setup . projectId ) {
129- const hasBilling = await isBillingEnabled ( setup ) ;
130132 await ensureApis ( setup . projectId ) ;
131133 await promptForExistingServices ( setup , info ) ;
132134 if ( ! info . serviceGql ) {
@@ -154,11 +156,7 @@ export async function askQuestions(setup: Setup): Promise<void> {
154156 } ) ;
155157 }
156158 }
157- if ( hasBilling ) {
158- await promptForCloudSQL ( setup , info ) ;
159- } else if ( info . appDescription ) {
160- await promptForLocation ( setup , info ) ;
161- }
159+ await promptForCloudSQL ( setup , info ) ;
162160 }
163161 setup . featureInfo = setup . featureInfo || { } ;
164162 setup . featureInfo . dataconnect = info ;
@@ -216,9 +214,6 @@ export async function actuate(setup: Setup, config: Config, options: any): Promi
216214 https://console.firebase.google.com/project/${ setup . projectId ! } /dataconnect/locations/${ info . locationId } /services/${ info . serviceId } /schema` ,
217215 ) ;
218216 }
219- if ( ! ( await isBillingEnabled ( setup ) ) ) {
220- setup . instructions . push ( upgradeInstructions ( setup . projectId || "your-firebase-project" ) ) ;
221- }
222217 setup . instructions . push (
223218 `Install the Data Connect VS Code Extensions. You can explore Data Connect Query on local pgLite and Cloud SQL Postgres Instance.` ,
224219 ) ;
@@ -238,9 +233,7 @@ async function actuateWithInfo(
238233 }
239234
240235 await ensureApis ( projectId , /* silent =*/ true ) ;
241- const provisionCSQL = info . shouldProvisionCSQL && ( await isBillingEnabled ( setup ) ) ;
242- if ( provisionCSQL ) {
243- // Kicks off Cloud SQL provisioning if the project has billing enabled.
236+ if ( info . shouldProvisionCSQL ) {
244237 await setupCloudSql ( {
245238 projectId : projectId ,
246239 location : info . locationId ,
@@ -296,7 +289,7 @@ async function actuateWithInfo(
296289 projectId ,
297290 info ,
298291 schemaFiles ,
299- provisionCSQL ,
292+ info . shouldProvisionCSQL ,
300293 ) ;
301294 await upsertSchema ( saveSchemaGql ) ;
302295 if ( waitForCloudSQLProvision ) {
@@ -695,6 +688,31 @@ async function promptForCloudSQL(setup: Setup, info: RequiredInfo): Promise<void
695688 if ( ! setup . projectId ) {
696689 return ;
697690 }
691+ const instrumentlessTrialEnabled = isEnabled ( "fdcift" ) ;
692+ const billingEnabled = await isBillingEnabled ( setup ) ;
693+ const freeTrialUsed = await checkFreeTrialInstanceUsed ( setup . projectId ) ;
694+ const freeTrialAvailable = ! freeTrialUsed && ( billingEnabled || instrumentlessTrialEnabled ) ;
695+
696+ if ( ! billingEnabled && ! instrumentlessTrialEnabled ) {
697+ setup . instructions . push ( upgradeInstructions ( setup . projectId || "your-firebase-project" , false ) ) ;
698+ return ;
699+ }
700+
701+ if ( freeTrialUsed ) {
702+ logLabeledWarning (
703+ "dataconnect" ,
704+ "CloudSQL no cost trial has already been used on this project." ,
705+ ) ;
706+ if ( ! billingEnabled ) {
707+ setup . instructions . push (
708+ upgradeInstructions ( setup . projectId || "your-firebase-project" , true ) ,
709+ ) ;
710+ return ;
711+ }
712+ } else if ( instrumentlessTrialEnabled || billingEnabled ) {
713+ logLabeledSuccess ( "dataconnect" , "CloudSQL no cost trial available!" ) ;
714+ }
715+
698716 // Check for existing Cloud SQL instances, if we didn't already set one.
699717 if ( info . cloudSqlInstanceId === "" ) {
700718 const instances = await cloudsql . listInstances ( setup . projectId ) ;
@@ -708,7 +726,7 @@ async function promptForCloudSQL(setup: Setup, info: RequiredInfo): Promise<void
708726 // If we've already chosen a region (ie service already exists), only list instances from that region.
709727 choices = choices . filter ( ( c ) => info . locationId === "" || info . locationId === c . location ) ;
710728 if ( choices . length ) {
711- if ( ! ( await checkFreeTrialInstanceUsed ( setup . projectId ) ) ) {
729+ if ( freeTrialAvailable ) {
712730 choices . push ( { name : "Create a new free trial instance" , value : "" , location : "" } ) ;
713731 } else {
714732 choices . push ( { name : "Create a new CloudSQL instance" , value : "" , location : "" } ) ;
@@ -737,7 +755,7 @@ async function promptForCloudSQL(setup: Setup, info: RequiredInfo): Promise<void
737755 if ( info . locationId === "" ) {
738756 await promptForLocation ( setup , info ) ;
739757 info . shouldProvisionCSQL = await confirm ( {
740- message : `Would you like to provision your Cloud SQL instance and database now?` ,
758+ message : `Would you like to provision your ${ freeTrialAvailable ? "free trial " : "" } Cloud SQL instance and database now?` ,
741759 default : true ,
742760 } ) ;
743761 }
0 commit comments