From 6abd865082dad28d3a9787dd791a3a9e4747cbfb Mon Sep 17 00:00:00 2001 From: Tomer Heber Date: Sun, 17 Nov 2024 09:23:56 -0600 Subject: [PATCH] update bad input use-cases --- client/template.go | 12 +++++++----- env0/resource_template_test.go | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/client/template.go b/client/template.go index 2dbcd4c3..c6d20a0a 100644 --- a/client/template.go +++ b/client/template.go @@ -127,10 +127,6 @@ func (payload *TemplateCreatePayload) Invalidate() error { return errors.New("must not specify organizationId") } - if payload.Type != TERRAGRUNT && payload.TerragruntVersion != "" { - return errors.New("can't define terragrunt version for non-terragrunt template") - } - if payload.Type == TERRAGRUNT { if payload.TerragruntVersion == "" { return errors.New("must supply terragrunt version") @@ -149,7 +145,13 @@ func (payload *TemplateCreatePayload) Invalidate() error { return errors.New("must supply terraform version") } } else { - payload.TerragruntTfBinary = "" + if payload.TerragruntVersion != "" { + return errors.New("can't define terragrunt version for non-terragrunt template") + } + + if payload.TerragruntTfBinary != "" { + return errors.New("can't define terragrunt_tf_binary for non-terragrunt template") + } } if payload.Type == OPENTOFU && payload.OpentofuVersion == "" { diff --git a/env0/resource_template_test.go b/env0/resource_template_test.go index a1e662f3..fbe84ee4 100644 --- a/env0/resource_template_test.go +++ b/env0/resource_template_test.go @@ -1389,6 +1389,25 @@ func TestUnitTemplateResource(t *testing.T) { runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) {}) }) + t.Run("terragrunt_tf_binary set with a non terragrunt template type", func(t *testing.T) { + testCase := resource.TestCase{ + Steps: []resource.TestStep{ + { + Config: resourceConfigCreate(resourceType, resourceName, map[string]interface{}{ + "name": "template0", + "repository": "env0/repo", + "type": "terraform", + "terraform_version": "0.15.1", + "terragrunt_tf_binary": "opentofu", + }), + ExpectError: regexp.MustCompile(`can't define terragrunt_tf_binary for non-terragrunt template`), + }, + }, + } + + runUnitTest(t, testCase, func(mock *client.MockApiClientInterface) {}) + }) + t.Run("run with terragrunt without an opentofu version", func(t *testing.T) { testCase := resource.TestCase{ Steps: []resource.TestStep{