Skip to content

Commit

Permalink
Add tfvars filetype (#821)
Browse files Browse the repository at this point in the history
Terraform and tofu can run on `.tfvars` files (although notably not
`.tfvars.json`). Adds this filetype

Also attempts to fix trivy test failures.
  • Loading branch information
TylerJang27 authored Jul 9, 2024
1 parent bfc2036 commit c08593f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions linters/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,11 @@ lint:
comments:
- hash

- name: tfvars
extensions:
# terraform/tofu can't format .tfvars.json files
- tfvars

- name: toml
extensions:
- toml
Expand Down
2 changes: 1 addition & 1 deletion linters/terraform/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 0.1
lint:
definitions:
- name: terraform
files: [terraform]
files: [terraform, tfvars]
tools: [terraform]
description: Validate and format terraform files
commands:
Expand Down
2 changes: 1 addition & 1 deletion linters/tofu/plugin.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 0.1
lint:
definitions:
- name: tofu
files: [terraform]
files: [terraform, tfvars]
tools: [tofu]
description: A Terraform validator and formatter
commands:
Expand Down
15 changes: 13 additions & 2 deletions linters/trivy/trivy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,20 @@ const callbackGenerator =
const trunkYamlPath = ".trunk/trunk.yaml";
const currentContents = driver.readFile(trunkYamlPath);
const trivyRegex = /- trivy@(.+)\n/;

// fs-vuln, config sometimes fail in CI to query DB concurrently.
const extraContents = `
definitions:
- name: trivy
commands:
- name: fs-vuln
max_concurrency: 1
- name: config
max_concurrency: 1
`;
const newContents = currentContents.replace(
trivyRegex,
`- trivy@$1:\n commands: [${command}]\n`,
`- trivy@$1:\n commands: [${command}]\n${extraContents}`,
);
driver.writeFile(trunkYamlPath, newContents);
if (otherPreCheck) {
Expand Down Expand Up @@ -42,7 +53,7 @@ fuzzyLinterCheckTest({
linterName: "trivy",
testName: "fs-vuln",
args: "-a",
fileIssueAssertionCallback: createFuzzyMatcher(() => vulnExpectedFileIssues, 30),
fileIssueAssertionCallback: createFuzzyMatcher(() => vulnExpectedFileIssues, 20),
preCheck: callbackGenerator("fs-vuln"),
});

Expand Down

0 comments on commit c08593f

Please sign in to comment.