Class: Dependabot::Terraform::RequirementsUpdater
- Inherits:
-
Object
- Object
- Dependabot::Terraform::RequirementsUpdater
- Extended by:
- T::Sig
- Defined in:
- lib/dependabot/terraform/requirements_updater.rb
Overview
Takes an array of ‘requirements` hashes for a dependency at the old version and a new version, and generates a set of new `requirements` hashes at the new version.
A requirements hash is a basic description of a dependency at a certain version constraint, and it includes the data that is needed to update the manifest (i.e. the ‘.tf` file) with the new version.
A requirements hash looks like this for a registry hosted requirement: “‘ruby {
requirement: "~> 0.2.1",
groups: [],
file: "main.tf",
source: {
type: "registry",
registry_hostname: "registry.terraform.io",
module_identifier: "hashicorp/consul/aws"
}
}
And like this for a git requirement: “‘ruby {
requirement: nil,
groups: [],
file: "main.tf",
source: {
type: "git",
url: "https://github.com/cloudposse/terraform-null-label.git",
branch: nil,
ref: nil
}
}
Instance Method Summary collapse
-
#initialize(requirements:, latest_version:, tag_for_latest_version:) ⇒ RequirementsUpdater
constructor
A new instance of RequirementsUpdater.
- #updated_requirements ⇒ Object
Constructor Details
#initialize(requirements:, latest_version:, tag_for_latest_version:) ⇒ RequirementsUpdater
Returns a new instance of RequirementsUpdater.
63 64 65 66 67 68 69 70 71 |
# File 'lib/dependabot/terraform/requirements_updater.rb', line 63 def initialize(requirements:, latest_version:, tag_for_latest_version:) @requirements = requirements @tag_for_latest_version = tag_for_latest_version return unless latest_version return unless version_class.correct?(latest_version) @latest_version = T.let(version_class.new(latest_version), Dependabot::Terraform::Version) end |
Instance Method Details
#updated_requirements ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/dependabot/terraform/requirements_updater.rb', line 79 def updated_requirements # NOTE: Order is important here. The FileUpdater needs the updated # requirement at index `i` to correspond to the previous requirement # at the same index. requirements.map do |req| case req.dig(:source, :type) when "git" then update_git_requirement(req) when "registry", "provider" then update_registry_requirement(req) else req end end end |