Skip to content

Commit

Permalink
fix(terraform): check line validity (#12102)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Oct 10, 2021
1 parent f74404b commit da1b7d5
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions lib/manager/terraform/providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,25 @@ export function extractTerraformProvider(
}

const line = lines[lineNumber];
// `{` will be counted wit +1 and `}` with -1. Therefore if we reach braceCounter == 0. We have found the end of the terraform block
const openBrackets = (line.match(/\{/g) || []).length;
const closedBrackets = (line.match(/\}/g) || []).length;
braceCounter = braceCounter + openBrackets - closedBrackets;
if (line) {
// `{` will be counted wit +1 and `}` with -1. Therefore if we reach braceCounter == 0. We have found the end of the terraform block
const openBrackets = (line.match(/\{/g) || []).length;
const closedBrackets = (line.match(/\}/g) || []).length;
braceCounter = braceCounter + openBrackets - closedBrackets;

// only update fields inside the root block
if (braceCounter === 1) {
const kvMatch = keyValueExtractionRegex.exec(line);
if (kvMatch) {
if (kvMatch.groups.key === 'version') {
dep.currentValue = kvMatch.groups.value;
} else if (kvMatch.groups.key === 'source') {
dep.managerData.source = kvMatch.groups.value;
dep.managerData.sourceLine = lineNumber;
// only update fields inside the root block
if (braceCounter === 1) {
const kvMatch = keyValueExtractionRegex.exec(line);
if (kvMatch) {
if (kvMatch.groups.key === 'version') {
dep.currentValue = kvMatch.groups.value;
} else if (kvMatch.groups.key === 'source') {
dep.managerData.source = kvMatch.groups.value;
dep.managerData.sourceLine = lineNumber;
}
}
}
}

lineNumber += 1;
} while (braceCounter !== 0);
deps.push(dep);
Expand Down

0 comments on commit da1b7d5

Please sign in to comment.