-
Notifications
You must be signed in to change notification settings - Fork 532
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
feat: iac experimental terraform support #1654
Conversation
37989df
to
c2133f5
Compare
|
18c419d
to
5c7c74e
Compare
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.
Looking great so far. Are you planning to add unit tests for this PR? I think we're at the point now where we'll want to consider them so it doesn't become a big task to add them later. Nor do we accidentally write the code in ways that make it harder to test in the future.
docId, | ||
}; | ||
} else { | ||
throw new Error('Invalid K8s File!'); |
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.
Would be really nice to include the missing fields here.
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.
Opened a task for it:
https://snyksec.atlassian.net/browse/CC-700
Will include it as part of the beta-overhaul with the other tasks we opened.
return tryParsingKubernetesFile(fileContent, fileMetadata); | ||
} catch (err) { | ||
// TODO: if it's also not TF file then we should error | ||
return [tryParsingTerraformFile(fileContent, fileMetadata)]; |
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.
I think your comment covers this but this will mask the above error and look like a failed Terraform file right? Perhaps we should do this a) only if fileType === "json"
and b) rethrow the original error if tryParsingTerraformFile
also errors.
I'm planning to add the unit-tests together with the dir support story (next one), as there are still lots changes until we reach that core-feature parity state in the experimental version. |
b3502c4
to
f1cc1a9
Compare
@@ -77,6 +77,7 @@ | |||
"configstore": "^5.0.1", | |||
"debug": "^4.1.1", | |||
"diff": "^4.0.1", | |||
"hcl-to-json": "^0.1.1", |
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.
Decide how to proceed with hcl-to-json lib and HCL2 syntax validations.
https://github.com/gokmen/hcl-to-json
Seeing it's an archived and unmaintained project, is there an alternative?
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.
you are correct, it was an informed decision to start with it as a temporary "unblocker" solution.
as generally there is no good HCL-2-JSON parser npm package out there.
we are aware of it's limitations and it was an informed decision to start with it taking into account it's a "good-enough" approach for the dog-fooding internal releases.
For the public beta and long-term solution, we will probably do one of the following:
- generate a Golang HCL to JSON parser into WASM and use it.
OR
- include HCL to JSON parsing inside our Terraform scanning wasm file, so you can just provide it with HCL.
@@ -48,4 +48,48 @@ Describe "Snyk iac test --experimental command" | |||
The result of function check_valid_json should be success | |||
End | |||
End | |||
|
|||
Describe "terraform single file scan" |
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.
Would you run this only in the Regression test and not in the smoke test? I don't think we need hourly checks of this.
With this after the Describe
like above:
Skip if "execute only in regression test" check_if_regression_test
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.
yes will add it as a regression 👍
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.
👍 Looks good, nice work. Looks like we need to add the new WebAssembly fixtures for the tests to be happy.
b3c455c
to
5a92c16
Compare
case 'tf': | ||
return [tryParsingTerraformFile(fileContent, fileMetadata)]; | ||
default: | ||
throw new Error('Invalid IaC file'); |
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.
Could have a more descriptive message e.g.
throw new Error('Invalid IaC file'); | |
throw new Error(`Unsupported filetype ${fileMetadata.fileType }`); |
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.
going to do a bit of an overhaul to the error handling in the next pr for Dir-Support, will take care of it over there.
tnx 👍
f4da83d
to
d9abb7f
Compare
d9abb7f
to
ae474a2
Compare
ae474a2
to
b455497
Compare
Expected release notes (by @rontalx) features: others (will not be included in Semantic-Release notes):
|
What does this PR do?
Adds Single Terraform file scan support to the:
snyk iac test --experimental
command.Running Locally
In order to run locally, checkout the branch, build and run the local built version.
make sure to download the
.iac-data
from here and place it in your CWD root folder where you're running the CLI from.e.g:
TODO
.wasm
file for terraform regression tests.hcl-to-json
lib and HCL2 syntax validations.