Skip to content

Commit

Permalink
update bad input use-cases
Browse files Browse the repository at this point in the history
  • Loading branch information
TomerHeber committed Nov 17, 2024
1 parent 5b13de4 commit 6abd865
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
12 changes: 7 additions & 5 deletions client/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 == "" {
Expand Down
19 changes: 19 additions & 0 deletions env0/resource_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 6abd865

Please sign in to comment.