Skip to content

Functions IaC: Terraform types#10118

Merged
inlined merged 9 commits intomainfrom
inlined.iac.2-terraform-utils
Mar 20, 2026
Merged

Functions IaC: Terraform types#10118
inlined merged 9 commits intomainfrom
inlined.iac.2-terraform-utils

Conversation

@inlined
Copy link
Copy Markdown
Member

@inlined inlined commented Mar 17, 2026

Creates terraform utilities for the IaC export tool. Using very loose typing for now.

To consider: should we also sort top level keys by some canonical style? Insert line breaks between for_each and other attributes for e.g.?

@gemini-code-assist
Copy link
Copy Markdown
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 foundational utilities for generating Terraform HCL configurations, specifically designed to support Infrastructure as Code (IaC) exports for Firebase Functions. The changes provide a structured way to define and serialize Terraform blocks and attributes, enabling programmatic construction of Terraform configurations. This enhancement is crucial for automating the deployment and management of cloud resources through Terraform.

Highlights

  • Terraform HCL Utilities: Introduced a new module src/functions/iac/terraform.ts containing utility functions and types for generating Terraform HCL (HashiCorp Configuration Language). This includes interfaces for HCL expressions and blocks, and functions for manipulating and serializing HCL values.
  • HCL Value Serialization: Implemented serializeValue to convert various JavaScript types (strings, numbers, booleans, null, arrays, objects, and custom HCLExpression objects) into their corresponding HCL string representations, handling indentation for complex structures and variable injection for project IDs.
  • Field Transformation and Naming: Added copyField and renameField utilities to assist in mapping source object fields to Terraform attributes, including automatic conversion of field names to lower snake case and optional value transformations.
  • Service Account Formatting: Included a serviceAccount helper function to correctly format service account strings, appending the IAM domain for short service accounts.
  • String Utility Enhancement: Added a new toLowerSnakeCase utility function in src/utils.ts to convert strings to lower snake case, which is beneficial for generating Terraform attribute names.
  • Comprehensive Unit Tests: Provided a dedicated test file src/functions/iac/terraform.spec.ts with extensive unit tests covering all new Terraform utility functions to ensure their correctness and expected behavior.

🧠 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/functions/iac/terraform.spec.ts
    • Added new test file for Terraform utility functions.
    • Included tests for expr to create HCL expressions.
    • Added tests for copyField to verify field copying and name conversion.
    • Implemented tests for renameField to ensure attribute renaming.
    • Provided tests for serviceAccount to format service account strings.
    • Included comprehensive tests for serializeValue covering various data types and HCL expression serialization.
    • Added tests for blockToString to ensure correct HCL block stringification.
  • src/functions/iac/terraform.ts
    • Added new file containing core utility functions and types for generating Terraform HCL.
    • Defined Expression interface for raw HCL expressions.
    • Implemented expr function to create HCLExpression objects.
    • Defined Value type for valid HCL attribute values.
    • Defined Block interface for generic HCL blocks.
    • Implemented copyField to copy and transform fields to attributes, converting to lower snake case.
    • Implemented renameField to copy fields to specified attribute names.
    • Implemented serviceAccount to append IAM domain for short service accounts.
    • Implemented serializeValue to convert various data types into HCL string representation, including handling parameterized fields and indentation for complex types.
    • Implemented blockToString to stringify HCL blocks with labels and attributes.
  • src/utils.ts
    • Refactored dir variable declaration in promptForDirectory for consistency.
    • Added a JSDoc comment block to the deepEqual function.
    • Added toLowerSnakeCase function to convert strings to lower snake case.
Activity
  • No specific pull request activity (comments, reviews, etc.) was provided in the context.
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
Copy Markdown
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 a set of utilities for generating Terraform configurations for Firebase Functions as Infrastructure as Code. The overall approach is solid, and the new modules are well-tested. I've identified a few areas for improvement, mainly concerning a new utility function's implementation that doesn't handle all edge cases, some type safety issues in the tests that violate the repository's style guide, and a couple of minor refinements in the HCL serialization logic for better consistency and clarity. Addressing these points will enhance the robustness and maintainability of this new feature.

Comment thread src/functions/iac/terraform.ts Outdated
Comment thread src/utils.ts
Comment thread src/functions/iac/terraform.spec.ts Outdated
Comment thread src/functions/iac/terraform.spec.ts Outdated
Comment thread src/functions/iac/terraform.ts Outdated
Comment thread src/utils.ts Outdated
@inlined inlined force-pushed the inlined.iac.2-terraform-utils branch from 2ee2e3e to fe941ed Compare March 17, 2026 19:47
@inlined
Copy link
Copy Markdown
Member Author

inlined commented Mar 17, 2026

/gemini review

Copy link
Copy Markdown
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 a set of utilities for generating Terraform HCL, complete with unit tests. A new toLowerSnakeCase utility is also added. The code is generally well-written and tested. My review includes one high-severity suggestion to correct the handling of null values in renameField, which is crucial for generating correct Terraform configurations that can unset or reset attributes.

Comment thread src/functions/iac/terraform.ts Outdated
@rainshen49
Copy link
Copy Markdown

The official Terraform docs don't enforce sorting of field names. Here's what they recommend https://developer.hashicorp.com/terraform/language/style#resource-order

  1. If present, The count or for_each meta-argument.
  2. Resource-specific non-block parameters.
  3. Resource-specific block parameters.
  4. If required, a lifecycle block.
  5. If required, the depends_on parameter.

Base automatically changed from inlined.iac.1-basic-structure to main March 20, 2026 17:00
@inlined
Copy link
Copy Markdown
Member Author

inlined commented Mar 20, 2026

Thanks. I'll merge this, add a new utility to order so that printing is deterministic, and then rebase the functions PR on that with better testing.

@inlined inlined enabled auto-merge (squash) March 20, 2026 20:56
@inlined inlined merged commit e343921 into main Mar 20, 2026
47 checks passed
@inlined inlined deleted the inlined.iac.2-terraform-utils branch March 20, 2026 21:07
andrewbrook pushed a commit that referenced this pull request Mar 25, 2026
* feat: add functions:export command with internal format support

* PR feedback

* Lint

* feat: add terraform hcl generation utilities

* PR feedback. More comments

* Improve tests

* PR feedback
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