firebase-functions
firebase-functions copied to clipboard
Set vpcConnector back to default, (e.g. no VPC connector) based on a defineString env var.
Related issues
[REQUIRED] Version info
node:
16
firebase-functions:
4.3.1
firebase-tools:
11.24.0
firebase-admin:
11.3.0
[REQUIRED] Test case
I want to deploy the same function to multiple GCP projects, some with a vpcConnector and some without. Those without, I've set an env variable to "default" and would like to use this in a comparator to set the connector back to default (e.g. no connector.)
[REQUIRED] Steps to reproduce
Given ResetValue
is "...Special configuration type to reset configuration to platform default." I'd assume I'd be able to do...
import { ResetValue } from 'firebase-functions/lib/common/options';
const region = defineString('REGION');
const vpcConnector = defineString('MY_VPC_VALUE');
const vpcConnectorConfig = vpcConnector
.equals('default')
.thenElse(ResetValue, vpcConnector);
const runtimeOpts: functions.RuntimeOptions = {
timeoutSeconds: 540,
memory: '8GB',
vpcConnector: vpcConnectorConfig,
vpcConnectorEgressSettings: 'ALL_TRAFFIC'
};
export const myHttpFunc = functions
.region(region)
.runWith(runtimeOpts)
.https.onCall(async (data, context) => {
but
- TS error, "Argument of type 'typeof ResetValue' is not assignable to parameter of type 'string | number | boolean | string[] | Expression<string | number | boolean | string[]>'"
- on deployment, if I cast ResetValue to any to work around the TS error, I receive an error:
Error: Failed to load function definition from source: Failed to generate manifest from function source: Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/common/options' is not defined by "exports" in .../node_modules/firebase-functions/package.json
[REQUIRED] Expected behavior
Able to set VPC connector to default value based on setting of built-in comparators
[REQUIRED] Actual behavior
Type not allow / function deploy failed.
Were you able to successfully deploy your functions?
No
Update to this, using
import * as functions from 'firebase-functions';
...
const vpcConnector = defineString('MY_VPC_VALUE');
const vpcConnectorConfig = vpcConnector
.equals('default')
.thenElse(functions.RESET_VALUE as any, vpcConnector);
export const myHttpFunc = functions
.region(region)
.runWith({
vpcConnector: vpcConnectorConfig,
vpcConnectorEgressSettings: 'ALL_TRAFFIC'
})
...
resolves the "Failed to generate manifest" error. However the deployment then fails with the following error instead
Error: Malformed list component object Object
Any updates on this one, or workarounds? (My current workaround was to define a "default" serverless VPC adapter in the projects I didn't really need one in, and use that)
I am also experiencing this issue on firebase-admin: ~12.0.0 and firebase-functions: ~4.6.0