diff --git a/lib/modules/manager/terragrunt/__fixtures__/2.hcl b/lib/modules/manager/terragrunt/__fixtures__/2.hcl index f38c3924453967..2141ad2d1cbdc3 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/2.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/2.hcl @@ -175,6 +175,16 @@ terraform { source = "git::https://gitlab.com/hashicorp/example?ref=v1.0.0" } +# gitlab-tags https with custom port +terraform { + source = "git::https://gitlab.com:4321/hashicorp/example?ref=v1.0.1" +} + +# gitlab-tags ssh with custom port +terraform { + source = "git::ssh://gitlab.com:1234/hashicorp/example?ref=v1.0.2" +} + # gitea-tags terraform { source = "git::https://gitea.com/hashicorp/example?ref=v1.0.0" diff --git a/lib/modules/manager/terragrunt/__fixtures__/3.hcl b/lib/modules/manager/terragrunt/__fixtures__/3.hcl index 3cf9e16f8bca42..7e6967d5e3a41c 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/3.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/3.hcl @@ -175,6 +175,16 @@ terraform { source = "git::https://gitlab.com/hashicorp/example?ref=v1.0.0" } +# gitlab-tags https with custom port +terraform { + source = "git::https://gitlab.com:4321/hashicorp/example?ref=v1.0.1" +} + +# gitlab-tags ssh with custom port +terraform { + source = "git::ssh://gitlab.com:1234/hashicorp/example?ref=v1.0.2" +} + # gitea-tags terraform { source = "git::https://gitea.com/hashicorp/example?ref=v1.0.0" diff --git a/lib/modules/manager/terragrunt/__fixtures__/4.hcl b/lib/modules/manager/terragrunt/__fixtures__/4.hcl index 2eef263e14e3d5..6bce778dea0630 100644 --- a/lib/modules/manager/terragrunt/__fixtures__/4.hcl +++ b/lib/modules/manager/terragrunt/__fixtures__/4.hcl @@ -176,6 +176,16 @@ terraform { source = "git::https://gitlab.com/hashicorp/example?ref=v1.0.0" } +# gitlab-tags https with custom port +terraform { + source = "git::https://gitlab.com:4321/hashicorp/example?ref=v1.0.1" +} + +# gitlab-tags ssh with custom port +terraform { + source = "git::ssh://gitlab.com:1234/hashicorp/example?ref=v1.0.2" +} + # gitea-tags terraform { source = "git::https://gitea.com/hashicorp/example?ref=v1.0.0" diff --git a/lib/modules/manager/terragrunt/extract.spec.ts b/lib/modules/manager/terragrunt/extract.spec.ts index 90eaca7caf16e5..c54270a9b00898 100644 --- a/lib/modules/manager/terragrunt/extract.spec.ts +++ b/lib/modules/manager/terragrunt/extract.spec.ts @@ -222,6 +222,22 @@ describe('modules/manager/terragrunt/extract', () => { packageName: 'hashicorp/example', registryUrls: ['https://gitlab.com'], }, + { + currentValue: 'v1.0.1', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'hashicorp/example', + registryUrls: ['https://gitlab.com:4321'], + }, + { + currentValue: 'v1.0.2', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'hashicorp/example', + registryUrls: ['https://gitlab.com'], + }, { currentValue: 'v1.0.0', datasource: 'gitea-tags', @@ -232,7 +248,7 @@ describe('modules/manager/terragrunt/extract', () => { }, ], }); - expect(res?.deps).toHaveLength(33); + expect(res?.deps).toHaveLength(35); expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); }); @@ -417,6 +433,22 @@ describe('modules/manager/terragrunt/extract', () => { packageName: 'hashicorp/example', registryUrls: ['https://gitlab.com'], }, + { + currentValue: 'v1.0.1', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'hashicorp/example', + registryUrls: ['https://gitlab.com:4321'], + }, + { + currentValue: 'v1.0.2', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'hashicorp/example', + registryUrls: ['https://gitlab.com'], + }, { currentValue: 'v1.0.0', datasource: 'gitea-tags', @@ -427,7 +459,7 @@ describe('modules/manager/terragrunt/extract', () => { }, ], }); - expect(res?.deps).toHaveLength(33); + expect(res?.deps).toHaveLength(35); expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); }); @@ -612,6 +644,22 @@ describe('modules/manager/terragrunt/extract', () => { packageName: 'hashicorp/example', registryUrls: ['https://gitlab.com'], }, + { + currentValue: 'v1.0.1', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'hashicorp/example', + registryUrls: ['https://gitlab.com:4321'], + }, + { + currentValue: 'v1.0.2', + datasource: 'gitlab-tags', + depName: 'gitlab.com/hashicorp/example', + depType: 'gitTags', + packageName: 'hashicorp/example', + registryUrls: ['https://gitlab.com'], + }, { currentValue: 'v1.0.0', datasource: 'gitea-tags', @@ -622,7 +670,7 @@ describe('modules/manager/terragrunt/extract', () => { }, ], }); - expect(res?.deps).toHaveLength(33); + expect(res?.deps).toHaveLength(35); expect(res?.deps.filter((dep) => dep.skipReason)).toHaveLength(4); }); diff --git a/lib/modules/manager/terragrunt/modules.ts b/lib/modules/manager/terragrunt/modules.ts index c214abb4570825..3b9821460086c6 100644 --- a/lib/modules/manager/terragrunt/modules.ts +++ b/lib/modules/manager/terragrunt/modules.ts @@ -68,27 +68,29 @@ export function analyseTerragruntModule( dep.currentValue = githubRefMatch.groups.tag; dep.datasource = GithubTagsDatasource.id; } else if (gitTagsRefMatch?.groups) { - const { url, host, path, tag } = gitTagsRefMatch.groups; - const containsSubDirectory = path.includes('//'); + const { url, tag } = gitTagsRefMatch.groups; + const { hostname, host, origin, pathname, protocol } = new URL(url); + const containsSubDirectory = pathname.includes('//'); if (containsSubDirectory) { logger.debug('Terragrunt module contains subdirectory'); } dep.depType = 'gitTags'; // We don't want to have .git or subdirectory in the depName - dep.depName = `${host}/${path.split('//')[0].replace('.git', '')}`; + dep.depName = `${hostname}${pathname.split('//')[0].replace('.git', '')}`; dep.currentValue = tag; dep.datasource = detectGitTagDatasource(url); if (dep.datasource === GitTagsDatasource.id) { if (containsSubDirectory) { - const [protocol, hostAndPath] = url.split('//'); - dep.packageName = `${protocol}//${hostAndPath}`; + dep.packageName = `${origin}${pathname.split('//')[0]}`; } else { dep.packageName = url; } } else { // The packageName should only contain the path to the repository - dep.packageName = path.split('//')[0]; - dep.registryUrls = [`https://${host}`]; + dep.packageName = pathname.replace(/^\//, '').split('//')[0]; + dep.registryUrls = [ + protocol === 'https:' ? `https://${host}` : `https://${hostname}`, + ]; } } else if (tfrVersionMatch?.groups) { dep.depType = 'terragrunt';