-
Notifications
You must be signed in to change notification settings - Fork 14
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: add support for running terragrunt with opentofu #785
Conversation
@@ -128,6 +130,10 @@ func (payload *TemplateCreatePayload) Invalidate() error { | |||
return errors.New("must supply opentofu version") | |||
} | |||
|
|||
if payload.TerragruntTfBinary != "" && payload.Type != "terragrunt" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to avoid setting TerragruntTfBinary
without a template of type terragrunt
.
@@ -239,6 +239,12 @@ func getTemplateSchema(prefix string) map[string]*schema.Schema { | |||
ConflictsWith: allVCSAttributesBut("helm_chart_name", "is_helm_repository"), | |||
RequiredWith: requiredWith("helm_chart_name"), | |||
}, | |||
"terragrunt_tf_binary": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could not set a deault value to "OpenTofu".
Default will only make sense if this was a "Terragrunt" template.
This is also an issue with existing templates that will use "Terrafrom" and not "OpenTofu".
I tried a few options. At the end I had to manually handle this unique use-case.
This makes the PR a little more complex than usual.
env0/resource_template.go
Outdated
} else { | ||
// No value was set - if it's a new template resource of type 'terragrunt' - default to 'opentofu' | ||
if templateType == "terragrunt" && isNew { | ||
payload.TerragruntTfBinary = "opentofu" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's a new terragrunt template send opentofu in the creation request
env0/resource_template.go
Outdated
|
||
// If the user has set a value - use it. | ||
if terragruntTfBinary := d.Get(terragruntTfBinaryKey).(string); terragruntTfBinary != "" { | ||
payload.TerragruntTfBinary = terragruntTfBinary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the user manually configured terragrunt_tf_binary use it.
} | ||
|
||
path, pathOk := d.GetOk(pathPrefix) | ||
terragruntTfBinary := d.Get(terragruntTfBinaryPrefix).(string) | ||
|
||
// If this value isn't set, ignore whatever is returned from the response. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a long explanation here. Hopefully it's clear enough.
Basically, if the user hasn't set anything in the schema ignore the response. This is to avoid drifts.
@@ -1899,9 +1899,11 @@ func TestUnitEnvironmentWithoutTemplateResource(t *testing.T) { | |||
ErrorRegex: "RetryMeForDestroy.*", | |||
}, | |||
}, | |||
Type: "terraform", | |||
Type: "terragrunt", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This impacts an environment with a template.
Wanted to test that use-case as well. In this case the user explicitly mentioned here wants to use "terraform" instead of "opentofu".
IsGitlabEnterprise: true, | ||
TerraformVersion: "0.12.24", | ||
TerragruntVersion: "0.35.1", | ||
TerragruntTfBinary: "opentofu", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, user has set nothing. Defaults to opentofu when the template is created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good nice coding and comments really helped me understand what is going on
btw. you can also integrate tenv that support Terraform as well as OpenTofu (and Terragrunt :) ) in one tool. It allow you to simplify version management. |
Issue & Steps to Reproduce / Feature Request
resolves #784
Solution