Skip to content

feat: update versionmanager to support root.hcl files#369

Merged
kvendingoldo merged 3 commits into
tofuutils:mainfrom
edgar-castle:add-root-hcl-file-support
Mar 11, 2025
Merged

feat: update versionmanager to support root.hcl files#369
kvendingoldo merged 3 commits into
tofuutils:mainfrom
edgar-castle:add-root-hcl-file-support

Conversation

@edgar-castle
Copy link
Copy Markdown
Contributor

@edgar-castle edgar-castle commented Mar 11, 2025

Context

When running plan/applies in newer versions of terragrunt, you now get the following output when the root configuration file is named terragrunt.hcl.

WARN[0000] Using `terragrunt.hcl` as the root of Terragrunt configurations is an anti-pattern, and no longer recommended. 
In a future version of Terragrunt, this will result in an error. You are advised to use a differently named file like `root.hcl` instead.
For more information, see https://terragrunt.gruntwork.io/docs/migrate/migrating-from-root-terragrunt-hcl

Gruntwork now recommends renaming the root config file to root.hcl instead. This PR is to add support for the new recommended naming convention in versionmanager.

Motivation

We've been doing some testing around using tenv to aid with Terraform & Terragrunt version management in our CI pipelines. Some repos use the new root.hcl format and tenv wasn't parsing terraform_version_constraint and
terragrunt_version_constraint since the file was named differently.

I first thought of setting an env var to pass in a different root terragrunt file name instead to make this more customizable. However, most people will likely conform to rename the file using whatever GruntWorks recommends so I figured adding support for the most likely cases was the better approach. It makes using the tool even easier since out of the box it will work with the most common configurations.

Summary of Change

The changes I made should be backwards compatible without changing anyone's current setup.
The following was done:

  1. I updated the consts in gruntparser.go with 2 new consts HCLNameLegacy and JSONNameLegacy and added some Go Doc compliant comments to indicate the move towards the new recommended naming convention.
  2. Added in new VersionFile configs in the tf, tg, and tofu BuildManager functions to now include parsing of the root.hcl & root.hcl.json files in the returned VersionManager struct.
    • I placed it after the terragrunt.hcl and terragrunt.hcl.json parser declarations to ensure this wouldn't break anyone's current setup using the legacy naming convention. So if they have both a terragrunt.hcl file and root.hcl file, the terragrunt.hcl file values will be the ones parsed and utilized.

Testing

I built the binaries then tested out the logic to ensure that it is correctly parsing the legacy and newly named files. I also ensured that the legacy file name takes precedence over the new one.

Terraform Detect Tests
image

Terragrunt Detect Test
tenv_testing_tg

Tofu Detect Test
tenv_testing_tofu

@edgar-castle edgar-castle force-pushed the add-root-hcl-file-support branch from 0d1c555 to 0c02170 Compare March 11, 2025 21:32
Signed-off-by: Edgar Castillo <edgar.castillo@gametime.co>
Signed-off-by: Edgar Castillo <edgar.castillo@gametime.co>
Signed-off-by: Edgar Castillo <edgar.castillo@gametime.co>
@edgar-castle edgar-castle force-pushed the add-root-hcl-file-support branch from 7d734c2 to 7a3e34a Compare March 11, 2025 21:38
Comment thread .changelog/.gitkeep
@edgar-castle edgar-castle marked this pull request as ready for review March 11, 2025 21:42
Copy link
Copy Markdown
Collaborator

@kvendingoldo kvendingoldo left a comment

Choose a reason for hiding this comment

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

Wow! Looks amazing! LGTM

@kvendingoldo kvendingoldo added the enhancement New feature or request label Mar 11, 2025
@kvendingoldo
Copy link
Copy Markdown
Collaborator

Thank you for the contribution, @edgar-castle! I gonna merge it, and make a release.

@edgar-castle
Copy link
Copy Markdown
Contributor Author

Sweeeet, happy to help! 😃

@edgar-castle edgar-castle deleted the add-root-hcl-file-support branch March 11, 2025 23:15
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Mar 24, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [tofuutils/tenv](https://github.com/tofuutils/tenv) | minor | `v4.2.4` -> `v4.4.0` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>tofuutils/tenv (tofuutils/tenv)</summary>

### [`v4.4.0`](https://github.com/tofuutils/tenv/releases/tag/v4.4.0)

[Compare Source](tofuutils/tenv@v4.3.0...v4.4.0)

#### Changelog

-   [`14f8f7d`](tofuutils/tenv@14f8f7d) use EarlyErrorExitCode (42) on proxy failure before proxied command call ([#&#8203;373](tofuutils/tenv#373))
-   [`9981094`](tofuutils/tenv@9981094) Fix Readme syntax for Jekyll compatibility
-   [`8ebb9ca`](tofuutils/tenv@8ebb9ca) Update bages
-   [`458ba45`](tofuutils/tenv@458ba45) Fix dots in README.md
-   [`0d50464`](tofuutils/tenv@0d50464) go: bump github.com/BurntSushi/toml from 1.4.0 to 1.5.0 ([#&#8203;378](tofuutils/tenv#378))
-   [`11c8e9b`](tofuutils/tenv@11c8e9b) go: bump github.com/stretchr/testify from 1.8.4 to 1.10.0 ([#&#8203;375](tofuutils/tenv#375))
-   [`4bd46f8`](tofuutils/tenv@4bd46f8) chore(deps): bump github.com/go-git/go-git/v5 in /tools
-   [`226c7e4`](tofuutils/tenv@226c7e4) chore(deps): bump golang.org/x/net from 0.32.0 to 0.36.0 in /tools
-   [`5ccaee3`](tofuutils/tenv@5ccaee3) Add end-to-end tests for the latest features
-   [`8804b3d`](tofuutils/tenv@8804b3d) tidy
-   [`812d6ca`](tofuutils/tenv@812d6ca) Add TENV_SKIP_LAST_USE and improve file permissions consistency ([#&#8203;372](tofuutils/tenv#372))
-   [`ca79866`](tofuutils/tenv@ca79866) go: bump github.com/charmbracelet/lipgloss from 1.0.0 to 1.1.0 ([#&#8203;371](tofuutils/tenv#371))

### [`v4.3.0`](https://github.com/tofuutils/tenv/releases/tag/v4.3.0)

[Compare Source](tofuutils/tenv@v4.2.4...v4.3.0)

#### Changelog

-   [`ef2d597`](tofuutils/tenv@ef2d597) Merge pull request [#&#8203;369](tofuutils/tenv#369) from edgar-castle/add-root-hcl-file-support
-   [`7a3e34a`](tofuutils/tenv@7a3e34a) chore: add changelog file
-   [`a3e364d`](tofuutils/tenv@a3e364d) feat: ensure HCLNameLegacy and JSONNameLegacy are parsed first
-   [`0c32ac1`](tofuutils/tenv@0c32ac1) feat: update versionmanager to support root.hcl files
-   [`4eae74e`](tofuutils/tenv@4eae74e) Disable deprecated tenv linter
-   [`59b90ad`](tofuutils/tenv@59b90ad) Add basic end to end tests
-   [`a62b2f9`](tofuutils/tenv@a62b2f9) Merge pull request [#&#8203;366](tofuutils/tenv#366) from tofuutils/dependabot/go_modules/github.com/ProtonMail/gopenpgp/v2-2.8.3
-   [`cbb426c`](tofuutils/tenv@cbb426c) go: bump github.com/ProtonMail/gopenpgp/v2 from 2.8.2 to 2.8.3
-   [`9378b0c`](tofuutils/tenv@9378b0c) go: bump github.com/charmbracelet/bubbletea from 1.3.3 to 1.3.4 ([#&#8203;365](tofuutils/tenv#365))
-   [`d538c9e`](tofuutils/tenv@d538c9e) Merge pull request [#&#8203;364](tofuutils/tenv#364) from tofuutils/dependabot/github_actions/sigstore/cosign-installer-3.8.1
-   [`49b29ca`](tofuutils/tenv@49b29ca) gh-actions: bump sigstore/cosign-installer from 3.8.0 to 3.8.1
-   [`6d429b4`](tofuutils/tenv@6d429b4) go: bump github.com/spf13/cobra from 1.8.1 to 1.9.1 ([#&#8203;359](tofuutils/tenv#359))
-   [`349bcfd`](tofuutils/tenv@349bcfd) Merge pull request [#&#8203;363](tofuutils/tenv#363) from Nmishin/feat/goreleaser
-   [`28e8952`](tofuutils/tenv@28e8952) Fix goreleaser deprecations
-   [`7439866`](tofuutils/tenv@7439866) Merge pull request [#&#8203;361](tofuutils/tenv#361) from Nmishin/fix/golangci-img
-   [`306a435`](tofuutils/tenv@306a435) Update check-golangci-lint.yml
-   [`dd68c23`](tofuutils/tenv@dd68c23) Merge pull request [#&#8203;362](tofuutils/tenv#362) from Nmishin/feat/cloudsmiths
-   [`fdf6da8`](tofuutils/tenv@fdf6da8) Include more linux distributives to the cloudsmiths config
-   [`863d910`](tofuutils/tenv@863d910) Update check golangci-lint GH action
-   [`55e9301`](tofuutils/tenv@55e9301) Merge pull request [#&#8203;360](tofuutils/tenv#360) from Nmishin/fix/golangci
-   [`7c0b680`](tofuutils/tenv@7c0b680) Fix golangci-lint configuration
-   [`8120be4`](tofuutils/tenv@8120be4) Merge pull request [#&#8203;358](tofuutils/tenv#358) from tofuutils/dependabot/go_modules/github.com/PuerkitoBio/goquery-1.10.2
-   [`6dc3bf4`](tofuutils/tenv@6dc3bf4) go: bump github.com/PuerkitoBio/goquery from 1.10.1 to 1.10.2
-   [`4ce0309`](tofuutils/tenv@4ce0309) Merge pull request [#&#8203;357](tofuutils/tenv#357) from tofuutils/dependabot/go_modules/github.com/charmbracelet/bubbletea-1.3.3
-   [`2386032`](tofuutils/tenv@2386032) go: bump github.com/charmbracelet/bubbletea from 1.3.2 to 1.3.3
-   [`bb6426e`](tofuutils/tenv@bb6426e) Merge pull request [#&#8203;356](tofuutils/tenv#356) from tofuutils/dependabot/go_modules/github.com/charmbracelet/bubbletea-1.3.2
-   [`4c254b8`](tofuutils/tenv@4c254b8) go: bump github.com/charmbracelet/bubbletea from 1.3.0 to 1.3.2

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xOTQuMCIsInVwZGF0ZWRJblZlciI6IjM5LjIxMC4xIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJSZW5vdmF0ZSBCb3QiXX0=-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants