Skip to content

Commit

Permalink
terraform: skip support files during parsing (#10328)
Browse files Browse the repository at this point in the history
* terraform: skip support files during parsing
* add spec for checking skip of support file

---------

Co-authored-by: kbukum1 <[email protected]>
  • Loading branch information
jakecoffman and kbukum1 authored Jan 28, 2025
1 parent 064cf8a commit 1cf9d09
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions terraform/lib/dependabot/terraform/file_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ def ecosystem

private

# rubocop:disable Metrics/PerceivedComplexity
sig { params(dependency_set: Dependabot::FileParsers::Base::DependencySet).void }
def parse_terraform_files(dependency_set)
terraform_files.each do |file|
next if file.support_file?

modules = parsed_file(file).fetch("module", {})
# If override.tf files are present, we need to merge the modules
if override_terraform_files.any?
Expand Down Expand Up @@ -86,6 +89,7 @@ def parse_terraform_files(dependency_set)
end
end
end
# rubocop:enable Metrics/PerceivedComplexity

sig { params(dependency_set: Dependabot::FileParsers::Base::DependencySet).void }
def parse_terragrunt_files(dependency_set)
Expand Down
15 changes: 15 additions & 0 deletions terraform/spec/dependabot/terraform/file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,21 @@
end
end
end

context "when a file is a support file" do
let(:support_file) do
Dependabot::DependencyFile.new(
name: "support.tf",
content: "module { source = 'foo/bar' }",
support_file: true
)
end
let(:files) { [support_file] }

it "skips the file and does not parse it" do
expect(dependencies).to be_empty
end
end
end

describe "#source_type" do
Expand Down

0 comments on commit 1cf9d09

Please sign in to comment.