@@ -40,6 +40,9 @@ import {
4040import { configstore } from "../../../configstore" ;
4141import { trackGA4 } from "../../../track" ;
4242
43+ // Default GCP region for Data Connect
44+ export const FDC_DEFAULT_REGION = "us-east4" ;
45+
4346const DATACONNECT_YAML_TEMPLATE = readTemplateSync ( "init/dataconnect/dataconnect.yaml" ) ;
4447const CONNECTOR_YAML_TEMPLATE = readTemplateSync ( "init/dataconnect/connector.yaml" ) ;
4548const SCHEMA_TEMPLATE = readTemplateSync ( "init/dataconnect/schema.gql" ) ;
@@ -125,6 +128,8 @@ export async function askQuestions(setup: Setup): Promise<void> {
125128 }
126129 if ( hasBilling ) {
127130 await promptForCloudSQL ( setup , info ) ;
131+ } else if ( info . appDescription ) {
132+ await promptForLocation ( setup , info ) ;
128133 }
129134 }
130135 setup . featureInfo = setup . featureInfo || { } ;
@@ -148,7 +153,7 @@ export async function actuate(setup: Setup, config: Config, options: any): Promi
148153 // Populate the default values of required fields.
149154 info . serviceId = info . serviceId || defaultServiceId ( ) ;
150155 info . cloudSqlInstanceId = info . cloudSqlInstanceId || `${ info . serviceId . toLowerCase ( ) } -fdc` ;
151- info . locationId = info . locationId || `us-central1` ;
156+ info . locationId = info . locationId || FDC_DEFAULT_REGION ;
152157 info . cloudSqlDatabase = info . cloudSqlDatabase || `fdcdb` ;
153158
154159 try {
@@ -435,10 +440,10 @@ function subDataconnectYamlValues(replacementValues: {
435440} ) : string {
436441 const replacements : Record < string , string > = {
437442 serviceId : "__serviceId__" ,
443+ locationId : "__location__" ,
438444 cloudSqlDatabase : "__cloudSqlDatabase__" ,
439445 cloudSqlInstanceId : "__cloudSqlInstanceId__" ,
440446 connectorDirs : "__connectorDirs__" ,
441- locationId : "__location__" ,
442447 } ;
443448 let replaced = DATACONNECT_YAML_TEMPLATE ;
444449 for ( const [ k , v ] of Object . entries ( replacementValues ) ) {
@@ -614,12 +619,7 @@ async function promptForCloudSQL(setup: Setup, info: RequiredInfo): Promise<void
614619 }
615620
616621 if ( info . locationId === "" ) {
617- const choices = await locationChoices ( setup ) ;
618- info . locationId = await select < string > ( {
619- message : "What location would like to use?" ,
620- choices,
621- default : "us-east4" ,
622- } ) ;
622+ await promptForLocation ( setup , info ) ;
623623 info . shouldProvisionCSQL = await confirm ( {
624624 message : `Would you like to provision your Cloud SQL instance and database now?` ,
625625 default : true ,
@@ -642,6 +642,17 @@ async function promptForCloudSQL(setup: Setup, info: RequiredInfo): Promise<void
642642 return ;
643643}
644644
645+ async function promptForLocation ( setup : Setup , info : RequiredInfo ) : Promise < void > {
646+ if ( info . locationId === "" ) {
647+ const choices = await locationChoices ( setup ) ;
648+ info . locationId = await select < string > ( {
649+ message : "What location should the new Cloud SQL instance be in?" ,
650+ choices,
651+ default : FDC_DEFAULT_REGION ,
652+ } ) ;
653+ }
654+ }
655+
645656async function locationChoices ( setup : Setup ) {
646657 if ( setup . projectId ) {
647658 const locations = await listLocations ( setup . projectId ) ;
0 commit comments