Class: Kitchen::Terraform::InSpecRunner

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

Overview

InSpecRunner is the class of objects which act as interfaces to the InSpec gem.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options:, profile_locations:) ⇒ Kitchen::Terraform::InSpecRunner

#initialize prepares a new instance of the class.

Parameters:

  • options (Hash)

    options to configure the runner.

  • profile_locations (Array<String>)

    a list of pathnames of profiles.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/kitchen/terraform/inspec_runner.rb', line 59

def initialize(options:, profile_locations:)
  self.host = options.fetch :host do
    ""
  end

  ::Inspec::Plugin::V2::Loader.new.tap do |loader|
    loader.load_all
    loader.exit_on_load_error
  end

  self.runner = ::Inspec::Runner.new options.merge logger: ::Inspec::Log.logger

  profile_locations.each do |profile_location|
    runner.add_target profile_location
  end
end

Class Method Details

.logger=(logger) ⇒ Kitchen::Logger

.logger= sets the logger for all InSpec processes.

The logdev of the logger is extended to conform to interface expected by InSpec.

Parameters:

  • logger (Kitchen::Logger)

    the logger to use.

Returns:

  • (Kitchen::Logger)

    the logger.



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

def logger=(logger)
  logger.logdev.define_singleton_method :filename do
    false
  end

  ::Inspec::Log.logger = logger
end

Instance Method Details

#execself

#exec executes InSpec.

Returns:

  • (self)

Raises:

  • (Kitchen::TransientFailure)

    if the execution of InSpec fails.



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

def exec
  run do |exit_code:|
    if 0 != exit_code
      raise ::Kitchen::TransientFailure, "#{action} failed due to a non-zero exit code of #{exit_code}."
    end
  end

  self
end