terragrunt: terragrunt conflicts with tfenv
Hello,
OS macOS 10.14 trying to install terragrunt
$ brew install terragrunt
Updating Homebrew… ==> Auto-updated Homebrew! Updated 1 tap (homebrew/core). No changes to formulae.
==> Installing dependencies for terragrunt: terraform ==> Installing terragrunt dependency: terraform Error: Cannot install terraform because conflicting formulae are installed. tfenv: because tfenv symlinks terraform binaries
Please
brew unlink tfenvbefore continuing.
Unlinking removes a formula’s symlinks from /usr/local. You can link the formula again after the install finishes. You can --force this install, but the build may fail or cause obscure side-effects in the resulting software.
So terragrunt won’t install because of Tfenv exists. Any help ?
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 1
- Comments: 16 (3 by maintainers)
You can just skip dependencies when installing:
Or in a Brewfile (Homebrew Bundle):
Then it can be installed via
brew bundle.But I’d also prefer terraform not to be a hard dependency. Though I couldn’t find the source for the Homebrew config to propose a change.
The real fix is to just remove the dependency, as terragrunt does not require it to actually execute, it’s an external dependency. Anyone using terragrunt, already knows they will need terraform, as it will also give you an error if you run it without terraform installed.
@MacFlurry I ran into this same issue and this was my workaround. I use tfenv to use the terraform version
0.11.7Verify before
Workaround will unlink
tfenv, installterragruntwhich installs the latest version ofterraform(which it depends on), and then we can relinktfenvto use the original0.11.7versionVerify after
And according to
terragrunt --help, it looks like it will default to use the terraform on PATH.An issue with using a Brewfile with
ignore-dependenciesis that flag is ignored on upgrades, giving the same linking issues. Since homebrew core doesn’t support options which would allow terraform install to be optional, I’m considering a PR to remove terraform as a dependency and adding info about installing terraform/tfenv in the caveats section. Curious what others, especially maintainers might think about this.I was able to implement a workaround for this using a git
post-mergehook. Here’s how to do it:cd $(brew --repo homebrew/core)to get to the repo root.From there, create a file under
.git/hookscalledpost-merge. The file should contain the following (if you already have apost-mergefile for some reason, add the code after the first line):Make sure the file is executable:
chmod +x .git/hooks/post-mergeNote that if you use
gnu-sed(installed asgsed) instead ofsednative in macOS, you’ll need to modify the last line slightly:And if you are running linux, I think this should work:
With this hook, whenever you run
brew updateandterragrunt.rbis included in the update, the dependency onterraformwill be removed from the updated file. Then when you runbrew upgrade, the upgrade will succeed without havingterraforminstalled via homebrew.I was worried that having a modified version of the
terragruntformula would cause an error the next timebrew updateran with a terraform change, but there was just an update today that succeeded, so I think this works.Can we take another crack at getting this done?
https://github.com/Homebrew/homebrew-core/pull/73326 was closed because the reviewer noted that it’s a poor user experience to install terragrunt via homebrew and have it not work due to terraform not being installed. I don’t disagree, but installing and updating terraform with homebrew does not work well for teams managing a lot of infrastructure across multiple providers with terraform! For example:
brew upgradethat included a newer version of terraform. This causes theterraform applyfor other users (and CI/CD pipelines!) to fail until they are also upgraded, because terraform won’t let you runapplywith an older version than what was captured in remote state. To prevent this from recurring, we added therequired_versionattribute to all of our terraform stacks.required_versionis older than the latest available in homebrew, it’s hard for team members to stay in sync with homebrew.brew install terraform. Instead, they need to find an earlier homebrew commit where the required version was the lastest, check out that commit, then runbrew install terraform.brew upgradebrew upgrade, the team needs to runbrew switch terraform <older version>to re-activate the correct version.Also, the experience for
tfenvusers is not good. Similar to above, I now have to do the following every time there’s a terraform or terragrunt homebrew update:I think terraform should absolutely be removed as a dependency, but a
caveatssection can be added that will be displayed to users after runningbrew install terragrunt(orbrew info terragrunt) that instructs users to install terrafrom either viabrew install tfenv; tfenv install <terraform version>(preferred) orbrew install terraform.I’ve made a PR trying the options used here https://stackoverflow.com/questions/21115259/alternative-dependencies-in-a-homebrew-formula-e-g-for-use-with-gcc
If they won’t accept this, perhaps we should add a tap to this repo?
Hi, this approach is working for me and I assume (from the 🚀 responses) at least a few others. My first suggestion is to double-check that you did everything above correctly:
post-mergefile in the.gitfolder within thehomebrew-corefolder (mine is under/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core.post-mergefile has execute permissions.sedthat comes pre-installed in MacOS (running the commandwhich sedshould return/usr/bin/sed). If you have installed another version ofsed(e.g., gnu sed from homebrew) you’ll need to change that last line to make the intended change with your version ofsed.If that still doesn’t work, you could write a small script that will manually run the
sedcommand against theterragrunt.rbfile. Run the command manually before the next time you runbrew upgrade. Then run the command after anybrew upgradethat includes a new version of terragrunt. You could also create an alias to do this automatically after every upgrade so you don’t have to think about it:Hope that helps!
Based on the response from the Homebrew folks, sounds like just don’t use brew to install terragrunt.
No joy! In the first PR it sounded like homebrew was amenable to the removal of terraform as a dependency as long as there were clear instructions to the user. In the 2nd PR, they made it clear that even with clear instructions for how to install terraform separately, they will not allow removal of terraform as a dependency in homebrew-core, because then the formula may not work when installed. They suggested creating a separate homebrew tap, then the formula can be managed however we want. If someone at gruntwork wants to take this up:
gruntwork-ioaccount. If there are other gruntwork tools that might be included in the future, it would probably make sense to name the repohomebrew-gruntworkinstead ofhomebrew-terragrunt.