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

Terragrunt OpenTofu: reset terraform_version when changing tool #552

Conversation

truszkowski
Copy link
Contributor

@truszkowski truszkowski commented May 9, 2024

Description of the change

Let's reset the version when we're changing the terragrunt tool.

Step 1 - now we have computed the latest for terraform (1.5.7)

resource spacelift_stack this {
  ...
  terragrunt {
    tool = "TERRAGRUNT_FOSS"
  }
}

Step 2 - we expect the latest for opentofu (1.7.1)

resource spacelift_stack this {
  ...
  terragrunt {
    tool = "OPEN_TOFU"
  }
}

Let's reset terraform_version when we're changing tool and terraform_version is not specified in the config.

Let's also take care of terraform_workflow_tool. It's the same situation. We should reset terraform_version in the case of the tool change.

resource spacelift_stack this {
  ...
  terraform_workflow_tool = "TERRAFORM_FOSS"
  ...
}

into:

resource spacelift_stack this {
  ...
  terraform_workflow_tool = "CUSTOM"
  ...
}

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (non-breaking change that adds documentation)

Related issues

Fix #1

Checklists

Development

  • Lint rules pass locally
  • The code changed/added as part of this pull request has been covered with tests
  • All tests related to the changed code pass in development
  • Examples for new resources and data sources have been added
  • Default values have been documented in the description (e.g., "Dummy: (Boolean) Blah blah. Defaults to false.)
  • If the action fails that checks the documentation: Run go generate to make sure the docs are up to date

Code review

  • This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached
  • Pull Request is no longer marked as "draft"
  • Reviewers have been assigned
  • Changes have been reviewed by at least one other engineer

@truszkowski truszkowski requested review from adamconnelly, TheMacies and a team May 9, 2024 13:16
@lorengordon
Copy link

Some interesting overlap here with the issue I opened recently, #540

adamconnelly
adamconnelly previously approved these changes May 9, 2024
@truszkowski
Copy link
Contributor Author

When I changing TERRAFORM_FOSS -> OPEN_TOFU:
Screenshot 2024-05-09 at 15 24 27

And it works but produces a warning:
Screenshot 2024-05-09 at 15 22 51

I've tried to convince Terraform to ignore/handle that but it didn't work.

TheMacies
TheMacies previously approved these changes May 10, 2024
@truszkowski
Copy link
Contributor Author

I've tried to convince Terraform to ignore/handle that but it didn't work.

I thought CustomizeDiff should help, but no. At the stack level, I can't:
Screenshot 2024-05-10 at 13 49 05

I could SetNewComputed("terragrunt") but then showed the plan is more misleading
Screenshot 2024-05-10 at 13 51 51

So, I'll keep it as is:
Screenshot 2024-05-10 at 13 53 46

If we turn on warnings (TF_LOG=warn), we can see the provider silently replaced terraform_version:
Screenshot 2024-05-10 at 13 55 08
Screenshot 2024-05-10 at 13 58 25

@truszkowski truszkowski dismissed stale reviews from TheMacies and adamconnelly via 06f5796 May 14, 2024 09:44
@truszkowski truszkowski requested review from adamconnelly, TheMacies, cube2222 and a team May 14, 2024 10:33
@truszkowski
Copy link
Contributor Author

I've also fixed tests ("terraform-default-" prefix).

adamconnelly
adamconnelly previously approved these changes May 14, 2024
Copy link
Contributor

@adamconnelly adamconnelly left a comment

Choose a reason for hiding this comment

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

LGTM

@marcinwyszynski
Copy link
Contributor

Will it make sense to extend this PR to also fix #547 ? Looks like it's almost the same issue, just with plain Terraform.

@truszkowski truszkowski requested a review from a team May 15, 2024 09:40
@peterdeme
Copy link
Contributor

@truszkowski we merged a fix to the unit tests, can you rebase this? 🙏

@truszkowski truszkowski force-pushed the CU-8694gufw3-Terragrunt-OpenTofu-Reset-versions-when-changing-tool branch from 06f5796 to 057cd04 Compare May 17, 2024 07:19
peterdeme
peterdeme previously approved these changes May 17, 2024
@truszkowski
Copy link
Contributor Author

Will it make sense to extend this PR to also fix #547 ? Looks like it's almost the same issue, just with plain Terraform.

I've made it. So, now, we'll reset terraform_version (if not specified) during terraform_workflow_tool change.

@truszkowski truszkowski force-pushed the CU-8694gufw3-Terragrunt-OpenTofu-Reset-versions-when-changing-tool branch from 257df16 to 3c13324 Compare May 17, 2024 09:52
@marcinwyszynski marcinwyszynski removed their request for review May 17, 2024 10:49
@truszkowski truszkowski merged commit c8054ad into main May 20, 2024
7 checks passed
@truszkowski truszkowski deleted the CU-8694gufw3-Terragrunt-OpenTofu-Reset-versions-when-changing-tool branch May 20, 2024 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants