Skip to content

Conversation

@eugenestarchenko
Copy link
Contributor

@eugenestarchenko eugenestarchenko commented Dec 30, 2025

Problem

Terragrunt's valid tfr:/// (triple slash) format fails in autodiscovery with:

invalid module registry hostname ""

Root Cause

Both the parser and matching rule code strip tfr:// from URLs, but this leaves a leading slash when the format is tfr:///:

Example:

  • Input: tfr:///terraform-aws-modules/eks/aws
  • After stripping tfr://: /terraform-aws-modules/eks/aws
  • Leading slash breaks ParseModuleSource

In matching rules with wildcards:

  • Pattern: tfr:/// (match all registry modules)
  • After stripping tfr://: / remains
  • Code adds wildcards: tfr:////updatecliswildcard/updatecliswildcard/updatecliswildcard
  • Creates invalid 4-slash URLs that fail parsing

Why not use 2 slash format?

The test suite uses tfr://terraform-aws-modules/... (2 slashes), which works in Updatecli but fails in actual Terragrunt:

$ terragrunt init
ERROR: lookup terraform-aws-modules: no such host

Per URL spec protocol://hostname/path, the 2-slash format treats terraform-aws-modules as a hostname, causing DNS lookup failures.

Valid Terragrunt formats:

  • tfr:///terraform-aws-modules/eks/aws (3 slashes = empty hostname → defaults to registry.terraform.io)
  • tfr://registry.terraform.io/terraform-aws-modules/eks/aws (explicit registry)

Invalid in Terragrunt:

  • tfr://terraform-aws-modules/eks/aws (2 slashes = namespace treated as hostname)

See https://terragrunt.gruntwork.io/docs/reference/hcl/blocks/#terraform

Result

All valid Terragrunt formats now work:

  • tfr:///namespace/name/target (valid Terragrunt)
  • tfr://namespace/name/target (invalid Terragrunt, but backward compatible)
  • tfr://registry.terraform.io/namespace/name/target (valid Terragrunt)

Testing

Verified with real Terragrunt module:

# Before: 0 manifests detected
# After:  1 manifest detected
# Found update: terraform-aws-modules/eks/aws//modules/karpenter 20.35.0 → 21.10.1

Fixes parsing of Terragrunt module sources using the tfr:/// (triple slash)
format, which is the valid Terragrunt syntax for default registry.

The current implementation fails on tfr:/// because it constructs baseUrl
with a leading slash (/terraform-aws-modules/eks/aws) which ParseModuleSource
rejects.

URL format: protocol://hostname/path
- tfr:///namespace/name/target → Host="", Path="/namespace/name/target"
- tfr://registry.io/namespace/name/target → Host="registry.io", Path="/namespace/name/target"
- tfr://namespace/name/target → Host="namespace", Path="/name/target"

The 2-slash format (tfr://terraform-aws-modules/...) works in Updatecli's
parser by accident but FAILS in actual Terragrunt with "lookup terraform-aws-modules:
no such host" because it treats the namespace as a hostname.

This fix strips the leading slash and correctly handles all valid formats.
Update all test files and test expectations to use the valid tfr:///
(triple slash) format instead of the invalid tfr:// (two slash) format.

Changes:
- testdata/*.hcl: Updated module sources to tfr:///
- main_test.go: Updated expected manifest outputs
- matching_rule_test.go: Updated test cases and assertions
- matching_rule.go: Updated documentation example
@eugenestarchenko eugenestarchenko force-pushed the fix/terragrunt-tfr-triple-slash branch from 9585e1e to d6836f3 Compare December 30, 2025 21:16
The matching rule code strips 'tfr://' from patterns, leaving an
extra slash when the pattern is 'tfr:///'. This causes invalid
wildcard URLs like 'tfr:////updatecliswildcard'.

Add TrimPrefix to remove the leading slash after stripping the protocol,
ensuring correct token counting for wildcard expansion.

Also update utils_test.go expectations to use tfr:/// format.
@eugenestarchenko
Copy link
Contributor Author

Hi @olblak how does that look to you?

@olblak
Copy link
Member

olblak commented Dec 31, 2025

Thanks @eugenestarchenko for the pull request.
It's on my list of things to look into but I am still on vacation with limited time here.

@olblak
Copy link
Member

olblak commented Jan 1, 2026

Thanks for the pull request, it looks great to me especially with the test
@eugenestarchenko Could you fix the linting warning by running go fmt?

I'll merge it once done

@olblak olblak added bug Something isn't working resource-terragrunt labels Jan 1, 2026
olblak
olblak previously approved these changes Jan 1, 2026
@eugenestarchenko
Copy link
Contributor Author

go fmt

done

@olblak olblak enabled auto-merge (squash) January 1, 2026 16:20
@olblak olblak merged commit 29139e5 into updatecli:main Jan 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working resource-terragrunt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants