Class: Kitchen::Terraform::VerifyVersion

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/terraform/verify_version.rb

Overview

VerifyVersion is the class of objects which verify the version of the Terraform client against a version requirement.

Instance Method Summary collapse

Constructor Details

#initialize(config:, logger:, version_requirement:) ⇒ Kitchen::Terraform::VerifyVersion

#initialize prepares a new instance of the class.

Parameters:

  • config (Hash)

    the configuration of the driver.

  • logger (Kitchen::Logger)

    a logger for logging messages.

  • version_requirement (Gem::VersionRequirement)

    the required version of the Terraform client.

Options Hash (config:):

  • :verify_version (Boolean)

    a toggle of strict or permissive verification of support for the version of the Terraform client.



51
52
53
54
55
56
57
58
59
60
# File 'lib/kitchen/terraform/verify_version.rb', line 51

def initialize(config:, logger:, version_requirement:)
  self.finish_message = "Finished verifying the Terraform client version."
  self.logger = logger
  self.rescue_strategy = ::Kitchen::Terraform::VerifyVersionRescueStrategyFactory.new(
    verify_version: config.fetch(:verify_version),
  ).build logger: logger
  self.start_message = "Verifying the Terraform client version is in the supported interval of " \
                       "#{version_requirement}..."
  self.version_verifier = ::Kitchen::Terraform::VersionVerifier.new version_requirement: version_requirement
end

Instance Method Details

#call(version:) ⇒ self

#call invokes the verification.

Parameters:

  • version (Gem::Version)

    the Terraform client version.

Returns:

  • (self)

Raises:

  • (Kitchen::ActionFailed)

    if the verification fails.



33
34
35
36
37
38
39
40
41
# File 'lib/kitchen/terraform/verify_version.rb', line 33

def call(version:)
  logger.warn start_message
  version_verifier.verify version: version
  logger.warn finish_message
rescue ::Kitchen::Terraform::UnsupportedClientVersionError
  rescue_strategy.call

  self
end