Skip to content

Commit

Permalink
fix(terragrunt-manager): Update terragrunt packageName
Browse files Browse the repository at this point in the history
Closes renovate/renovate#33370

Fix dependency.packageName evaluated by the terragrunt manager when the
terraform source url contains double slashes and ssh as the protocol (e.g.,
git::ssh://git@mygit.com/hashicorp/example.git//subdir/test?ref=1.1.0 )
  • Loading branch information
mblum14 committed Jan 23, 2025
1 parent 6964458 commit 2f9d3b9
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/modules/manager/terragrunt/__fixtures__/2.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ terraform {
source = "git::ssh://git@mygit.com/hashicorp/example?ref=v1.0.3"
}

# gittags_ssh_subdir
terraform {
source = "git::ssh://git@mygit.com/hashicorp/example//subdir/test?ref=v1.0.4"
}

# invalid, ignored by test since it does not have source on the next line
terraform {
}
Expand Down
5 changes: 5 additions & 0 deletions lib/modules/manager/terragrunt/__fixtures__/3.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ terraform {
source = "git::ssh://git@mygit.com/hashicorp/example?ref=v1.0.3&depth=1"
}

# gittags_ssh_subdir
terraform {
source = "git::ssh://git@mygit.com/hashicorp/example//subdir/test?ref=v1.0.4&depth=1"
}

# invalid, ignored by test since it does not have source on the next line
terraform {
}
Expand Down
5 changes: 5 additions & 0 deletions lib/modules/manager/terragrunt/__fixtures__/4.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ terraform {
source = "git::ssh://git@mygit.com/hashicorp/example?depth=1&ref=v1.0.3"
}

# gittags_ssh_subdir
terraform {
source = "git::ssh://git@mygit.com/hashicorp/example//subdir/test?depth=1&ref=v1.0.4"
}

# invalid, ignored by test since it does not have source on the next line
terraform {
}
Expand Down
27 changes: 24 additions & 3 deletions lib/modules/manager/terragrunt/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,13 @@ describe('modules/manager/terragrunt/extract', () => {
depType: 'gitTags',
packageName: 'ssh://git@mygit.com/hashicorp/example',
},
{
currentValue: 'v1.0.4',
datasource: 'git-tags',
depName: 'mygit.com/hashicorp/example',
depType: 'gitTags',
packageName: 'ssh://git@mygit.com/hashicorp/example',
},
{
skipReason: 'no-source',
},
Expand Down Expand Up @@ -255,7 +262,7 @@ describe('modules/manager/terragrunt/extract', () => {
},
],
});
expect(res?.deps).toHaveLength(36);
expect(res?.deps).toHaveLength(37);
expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4);
});

Expand Down Expand Up @@ -418,6 +425,13 @@ describe('modules/manager/terragrunt/extract', () => {
depType: 'gitTags',
packageName: 'ssh://git@mygit.com/hashicorp/example',
},
{
currentValue: 'v1.0.4',
datasource: 'git-tags',
depName: 'mygit.com/hashicorp/example',
depType: 'gitTags',
packageName: 'ssh://git@mygit.com/hashicorp/example',
},
{
skipReason: 'no-source',
},
Expand Down Expand Up @@ -466,7 +480,7 @@ describe('modules/manager/terragrunt/extract', () => {
},
],
});
expect(res?.deps).toHaveLength(35);
expect(res?.deps).toHaveLength(36);
expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4);
});

Expand Down Expand Up @@ -629,6 +643,13 @@ describe('modules/manager/terragrunt/extract', () => {
depType: 'gitTags',
packageName: 'ssh://git@mygit.com/hashicorp/example',
},
{
currentValue: 'v1.0.4',
datasource: 'git-tags',
depName: 'mygit.com/hashicorp/example',
depType: 'gitTags',
packageName: 'ssh://git@mygit.com/hashicorp/example',
},
{
skipReason: 'no-source',
},
Expand Down Expand Up @@ -677,7 +698,7 @@ describe('modules/manager/terragrunt/extract', () => {
},
],
});
expect(res?.deps).toHaveLength(35);
expect(res?.deps).toHaveLength(36);
expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4);
});

Expand Down
2 changes: 1 addition & 1 deletion lib/modules/manager/terragrunt/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function analyseTerragruntModule(
dep.datasource = detectGitTagDatasource(url);
if (dep.datasource === GitTagsDatasource.id) {
if (containsSubDirectory) {
dep.packageName = `${origin}${pathname.split('//')[0]}`;
dep.packageName = `${protocol}//${host}${pathname.split('//')[0]}`;
} else {
dep.packageName = url;
}
Expand Down

0 comments on commit 2f9d3b9

Please sign in to comment.