Class: Dependabot::Terraform::FileUpdater

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

Constant Summary collapse

PRIVATE_MODULE_ERROR =
/Could not download module.*code from\n.*\"(?<repo>\S+)\":/.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.updated_files_regexObject


16
17
18
# File 'lib/dependabot/terraform/file_updater.rb', line 16

def self.updated_files_regex
  [/\.tf$/, /\.hcl$/]
end

Instance Method Details

#updated_dependency_filesObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dependabot/terraform/file_updater.rb', line 20

def updated_dependency_files
  updated_files = []

  [*terraform_files, *terragrunt_files].each do |file|
    next unless file_changed?(file)

    updated_content = updated_terraform_file_content(file)

    raise "Content didn't change!" if updated_content == file.content

    updated_files << updated_file(file: file, content: updated_content)
  end
  updated_lockfile_content = update_lockfile_declaration(updated_files)

  if updated_lockfile_content && lock_file.content != updated_lockfile_content
    updated_files << updated_file(file: lock_file, content: updated_lockfile_content)
  end

  updated_files.compact!

  raise "No files changed!" if updated_files.none?

  updated_files
end