Class: Dependabot::Terraform::FileParser

Inherits:
FileParsers::Base
  • Object
show all
Includes:
FileSelector
Defined in:
lib/dependabot/terraform/file_parser.rb

Constant Summary collapse

ARCHIVE_EXTENSIONS =
%w(.zip .tbz2 .tgz .txz).freeze

Instance Method Summary collapse

Instance Method Details

#parseObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dependabot/terraform/file_parser.rb', line 24

def parse
  dependency_set = DependencySet.new

  terraform_files.each do |file|
    modules = parsed_file(file).fetch("module", {})
    modules.each do |name, details|
      dependency_set << build_terraform_dependency(file, name, details)
    end
  end

  terragrunt_files.each do |file|
    # legacy terragrunt (.tfvars) files have a top-level "terragrunt" key
    # that has since been removed.
    legacy_modules = (parsed_file(file).fetch("terragrunt", []).first || {}).fetch("terraform", [])
    modules = parsed_file(file).fetch("terraform", []) + legacy_modules
    modules.each do |details|
      next unless details["source"]

      dependency_set << build_terragrunt_dependency(file, details)
    end
  end

  dependency_set.dependencies.sort_by(&:name)
end