-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat(terraform): add OpenTofu file extension support #8747
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
base: main
Are you sure you want to change the base?
Conversation
Add support for OpenTofu file extensions (.tofu and .tofu.json) to enable scanning of OpenTofu infrastructure as code files.
|
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.
Pull Request Overview
This PR adds support for OpenTofu file extensions to enable scanning of infrastructure as code files with .tofu and .tofu.json extensions.
- Updated parser logic to recognize tofu file extensions.
- Added test cases to confirm tofu file detection.
- Extended detection logic to include tofu extensions in file type determination.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
pkg/iac/scanners/terraform/parser/parser.go | Updated file parsing to support .tofu and .tofu.json files. |
pkg/iac/detection/detect_test.go | Added tests for tofu file handling with and without readers. |
pkg/iac/detection/detect.go | Expanded extension checking to include tofu extensions. |
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.
Thanks for the PR @jswank - adding support for OpenTofu file extension would imply adding support for OpenTofu scanning as a whole. We haven't committed to doing that just yet - there is an open discussion for it #5069
Having said that, it might be time to do so since OpenTofu has been out for a some time now. There are a couple of issues that if added to OpenTofu will make it diverge from Terraform (and may require changes on our end as well) such as:
- Direct support for conditional single-instance resources opentofu/opentofu#1306
- Support OCI registries for provider and module distribution. opentofu/opentofu#308
cc @nikpivkin @itaysk WDYT?
Thanks for the response @simar7! It does seems like an important consideration for the project- you certainly don't want to imply support of OpenTofu-specific functionality unintentionally. Especially since some divergence in OpenTofu / Terraform capabilities has begun to occur in recent versions. The use case I have is fairly limited: my organization has made the decision to standardize on OpenTofu and is in the process of converting existing Terraform IaC. In order to clearly signify where this conversion has happened, we are renaming Would you be open to a PR which allowed for the TF ( |
Usually, in such cases, Trivy allows customizing file patterns via the
If we decide to support OpenTofu, we will also need to implement support for features that exist exclusively in OpenTofu, and only enable them for files with the At this point, to my understanding and unless I'm missing something, OpenTofu does not contain any changes that could affect our current scanning goals. However, if we add support for the |
My org is currently switching over to only .tofu files and would love to use trivy as before with .tf files so this would be great to have included. In the interim I attempted to do the following:
but am unsuccessful in getting that to work no matter what regex is used:
@nikpivkin Am I missing something obvious or does that flag not work for the misconfig scanner? |
This is not a valid pattern because the first section should specify one of the following scanners. This flag works for most IaC scanners, but not for Terraform. I left a comment above with an explanation. |
@simar7 I've left the comment. Wdyt? I think changing the |
Add support for OpenTofu file extensions (
.tofu
and.tofu.json
) to enable scanning of OpenTofu infrastructure as code files.Description
This PR adds detection support for OpenTofu file extensions (
.tofu
and.tofu.json
). These files are functionally identical to Terraform files but use the OpenTofu extension, allowing Trivy to scan OpenTofu infrastructure as code files.Checklist
I've updated the https://github.com/aquasecurity/trivy/blob/main/docs with the relevant information (if needed).I've added usage information (if the PR introduces new options)Before/After Example
Before
OpenTofu (
.tofu
) files are not recognized as infrastructure as code files.After
OpenTofu (
.tofu
) files are correctly detected and scanned for security issues.