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
DEFAULT_REGISTRY =
"registry.terraform.io"
DEFAULT_NAMESPACE =
"hashicorp"
PROVIDER_SOURCE_ADDRESS =
%r{\A((?<hostname>.+)/)?(?<namespace>.+)/(?<name>.+)\z}.freeze

Instance Method Summary collapse

Instance Method Details

#parseObject


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/dependabot/terraform/file_parser.rb', line 28

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

    parsed_file(file).fetch("terraform", []).each do |terraform|
      required_providers = terraform.fetch("required_providers", {})
      required_providers.each do |provider|
        provider.each do |name, details|
          dependency_set << build_provider_dependency(file, name, details)
        end
      end
    end
  end

  terragrunt_files.each do |file|
    modules = parsed_file(file).fetch("terraform", [])
    modules.each do |details|
      next unless details["source"]

      dependency_set << build_terragrunt_dependency(file, details)
    end
  end

  dependency_set.dependencies.sort_by(&:name)
end