Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set vpcConnector back to default, (e.g. no VPC connector) based on a defineString env var. #1406

Open
RYFN opened this issue May 24, 2023 · 3 comments

Comments

@RYFN
Copy link

RYFN commented May 24, 2023

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

  1. TS error, "Argument of type 'typeof ResetValue' is not assignable to parameter of type 'string | number | boolean | string[] | Expression<string | number | boolean | string[]>'"
  2. 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

@RYFN
Copy link
Author

RYFN commented Jun 6, 2023

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

@RYFN
Copy link
Author

RYFN commented Jul 20, 2023

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)

@Schmale97
Copy link

I am also experiencing this issue on firebase-admin: ~12.0.0 and firebase-functions: ~4.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants