Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(terraform): extend module provider git url parsing #15773

7 changes: 7 additions & 0 deletions lib/modules/manager/terraform/modules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ describe('modules/manager/terraform/modules', () => {
'ssh://github.com/hashicorp/example.repo-123?ref=v1.0.0'
).groups;

const withoutSshHttpHttps = gitTagsRefMatchRegex.exec(
'git@my-gitlab-instance.local:devops/terraform/instance.git?ref=v5.0.0'
).groups;

expect(http.project).toBe('hashicorp/example.repo-123');
expect(http.tag).toBe('v1.0.0');

Expand All @@ -64,6 +68,9 @@ describe('modules/manager/terraform/modules', () => {

expect(ssh.project).toBe('hashicorp/example.repo-123');
expect(ssh.tag).toBe('v1.0.0');

expect(withoutSshHttpHttps.project).toBe('terraform/instance.git');
expect(withoutSshHttpHttps.tag).toBe('v5.0.0');
});
});

Expand Down
13 changes: 5 additions & 8 deletions lib/modules/manager/terraform/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const bitbucketRefMatchRegex = regEx(
/(?:git::)?(?<url>(?:http|https|ssh)?(?::\/\/)?(?:.*@)?(?<path>bitbucket\.org\/(?<workspace>.*)\/(?<project>.*).git\/?(?<subfolder>.*)))\?ref=(?<tag>.*)$/
);
export const gitTagsRefMatchRegex = regEx(
/(?:git::)?(?<url>(?:http|https|ssh):\/\/(?:.*@)?(?<path>.*.*\/(?<project>.*\/.*)))\?ref=(?<tag>.*)$/
/(?:git::)?(?<url>(?:(?:http|https|ssh):\/\/)?(?:.*@)?(?<path>.*\/(?<project>.*\/.*)))\?ref=(?<tag>.*)$/
);
export const azureDevOpsSshRefMatchRegex = regEx(
/(?:git::)?(?<url>git@ssh\.dev\.azure\.com:v3\/(?<organization>[^/]*)\/(?<project>[^/]*)\/(?<repository>[^/]*))(?<modulepath>.*)?\?ref=(?<tag>.*)$/
Expand Down Expand Up @@ -64,7 +64,10 @@ export function analyseTerraformModule(dep: PackageDependency): void {
dep.datasource = BitBucketTagsDatasource.id;
} else if (gitTagsRefMatch?.groups) {
MaronHatoum marked this conversation as resolved.
Show resolved Hide resolved
dep.depType = 'module';
if (gitTagsRefMatch.groups.path.includes('//')) {
if (azureDevOpsSshRefMatch?.groups) {
MaronHatoum marked this conversation as resolved.
Show resolved Hide resolved
dep.depName = `${azureDevOpsSshRefMatch.groups.organization}/${azureDevOpsSshRefMatch.groups.project}/${azureDevOpsSshRefMatch.groups.repository}${azureDevOpsSshRefMatch.groups.modulepath}`;
dep.packageName = azureDevOpsSshRefMatch.groups.url;
} else if (gitTagsRefMatch.groups.path.includes('//')) {
MaronHatoum marked this conversation as resolved.
Show resolved Hide resolved
logger.debug('Terraform module contains subdirectory');
dep.depName = gitTagsRefMatch.groups.path.split('//')[0];
const tempLookupName = gitTagsRefMatch.groups.url.split('//');
Expand All @@ -75,12 +78,6 @@ export function analyseTerraformModule(dep: PackageDependency): void {
}
dep.currentValue = gitTagsRefMatch.groups.tag;
dep.datasource = GitTagsDatasource.id;
} else if (azureDevOpsSshRefMatch?.groups) {
dep.depType = 'module';
dep.depName = `${azureDevOpsSshRefMatch.groups.organization}/${azureDevOpsSshRefMatch.groups.project}/${azureDevOpsSshRefMatch.groups.repository}${azureDevOpsSshRefMatch.groups.modulepath}`;
dep.packageName = azureDevOpsSshRefMatch.groups.url;
dep.currentValue = azureDevOpsSshRefMatch.groups.tag;
dep.datasource = GitTagsDatasource.id;
} else if (source) {
const moduleParts = source.split('//')[0].split('/');
if (moduleParts[0] === '..') {
Expand Down