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

feat: Only check TF version when necessary #3583

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions cli/commands/terraform/version_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ import (
"github.com/hashicorp/go-version"
)

// DefaultTerraformVersionConstraint uses the constraint syntax from https://github.com/hashicorp/go-version
// This version of Terragrunt was tested to work with Terraform 0.12.0 and above only
const DefaultTerraformVersionConstraint = ">= v0.12.0"

// TerraformVersionRegex verifies that terraform --version output is in one of the following formats:
// - OpenTofu v1.6.0-dev
// - Terraform v0.9.5-dev (cad024a5fe131a546936674ef85445215bbc4226+CHANGES)
Expand Down Expand Up @@ -54,17 +50,14 @@ func checkVersionConstraints(ctx context.Context, terragruntOptions *options.Ter
terragruntOptions.TerraformPath = partialTerragruntConfig.TerraformBinary
}

if err := PopulateTerraformVersion(ctx, terragruntOptions); err != nil {
return err
}

terraformVersionConstraint := DefaultTerraformVersionConstraint
if partialTerragruntConfig.TerraformVersionConstraint != "" {
terraformVersionConstraint = partialTerragruntConfig.TerraformVersionConstraint
}
if terraformVersionConstraint := partialTerragruntConfig.TerraformVersionConstraint; terraformVersionConstraint != "" {
if err := PopulateTerraformVersion(ctx, terragruntOptions); err != nil {
return err
}

if err := CheckTerraformVersion(terraformVersionConstraint, terragruntOptions); err != nil {
return err
if err := CheckTerraformVersion(terraformVersionConstraint, terragruntOptions); err != nil {
return err
}
}

if partialTerragruntConfig.TerragruntVersionConstraint != "" {
Expand Down