diff --git a/lib/modules/manager/terraform/extractors/others/modules.spec.ts b/lib/modules/manager/terraform/extractors/others/modules.spec.ts index 845e7b7c46e0089dd8456a063da42a4d93f717d9..7062f4d39eb494abf7498b93246c8a13f0e3ce90 100644 --- a/lib/modules/manager/terraform/extractors/others/modules.spec.ts +++ b/lib/modules/manager/terraform/extractors/others/modules.spec.ts @@ -4,6 +4,7 @@ import { bitbucketRefMatchRegex, gitTagsRefMatchRegex, githubRefMatchRegex, + hostnameMatchRegex, } from './modules'; describe('modules/manager/terraform/extractors/others/modules', () => { @@ -300,4 +301,22 @@ describe('modules/manager/terraform/extractors/others/modules', () => { }); }); }); + + describe('hostnameMatchRegex', () => { + it('should extact hostname from source url', () => { + const host1 = hostnameMatchRegex.exec( + 'git-lab.git-server.com/my/terraform/module', + )?.groups; + const host2 = hostnameMatchRegex.exec( + 'example.com/my/terraform/module', + )?.groups; + + expect(host1).toEqual({ + hostname: 'git-lab.git-server.com', + }); + expect(host2).toEqual({ + hostname: 'example.com', + }); + }); + }); }); diff --git a/lib/modules/manager/terraform/extractors/others/modules.ts b/lib/modules/manager/terraform/extractors/others/modules.ts index 5ba4f31c3ca1220f7af3b37b3a403dd89ea366d3..21cbddca1f9dd364d6aa5731e634b3fb5d87b508 100644 --- a/lib/modules/manager/terraform/extractors/others/modules.ts +++ b/lib/modules/manager/terraform/extractors/others/modules.ts @@ -21,7 +21,9 @@ export const gitTagsRefMatchRegex = regEx( export const azureDevOpsSshRefMatchRegex = regEx( /(?:git::)?(?<url>git@ssh\.dev\.azure\.com:v3\/(?<organization>[^/]*)\/(?<project>[^/]*)\/(?<repository>[^/]*))(?<modulepath>.*)?\?(depth=\d+&)?ref=(?<tag>.*?)(&depth=\d+)?$/, ); -const hostnameMatchRegex = regEx(/^(?<hostname>([\w|\d]+\.)+[\w|\d]+)/); +export const hostnameMatchRegex = regEx( + /^(?<hostname>[a-zA-Z\d]([a-zA-Z\d-]*\.)+[a-zA-Z\d]+)/, +); export class ModuleExtractor extends DependencyExtractor { getCheckList(): string[] { diff --git a/lib/modules/manager/terragrunt/modules.ts b/lib/modules/manager/terragrunt/modules.ts index 9d71e1e8aa6483a31a4c1e9007b2a59c7b378a4c..0079b18581303b9c461481c9c489586b8a4a69cc 100644 --- a/lib/modules/manager/terragrunt/modules.ts +++ b/lib/modules/manager/terragrunt/modules.ts @@ -20,7 +20,9 @@ export const gitTagsRefMatchRegex = regEx( export const tfrVersionMatchRegex = regEx( /tfr:\/\/(?<registry>.*?)\/(?<org>[^/]+?)\/(?<name>[^/]+?)\/(?<cloud>[^/?]+).*\?(?:ref|version)=(?<currentValue>.*?)$/, ); -const hostnameMatchRegex = regEx(/^(?<hostname>([\w|\d]+\.)+[\w|\d]+)/); +const hostnameMatchRegex = regEx( + /^(?<hostname>[a-zA-Z\d]([a-zA-Z\d-]*\.)+[a-zA-Z\d]+)/, +); export function extractTerragruntModule( startingLine: number,