-
Notifications
You must be signed in to change notification settings - Fork 62
Add tofu tool and linter #707
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| version: 0.1 | ||
| lint: | ||
| definitions: | ||
| - name: tofu | ||
| files: [terraform] | ||
| tools: [tofu] | ||
| commands: | ||
| - name: validate | ||
| # Custom parser type defined in the trunk cli to handle tofu's JSON output. | ||
| output: terraform_validate | ||
| target: ${parent} | ||
| run: tofu validate -json | ||
| run_from: ${target_directory} | ||
| success_codes: [0, 1] | ||
| enabled: false | ||
| - name: fmt | ||
| output: rewrite | ||
| formatter: true | ||
| run: tofu fmt -no-color - | ||
| stdin: true | ||
| success_codes: [0] | ||
| cache_results: true | ||
| suggest_if: never | ||
| environment: | ||
| - name: PATH | ||
| list: ["${linter}"] | ||
| - name: GITHUB_APP_ID | ||
| value: ${env.GITHUB_APP_ID} | ||
| optional: true | ||
| - name: GITHUB_APP_INSTALLATION_ID | ||
| value: ${env.GITHUB_APP_INSTALLATION_ID} | ||
| optional: true | ||
| - name: GITHUB_APP_PEM_FILE | ||
| value: ${env.GITHUB_APP_PEM_FILE} | ||
| optional: true | ||
| known_good_version: 1.6.2 | ||
| version_command: | ||
| parse_regex: ${semver} | ||
| run: tofu --version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Testing linter tofu test variables 1`] = ` | ||
| { | ||
| "issues": [ | ||
| { | ||
| "code": "Invalid quoted type constraints", | ||
| "file": "test_data/variables.in.tf", | ||
| "issueClass": "ISSUE_CLASS_EXISTING", | ||
| "level": "LEVEL_HIGH", | ||
| "line": "2", | ||
| "linter": "tofu", | ||
| "message": "OpenTofu 0.11 and earlier required type constraints to be given in quotes, but that form is now deprecated and will be removed in a future version of OpenTofu. Remove the quotes around "map" and write map(string) instead to explicitly indicate that the map elements are strings.", | ||
| "targetType": "terraform", | ||
| }, | ||
| ], | ||
| "lintActions": [ | ||
| { | ||
| "command": "fmt", | ||
| "fileGroupName": "terraform", | ||
| "linter": "tofu", | ||
| "paths": [ | ||
| "test_data/variables.in.tf", | ||
| ], | ||
| "verb": "TRUNK_VERB_FMT", | ||
| }, | ||
| { | ||
| "command": "validate", | ||
| "fileGroupName": "terraform", | ||
| "linter": "tofu", | ||
| "paths": [ | ||
| "test_data", | ||
| ], | ||
| "verb": "TRUNK_VERB_CHECK", | ||
| }, | ||
| { | ||
| "command": "validate", | ||
| "fileGroupName": "terraform", | ||
| "linter": "tofu", | ||
| "paths": [ | ||
| "test_data", | ||
| ], | ||
| "upstream": true, | ||
| "verb": "TRUNK_VERB_CHECK", | ||
| }, | ||
| ], | ||
| "taskFailures": [], | ||
| "unformattedFiles": [ | ||
| { | ||
| "column": "1", | ||
| "file": "test_data/variables.in.tf", | ||
| "issueClass": "ISSUE_CLASS_UNFORMATTED", | ||
| "level": "LEVEL_HIGH", | ||
| "line": "1", | ||
| "linter": "tofu", | ||
| "message": "Incorrect formatting, autoformat by running 'trunk fmt'", | ||
| }, | ||
| ], | ||
| } | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`Testing formatter tofu test variables 1`] = ` | ||
| "variable "ssl_certificates" { | ||
| type = map(string) | ||
| default = { | ||
| lorem-elb-us-west-3 = "lorem" | ||
| ipsum-elb-us-east-1 = "ipsum" | ||
| dolor-elb-us-east-2 = "dolor" | ||
| } | ||
| } | ||
| " | ||
| `; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| variable "ssl_certificates" { | ||
| type = "map" | ||
| default = { | ||
| lorem-elb-us-west-3 = "lorem" | ||
| ipsum-elb-us-east-1 = "ipsum" | ||
| dolor-elb-us-east-2 = "dolor" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { linterCheckTest, linterFmtTest } from "tests"; | ||
| import { TrunkLintDriver } from "tests/driver"; | ||
|
|
||
| // Due to tofu's validate subcommand being disabled by default, we need to manually enable it in our test's trunk.yaml. | ||
| const preCheck = (driver: TrunkLintDriver) => { | ||
| const trunkYamlPath = ".trunk/trunk.yaml"; | ||
| const currentContents = driver.readFile(trunkYamlPath); | ||
| const sqlfluffRegex = /- tofu@(.+)\n/; | ||
| const newContents = currentContents.replace( | ||
| sqlfluffRegex, | ||
| "- tofu@$1:\n commands: [validate, fmt]\n", | ||
| ); | ||
| driver.writeFile(trunkYamlPath, newContents); | ||
| }; | ||
|
|
||
| linterCheckTest({ linterName: "tofu", preCheck }); | ||
|
|
||
| linterFmtTest({ linterName: "tofu" }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| version: 0.1 | ||
| downloads: | ||
| - name: tofu | ||
| version: 1.6.2 | ||
| downloads: | ||
| - os: | ||
| linux: linux | ||
| macos: darwin | ||
| windows: windows | ||
| cpu: | ||
| x86_64: amd64 | ||
| arm_64: arm64 | ||
| url: https://github.com/opentofu/opentofu/releases/download/v${version}/tofu_${version}_${os}_${cpu}.zip | ||
| tools: | ||
| definitions: | ||
| - name: tofu | ||
| download: tofu | ||
| shims: [tofu] | ||
| known_good_version: 1.6.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { makeToolTestConfig, toolTest } from "tests"; | ||
| toolTest({ | ||
| toolName: "tofu", | ||
| toolVersion: "1.6.2", | ||
| testConfigs: [ | ||
| makeToolTestConfig({ | ||
| command: ["tofu", "--version"], | ||
| expectedOut: "OpenTofu v1.6.2", | ||
| }), | ||
| ], | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this should be renamed (in the terraform test too 🙃 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have 14 instances of this, will break into its own PR :)