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

Fix terragrunt parsing #409

Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions lib/param_parsing/terragrunt.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ func GetVersionFromTerragrunt(params Params) (Params, error) {
}
var versionFromTerragrunt terragruntVersionConstraints
diagnostics = gohcl.DecodeBody(hclFile.Body, nil, &versionFromTerragrunt)
if diagnostics.HasErrors() {
return params, fmt.Errorf("could not decode body of HCL file %q", filePath)
if versionFromTerragrunt.TerraformVersionConstraint == "" {
logger.Infof("No terraform version constraint in %q", filePath)
return params, nil
}
version, err := lib.GetSemver(versionFromTerragrunt.TerraformVersionConstraint, params.MirrorURL)
if err != nil {
Expand Down
20 changes: 11 additions & 9 deletions lib/param_parsing/terragrunt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ package param_parsing
import (
"github.com/hashicorp/go-version"
"github.com/warrensbox/terraform-switcher/lib"
"strings"
"testing"
)

func TestGetVersionFromTerragrunt(t *testing.T) {
var params Params
logger = lib.InitLogger("DEBUG")
params = initParams(params)
params.ChDirPath = "../../test-data/integration-tests/test_terragrunt_hcl"
params, _ = GetVersionFromTerragrunt(params)
params, err := GetVersionFromTerragrunt(params)
if err != nil {
t.Fatalf("Got error '%s'", err)
}
v1, _ := version.NewVersion("0.13")
v2, _ := version.NewVersion("0.14")
actualVersion, _ := version.NewVersion(params.Version)
Expand All @@ -37,12 +40,11 @@ func TestGetVersionFromTerragrunt_erroneous_file(t *testing.T) {
params = initParams(params)
params.ChDirPath = "../../test-data/skip-integration-tests/test_terragrunt_error_hcl"
params, err := GetVersionFromTerragrunt(params)
if err == nil {
t.Error("Expected error but got none.")
} else {
expectedError := "could not decode body of HCL file"
if !strings.Contains(err.Error(), expectedError) {
t.Errorf("Expected error to contain '%q', got '%q'", expectedError, err)
}
if err != nil {
t.Error(err)
}
expected := ""
if params.Version != expected {
t.Errorf("Expected version '%s', got '%s'", expected, params.Version)
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
terragrunt_version_constraint = "= 0.36.2"
terraform_version_constraint = ">= 0.13, < 0.14"