Skip to content

Commit

Permalink
fix(terraform): support subdirectories (#6354)
Browse files Browse the repository at this point in the history
  • Loading branch information
TerrapinStation committed May 29, 2020
1 parent 21b606e commit 0fcd548
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/manager/terraform/__fixtures__/1.tf
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,7 @@ module "gittags" {
module "gittags_badversion" {
source = "git::https://bitbucket.com/hashicorp/example?ref=next"
}

module "gittags_subdir" {
source = "git::https://bitbucket.com/hashicorp/example//subdir/test?ref=v1.0.0"
}
8 changes: 8 additions & 0 deletions lib/manager/terraform/__snapshots__/extract.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ Object {
"lookupName": "https://bitbucket.com/hashicorp/example",
"skipReason": "unsupported-version",
},
Object {
"currentValue": "v1.0.0",
"datasource": "git-tags",
"depName": "bitbucket.com/hashicorp/example",
"depNameShort": "hashicorp/example",
"depType": "gitTags",
"lookupName": "https://bitbucket.com/hashicorp/example",
},
],
}
`;
2 changes: 1 addition & 1 deletion lib/manager/terraform/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('lib/manager/terraform/extract', () => {
it('extracts', () => {
const res = extractPackageFile(tf1);
expect(res).toMatchSnapshot();
expect(res.deps).toHaveLength(24);
expect(res.deps).toHaveLength(25);
expect(res.deps.filter((dep) => dep.skipReason)).toHaveLength(6);
});
it('returns null if only local deps', () => {
Expand Down
14 changes: 11 additions & 3 deletions lib/manager/terraform/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,19 @@ export function extractPackageFile(content: string): PackageFile | null {
}
} else if (gitTagsRefMatch) {
dep.depType = 'gitTags';
dep.depName = gitTagsRefMatch[2].replace('.git', '');
dep.depNameShort = gitTagsRefMatch[3].replace('.git', '');
if (gitTagsRefMatch[2].includes('//')) {
logger.debug('Terraform module contains subdirectory');
dep.depName = gitTagsRefMatch[2].split('//')[0];
dep.depNameShort = dep.depName.split(/\/(.+)/)[1];
const tempLookupName = gitTagsRefMatch[1].split('//');
dep.lookupName = tempLookupName[0] + '//' + tempLookupName[1];
} else {
dep.depName = gitTagsRefMatch[2].replace('.git', '');
dep.depNameShort = gitTagsRefMatch[3].replace('.git', '');
dep.lookupName = gitTagsRefMatch[1];
}
dep.currentValue = gitTagsRefMatch[4];
dep.datasource = datasourceGitTags.id;
dep.lookupName = gitTagsRefMatch[1];
dep.managerData.lineNumber = dep.managerData.sourceLine;
if (!isVersion(dep.currentValue)) {
dep.skipReason = SkipReason.UnsupportedVersion;
Expand Down

0 comments on commit 0fcd548

Please sign in to comment.