Skip to content

Add basic 1st gen functions support#10119

Open
inlined wants to merge 4 commits intoinlined.iac.2-terraform-utilsfrom
inlined.iac.3-cloud-functions
Open

Add basic 1st gen functions support#10119
inlined wants to merge 4 commits intoinlined.iac.2-terraform-utilsfrom
inlined.iac.3-cloud-functions

Conversation

@inlined
Copy link
Member

@inlined inlined commented Mar 17, 2026

Adds the Terraform exporter and implements 1st gen functions (not including "advanced" trigger types).

This is a checkpoint to get feedback and more invasive testing will be done in the future. There's some hacks present in the way we run the builder because a separate PR is going to need to update both firebase-functions and firebase-tools to allow injecting TF variables and declaring dependencies on standard variables (so as to not create a variables.tf that asks for more things than are used)

This is not really sufficient yet because I don't have providers declarations. Will come in part 4 where I actually field test this

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces the initial support for exporting Firebase Functions as Terraform configurations. It enables the functions:export command to generate variables.tf and main.tf files for 1st generation Cloud Functions (GCFv1). This foundational work aims to facilitate infrastructure-as-code management for Firebase Functions, with current limitations on advanced trigger types and GCFv2 functions, which are slated for future development.

Highlights

  • Terraform Exporter Added: A new terraform exporter has been integrated into the functions:export command, enabling the generation of Terraform configurations for Firebase Functions.
  • 1st Generation Cloud Functions (GCFv1) Support: The exporter specifically supports 1st generation Cloud Functions, converting their definitions into google_cloudfunctions_function and google_cloudfunctions_function_iam_binding Terraform resources.
  • Terraform Variable Definitions: Standard Terraform variables (project, location, gcf_bucket, gcf_archive, extension_id) are now defined in variables.tf to parameterize the generated infrastructure.
  • Comprehensive GCFv1 Configuration Handling: The implementation handles various GCFv1 configurations, including different region formats, VPC connectors, secret environment variables, and invoker permissions (public, private, custom service accounts).
  • Unit Test Coverage: Extensive unit tests have been added to validate the correct generation of Terraform blocks for diverse GCFv1 function scenarios and configurations.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • src/commands/functions-export.ts
    • Registered the new terraform exporter to the EXPORTERS map.
  • src/functions/iac/export.spec.ts
    • Added a new test suite for getTerraformIac to verify the generation of variables.tf and main.tf for GCFv1 functions.
    • Ensured that the generated Terraform includes function resources and IAM bindings, while correctly ignoring GCFv2 functions.
  • src/functions/iac/export.ts
    • Imported terraform and gcfv1 modules for Terraform block generation.
    • Defined STANDARD_TF_VARS to include common Terraform variables like project, location, and GCF deployment details.
    • Implemented getTerraformIac function to discover GCFv1 endpoints and convert them into sorted Terraform resource blocks.
    • Introduced 'hacks' for Firebase config and GCLOUD_PROJECT environment variables to support Terraform interpolation during the build process.
  • src/gcp/cloudfunctions.spec.ts
    • Imported build and tf modules for testing Terraform generation.
    • Added a BUILD_ENDPOINT constant for consistent test data.
    • Included tests for terraformFromEndpoint to validate rejection of non-GCFv1 endpoints and invalid runtimes, and correct resource generation.
    • Added tests for functionTerraform to cover various region formats, VPC connectivity, and secret environment variables, and to confirm error handling for unsupported trigger types.
    • Added tests for invokerTerraform to verify public, private, and custom service account invoker configurations, including multi-region deployments.
  • src/gcp/cloudfunctions.ts
    • Imported build, tf, and assertExhaustive modules.
    • Updated captureRuntimeValidationError to use regex.exec for improved regex matching.
    • Implemented terraformFromEndpoint to generate an array of Terraform blocks (compute and IAM) for a given GCFv1 endpoint, with validation for platform and runtime.
    • Implemented functionTerraform to construct a google_cloudfunctions_function resource block, handling attributes like runtime, region, VPC, environment variables, and trigger settings.
    • Implemented invokerTerraform to construct a google_cloudfunctions_function_iam_binding resource block for function invokers, supporting various permission configurations and multi-region deployments.
Activity
  • The pull request author indicated that this is a checkpoint for feedback and that more invasive testing will be conducted in the future.
  • The author noted the presence of temporary 'hacks' in the builder integration, anticipating future updates to firebase-functions and firebase-tools for Terraform variable injection.
  • The author mentioned that provider declarations are currently missing and will be addressed in a subsequent part (part 4) after initial field testing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for exporting 1st generation Cloud Functions to Terraform. The changes include adding a new 'terraform' exporter, implementing the logic to convert function endpoints into Terraform resource blocks, and adding corresponding unit tests.

My review focuses on improving code quality, documentation, and ensuring correctness of the generated Terraform configuration. I've identified a few areas for improvement:

  • A missing feature in Terraform generation for event-triggered function retries.
  • Violations of the repository's style guide regarding the use of any and missing documentation.
  • A minor typo in a variable description.

Overall, this is a solid addition. The author has clearly marked areas with hacks that will be addressed later, which is helpful context.

@inlined inlined force-pushed the inlined.iac.2-terraform-utils branch from 2ee2e3e to fe941ed Compare March 17, 2026 19:47
@inlined inlined force-pushed the inlined.iac.3-cloud-functions branch from a1f5549 to 70a2bfb Compare March 17, 2026 19:52
@inlined
Copy link
Member Author

inlined commented Mar 17, 2026

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces Terraform export support for 1st generation Cloud Functions. The changes include adding a new 'terraform' exporter, implementing the logic to generate main.tf and variables.tf from function definitions, and adding corresponding unit tests. The implementation cleverly uses Terraform interpolated values to work with the existing functions discovery mechanism.

My review focuses on improving type safety, documentation, and code maintainability. I've pointed out a violation of the style guide regarding the use of any, suggested adding documentation to a new public function, and proposed a refactoring to reduce code duplication. I also noted the hardcoded 'latest' version for secrets, which might be a point for future improvement.

Comment on lines +838 to +839
// TODO: Where does this get resolved normally?
version: "latest",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The secret version is hardcoded to "latest". While the TODO comment acknowledges this, hardcoding to latest can lead to unexpected behavior in production if the secret is updated, as it's not a stable reference. It's generally safer to use specific secret versions. If this is a temporary measure for this PR, it would be good to create a follow-up issue to track making this configurable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentional. Leaving open for now until I look up how to solve it and what those ramifications are (e.g. making more things async)


const mainTf = result["main.tf"];
expect(mainTf).to.include('resource "google_cloudfunctions_function" "my_func"');
expect(mainTf).to.include('resource "google_cloudfunctions_function_iam_binding" "my_func"');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you assert on the entire string, instead of includes, kind of like minion? This will also allow me to see a full example in case there are any missed edges.

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

Successfully merging this pull request may close these issues.

3 participants