Class: Kitchen::Terraform::InSpecOptionsFactory

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

Overview

InSpecOptionsMapper is the class of objects which build Inspec options.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outputs:) ⇒ Kitchen::Terraform::InSpecOptionsFactory

#initialize prepares a new instance of the class.

Parameters:

  • outputs (Hash)

    the Terraform output variables.



58
59
60
61
62
# File 'lib/kitchen/terraform/inspec_options_factory.rb', line 58

def initialize(outputs:)
  self.options = { "distinct_exit" => false }
  self.system_bastion_host_resolver = ::Kitchen::Terraform::SystemBastionHostResolver.new outputs: outputs
  self.system_inspec_map = ::Kitchen::Terraform::SYSTEM_INSPEC_MAP.dup
end

Class Method Details

.inputs_keySymbol

#inputs_key provides a key for InSpec profile inputs which depends on the version of InSpec.

Returns:

  • (Symbol)

    if the version is less than 4.3.2, :attributes; else, :inputs.



30
31
32
33
34
35
36
# File 'lib/kitchen/terraform/inspec_options_factory.rb', line 30

def inputs_key
  if ::Gem::Requirement.new("< 4.3.2").satisfied_by? ::Gem::Version.new ::Inspec::VERSION
    :attributes
  else
    :inputs
  end
end

Instance Method Details

#build(attributes:, system_configuration_attributes:) ⇒ Hash

#build creates a mapping of InSpec options. Most key-value pairs are derived from the configuration attributes of a system; some key-value pairs are hard-coded.

Parameters:

  • attributes (Hash)

    the attributes to be added to the InSpec options.

  • system_configuration_attributes (Hash)

    the configuration attributes of a system.

Returns:

  • (Hash)

    a mapping of InSpec options.

Raises:

  • (Kitchen::ClientError)

    if the system bastion host fails to be resolved.



46
47
48
49
50
51
52
# File 'lib/kitchen/terraform/inspec_options_factory.rb', line 46

def build(attributes:, system_configuration_attributes:)
  map_system_to_inspec system_configuration_attributes: system_configuration_attributes
  options.store self.class.inputs_key, attributes
  resolve_bastion_host system_configuration_attributes: system_configuration_attributes

  options
end