Skip to content

Unable to deploy with VPC from external shared project #6327

Closed

Description

@steveoh

[REQUIRED] Environment info

firebase-tools: 12.5.2

Platform: macos

[REQUIRED] Test case

Trying to use a shared vpc from a different project with .env and

FUNCTION_VPC="projects/shared/locations/us-central1/connectors/shared"
const vpc = params.defineString('FUNCTION_VPC');
setGlobalOptions({
  vpcConnector: vpc
});

[REQUIRED] Steps to reproduce

Try to deploy with these values and firebase tools mutates the vpcConnector string to an invalid value.

functions: HTTP Error: 400, Could not update Cloud Run service projects/my-project/locations/us-central1/services/function. spec.template.metadata.annotations: Expected a VPC access connector name like projects/*/locations/*/connectors/*, but obtained projects/not-shared-project/locations/us-central1/connectors/{{the full value of the FUNCTION_VPC}}

I assume the issue is around

if (annotation.vpcConnector != null) {
let maybeId = annotation.vpcConnector;
if (maybeId && !maybeId.includes("/")) {
maybeId = `projects/${projectId}/locations/${region}/connectors/${maybeId}`;
}
endpoint.vpc = { connector: maybeId };
proto.renameIfPresent(
endpoint.vpc,
annotation,
"egressSettings",
"vpcConnectorEgressSettings"
);
}

But my connector has a / in it so it shouldn't get modified. I wonder if it has to do with the Expression<string> type that has a .value() not being invoked or something until later? Or maybe the / is encoded when read from the environment file?

[REQUIRED] Expected behavior

The VPC value I specify is used

[REQUIRED] Actual behavior

The string is mutated and the deployment fails.

Activity

  1. changed the title [-]Unable to deploy VPC in shared project[/-] [+]Unable to deploy VPC from external shared project[/+] on Sep 6, 2023
  2. changed the title [-]Unable to deploy VPC from external shared project[/-] [+]Unable to deploy with VPC from external shared project[/+] on Sep 6, 2023
  3. thomasmburke commented on Sep 6, 2023

    @thomasmburke
    Contributor

    Another reference to the connector in the source:

    if (bdEndpoint.vpc) {
    if (bdEndpoint.vpc.connector && !bdEndpoint.vpc.connector.includes("/")) {
    bdEndpoint.vpc.connector = `projects/${bdEndpoint.project}/locations/${region}/connectors/${bdEndpoint.vpc.connector}`;
    }
    bkEndpoint.vpc = { connector: params.resolveString(bdEndpoint.vpc.connector, paramValues) };

  4. steveoh commented on Sep 6, 2023

    @steveoh
    ContributorAuthor

    all of the connector building strings are protected by the / include but somehow I am getting through and it's getting appended. How is that possible?

    Are there instructions on how to step through the code with like a javascript debug terminal in vs code if i knew where in the npm package to set a breakpoint?

  5. thomasmburke commented on Sep 6, 2023

    @thomasmburke
    Contributor

    does the --debug potentially log the values of .env ?

  6. steveoh commented on Sep 6, 2023

    @steveoh
    ContributorAuthor

    i'm stepping through my node_modules and found this which implies it doesn't know the value yet and hasn't expanded the value so it doesn't have the / and why it gets appended incorrectly. It's resolving too late.

    image

    That gets expanded to

    bkEndpoint.vpc.connector = "projects/wrong-project/locations/us-central1/connectors/{{ params.FUNCTION_VPC }}"
    

    moving the expansion above the check for the / fixes my issue. Unsure if that is viable for other intended purposes.

    if (bdEndpoint.vpc) {
      bdEndpoint.vpc = { connector: params.resolveString(bdEndpoint.vpc.connector, paramValues) };
    
      if (bdEndpoint.vpc.connector && !bdEndpoint.vpc.connector.includes("/")) {
        bdEndpoint.vpc.connector = `projects/${bdEndpoint.project}/locations/${region}/connectors/${bdEndpoint.vpc.connector}`;
      }
      proto.copyIfPresent(bkEndpoint.vpc, bdEndpoint.vpc, "egressSettings");
    }
  7. steveoh commented on Sep 7, 2023

    @steveoh
    ContributorAuthor

    I'm happy to contribute that as a PR if you think it is a good solution?

  8. thomasmburke commented on Sep 7, 2023

    @thomasmburke
    Contributor

    Not a maintainer of the repo - so don't have an in depth understanding of how param changes could impact other situations. You'd definitely get feedback you are looking for on a PR, just follow the contributing guide

    Also - great find!

  9. steveoh commented on Sep 7, 2023

    @steveoh
    ContributorAuthor

    Ok opened a PR to see the testing results as I don't have this repo checked out and cloned. Curious to see if this causes any failures.

  10. self-assigned this
    on Sep 13, 2023
  11. added a commit that references this issue on Oct 10, 2023
  12. added 2 commits that reference this issue on Oct 10, 2023
    b36700f
    f840896
  13. added a commit that references this issue on Dec 14, 2023
    916a790
  14. added a commit that references this issue on Apr 26, 2024
    c4aaa7b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions