Skip to content

Commit

Permalink
fix(terragunt): ignore port when creating registry urls (#28653)
Browse files Browse the repository at this point in the history
  • Loading branch information
lstoeferle committed Apr 26, 2024
1 parent 376a2a5 commit ec9f553
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 10 deletions.
10 changes: 10 additions & 0 deletions lib/modules/manager/terragrunt/__fixtures__/2.hcl
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions lib/modules/manager/terragrunt/__fixtures__/3.hcl
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions lib/modules/manager/terragrunt/__fixtures__/4.hcl
Expand Up @@ -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"
Expand Down
54 changes: 51 additions & 3 deletions lib/modules/manager/terragrunt/extract.spec.ts
Expand Up @@ -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',
Expand All @@ -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);
});

Expand Down Expand Up @@ -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',
Expand All @@ -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);
});

Expand Down Expand Up @@ -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',
Expand All @@ -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);
});

Expand Down
16 changes: 9 additions & 7 deletions lib/modules/manager/terragrunt/modules.ts
Expand Up @@ -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';
Expand Down

0 comments on commit ec9f553

Please sign in to comment.