Skip to content

Add warning logs for TF version less than recommended version#5346

Open
parulbajaj01 wants to merge 1 commit intoGoogleCloudPlatform:developfrom
parulbajaj01:parul/terraform
Open

Add warning logs for TF version less than recommended version#5346
parulbajaj01 wants to merge 1 commit intoGoogleCloudPlatform:developfrom
parulbajaj01:parul/terraform

Conversation

@parulbajaj01
Copy link
Contributor

Added version validation logic and warning logs if the user's terraform version is less than Cluster Toolkit's recommended version.

Submission Checklist

NOTE: Community submissions can take up to 2 weeks to be reviewed.

Please take the following actions before submitting this pull request.

  • Fork your PR branch from the Toolkit "develop" branch (not main)
  • Test all changes with pre-commit in a local branch #
  • Confirm that "make tests" passes all tests
  • Add or modify unit tests to cover code changes
  • Ensure that unit test coverage remains above 80%
  • Update all applicable documentation
  • Follow Cluster Toolkit Contribution guidelines #

@parulbajaj01 parulbajaj01 added the release-improvements Added to release notes under the "Improvements" heading. label Mar 12, 2026
@parulbajaj01 parulbajaj01 requested a review from a team as a code owner March 12, 2026 09:37
@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 a proactive mechanism to ensure users are running a compatible Terraform version with the Cluster Toolkit. By validating the installed Terraform version against a recommended minimum and issuing a warning if it's outdated, the change aims to prevent potential compatibility issues and improve the overall user experience without blocking execution.

Highlights

  • Terraform Version Validation: Implemented logic to validate the user's installed Terraform version against a recommended minimum (1.12.2).
  • Warning Log Integration: Introduced a warning log that is displayed if the detected Terraform version is older than the recommended minimum, advising the user to upgrade.
Changelog
  • go.mod
    • Removed the "// indirect" tag for the github.com/hashicorp/go-version dependency, making it a direct dependency.
  • pkg/shell/terraform.go
    • Imported the "sync" package and the "github.com/hashicorp/go-version" library.
    • Defined "minTfVersion" constant as "1.12.2".
    • Added a "sync.Once" mechanism ("tfVersionOnce") to ensure the version check runs only once.
    • Implemented "checkTfVersion" function to retrieve the current Terraform version, parse it, and compare it with "minTfVersion".
    • Included a "logging.Warn" call if the current Terraform version is older than the recommended minimum.
    • Integrated the "checkTfVersion" call into the "ConfigureTerraform" function.
Activity
  • No specific activity (comments, reviews, progress updates) has been recorded for this pull request yet.
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 a valuable check for the user's Terraform version, issuing a warning if it falls below the recommended minimum. The implementation is efficient, using sync.Once to ensure the check runs only a single time. The code is generally well-written and clear. I have one suggestion to enhance the robustness of the version parsing logic to prevent a potential panic, thereby making the implementation more resilient to configuration errors during development.

Comment on lines +95 to +98
minVer, _ := version.NewVersion(minTfVersion)
if tfVer.LessThan(minVer) {
logging.Warn("Terraform version %s is older than the recommended minimum version %s. Please consider upgrading.", v, minTfVersion)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Ignoring the error from version.NewVersion when parsing the hardcoded minTfVersion constant could lead to a panic. If minTfVersion were ever set to an invalid version string, version.NewVersion would return a nil version and an error. The subsequent call to tfVer.LessThan(minVer) would then cause a nil pointer dereference. It's safer to handle this potential error by panicking with a descriptive message, which would catch such a configuration bug during development.

                minVer, err := version.NewVersion(minTfVersion)
                if err != nil {
                        // This is a developer error with a constant, so panicking is appropriate
                        // to catch this during development.
                        panic(fmt.Sprintf("BUG: hardcoded minimum terraform version %q is invalid: %v", minTfVersion, err))
                }
                if tfVer.LessThan(minVer) {
                        logging.Warn("Terraform version %s is older than the recommended minimum version %s. Please consider upgrading.", v, minTfVersion)
                }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-improvements Added to release notes under the "Improvements" heading.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant