@@ -9,7 +9,7 @@ import { Repository } from "../../../gcp/cloudbuild";
99import { API_VERSION } from "../../../gcp/frameworks" ;
1010import { FirebaseError } from "../../../error" ;
1111import { promptOnce } from "../../../prompt" ;
12- import { DEFAULT_REGION , ALLOWED_REGIONS } from "./constants" ;
12+ import { DEFAULT_REGION } from "./constants" ;
1313import { ensure } from "../../../ensureApiEnabled" ;
1414
1515const frameworksPollerOptions : Omit < poller . OperationPollerOptions , "operationResourceName" > = {
@@ -32,17 +32,19 @@ export async function doSetup(setup: any, projectId: string): Promise<void> {
3232 ensure ( projectId , "artifactregistry.googleapis.com" , "frameworks" , true ) ,
3333 ] ) ;
3434
35+ const allowedLocations = ( await gcp . listLocations ( projectId ) ) . map ( ( loc ) => loc . locationId ) ;
36+
37+ if ( setup . location ) {
38+ if ( ! allowedLocations . includes ( setup . location ) ) {
39+ throw new FirebaseError (
40+ `Invalid location ${ setup . location } . Valid choices are ${ allowedLocations . join ( ", " ) } `
41+ ) ;
42+ }
43+ }
44+
3545 logBullet ( "First we need a few details to create your backend." ) ;
3646
37- const location = await promptOnce ( {
38- name : "region" ,
39- type : "list" ,
40- default : DEFAULT_REGION ,
41- message :
42- "Please select a region " +
43- `(${ clc . yellow ( "info" ) } : Your region determines where your backend is located):\n` ,
44- choices : ALLOWED_REGIONS ,
45- } ) ;
47+ const location : string = setup . location || ( await promptLocation ( projectId , allowedLocations ) ) ;
4648
4749 logSuccess ( `Region set to ${ location } .\n` ) ;
4850
@@ -78,6 +80,18 @@ export async function doSetup(setup: any, projectId: string): Promise<void> {
7880 }
7981}
8082
83+ async function promptLocation ( projectId : string , locations : string [ ] ) : Promise < string > {
84+ return await promptOnce ( {
85+ name : "region" ,
86+ type : "list" ,
87+ default : DEFAULT_REGION ,
88+ message :
89+ "Please select a region " +
90+ `(${ clc . yellow ( "info" ) } : Your region determines where your backend is located):\n` ,
91+ choices : locations . map ( ( loc ) => ( { value : loc } ) ) ,
92+ } ) ;
93+ }
94+
8195function toBackend ( cloudBuildConnRepo : Repository ) : Omit < Backend , BackendOutputOnlyFields > {
8296 return {
8397 servingLocality : "GLOBAL_ACCESS" ,
0 commit comments