Skip to content

Commit

Permalink
Fix: openTofu version is missing when creating a Terragrunt env causi…
Browse files Browse the repository at this point in the history
…ng deploy to fail (#868)
  • Loading branch information
TomerHeber committed May 30, 2024
1 parent 4a3c011 commit de81881
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 0 additions & 2 deletions client/configuration_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,3 @@ var _ = Describe("Configuration Set", func() {
})
})
})

// TODO add more tests...
2 changes: 1 addition & 1 deletion client/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (payload *TemplateCreatePayload) Invalidate() error {
payload.TerraformVersion = ""
}

if payload.Type != "opentofu" {
if payload.Type != "opentofu" && payload.TerragruntTfBinary != "opentofu" {
payload.OpentofuVersion = ""
}

Expand Down
13 changes: 11 additions & 2 deletions env0/resource_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,8 @@ func TestUnitEnvironmentWithoutTemplateResource(t *testing.T) {
GithubInstallationId: 2,
TerraformVersion: "0.12.25",
TerragruntVersion: "0.26.1",
TerragruntTfBinary: "terraform",
OpentofuVersion: "1.7.1",
TerragruntTfBinary: "opentofu",
}

environmentCreatePayload := client.EnvironmentCreate{
Expand Down Expand Up @@ -2074,6 +2075,7 @@ func TestUnitEnvironmentWithoutTemplateResource(t *testing.T) {
IsTerragruntRunAll: updatedTemplate.IsTerragruntRunAll,
OrganizationId: updatedTemplate.OrganizationId,
TerragruntTfBinary: updatedTemplate.TerragruntTfBinary,
OpentofuVersion: updatedTemplate.OpentofuVersion,
}

createPayload := client.EnvironmentCreateWithoutTemplate{
Expand All @@ -2092,6 +2094,11 @@ func TestUnitEnvironmentWithoutTemplateResource(t *testing.T) {
terragruntTfBinary = "terragrunt_tf_binary = \"" + template.TerragruntTfBinary + "\""
}

openTofuVersion := ""
if template.OpentofuVersion != "" {
openTofuVersion = "opentofu_version = \"" + template.OpentofuVersion + "\""
}

return fmt.Sprintf(`
resource "%s" "%s" {
name = "%s"
Expand All @@ -2114,6 +2121,7 @@ func TestUnitEnvironmentWithoutTemplateResource(t *testing.T) {
github_installation_id = %d
%s
%s
%s
}
}`,
resourceType, resourceName,
Expand All @@ -2135,6 +2143,7 @@ func TestUnitEnvironmentWithoutTemplateResource(t *testing.T) {
template.GithubInstallationId,
terragruntVersion,
terragruntTfBinary,
openTofuVersion,
)
}

Expand Down Expand Up @@ -2176,7 +2185,7 @@ func TestUnitEnvironmentWithoutTemplateResource(t *testing.T) {
resource.TestCheckResourceAttr(accessor, "terragrunt_working_directory", environment.TerragruntWorkingDirectory),
resource.TestCheckResourceAttr(accessor, "vcs_commands_alias", environment.VcsCommandsAlias),
resource.TestCheckResourceAttr(accessor, "without_template_settings.0.repository", updatedTemplate.Repository),
resource.TestCheckResourceAttr(accessor, "without_template_settings.0.terraform_version", updatedTemplate.TerraformVersion),
resource.TestCheckResourceAttr(accessor, "without_template_settings.0.opentofu_version", updatedTemplate.OpentofuVersion),
resource.TestCheckResourceAttr(accessor, "without_template_settings.0.type", updatedTemplate.Type),
resource.TestCheckResourceAttr(accessor, "without_template_settings.0.path", updatedTemplate.Path),
resource.TestCheckResourceAttr(accessor, "without_template_settings.0.terragrunt_version", updatedTemplate.TerragruntVersion),
Expand Down

0 comments on commit de81881

Please sign in to comment.