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

Feat: Breaking Change - default terragrunt_tf_binary to 'opentofu' #980

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

TomerHeber
Copy link
Collaborator

@TomerHeber TomerHeber commented Nov 16, 2024

Issue & Steps to Reproduce / Feature Request

resolves #979

Solution

  1. For terragrunt_tf_binary - implicitly send "opentofu" when terragrunt is enabled and terragrunt_tf_binary has not been set.
  2. In the template body http respone ignore the "opentofu" value in the field terragruntTfBinary if terragrunt_tf_binary has not been set - to avoid drifts.
  3. Updated acceptance tests.

--- breaking change for terraform + terragrunt_tf_binary (must excplicitly state 'terraform' value).

Discussion thread:
https://env0.slack.com/archives/C01QBBEGBEH/p1731500435184849

client/template.go Outdated Show resolved Hide resolved
client/template.go Outdated Show resolved Hide resolved
@@ -410,25 +410,6 @@ func templateCreatePayloadFromParameters(prefix string, d *schema.ResourceData)
return payload, diag.Errorf("schema resource data serialization failed: %v", err)
}

isNew := d.IsNewResource()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was the code to handle only for new resources... this is the breaking change...

@TomerHeber
Copy link
Collaborator Author

/review

@bot-env0 bot-env0 requested a review from a team November 16, 2024 16:50
@@ -1443,7 +1443,7 @@ func resourceEnvironmentImport(ctx context.Context, d *schema.ResourceData, meta
return nil, fmt.Errorf("failed to get template with id %s: %w", templateId, err)
}

if err := templateRead("without_template_settings", template, d, true); err != nil {
if err := templateRead("without_template_settings", template, d); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can explain this file changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was special handling related to import and TerragruntTfBinary - it's no longer needed since we will implicitly default to "opentofu".

If there is a value returned from the http response (when askign for the template) it will be assigned to the schema.

In other words, the code that was handling a special use case related to terraform import and TerragruntTfBinary was removed. So it's no longer required to pass a true/false flag.

Comment on lines +435 to +437
// This is done to avoid drifts in case the backend returns "opentofu", but non is configured in the provider.
// (The provider implicitly defaults to "opentofu").
if template.TerragruntTfBinary == client.OPENTOFU {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. But this PR will do a breaking change on purpose, so why do we need that?
  2. if BE returns "opentofu" and non is configured in the provider, it means this template was "terraform" before. So we should actually set "terraform", or actually show the drift. Am I missing something? i

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the BE returns opentofu - then it's opentofu.
The backend is the source of truth.

However, if nothing is set in the provider - then - the defaul is "opentofu".
For various hashicorp reasons, I can't set default as "opentofu" in the terraform schema. But still want avoid the drift for the "opentofu" case. '' -> 'opentofu'.

If in the backend the value is "terraform" - and nothing was set in the provider - the user will get a drift message terraform -> null. To avoid the drift they will have to explicitly add terragrunt_tf_binary = 'terraform'

Now this is assuming that the backend (source of truth) will always return the correct value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terraform -> null

isn't it '' -> 'terraform'? I didnt get this part

and thanks for the explanation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah - I think you're right. Just flip the examples.

Copy link
Contributor

@razbensimon razbensimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the last question, let's resolve that before the merge
Overall looks good to me 👍🏼

Let's do it in a new minor version, and doc it.

@github-actions github-actions bot added ready to merge PR approved - can be merged once the PR owner is ready and removed pending final review labels Nov 18, 2024
@TomerHeber
Copy link
Collaborator Author

See the last question, let's resolve that before the merge Overall looks good to me 👍🏼

Let's do it in a new minor version, and doc it.

Yes. That's the plan.
Let me know if I should merge it...

@razbensimon
Copy link
Contributor

yea lets

@razbensimon
Copy link
Contributor

Maybe release it after other open PRs, an isolated version of a single change @TomerHeber

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-client feature provider ready to merge PR approved - can be merged once the PR owner is ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Breaking Change - default terragrunt_tf_binary to 'opentofu'
2 participants