Class: Kitchen::Terraform::System

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

Overview

System is the class of objects which are verified by the Terraform Verifier.

Instance Method Summary collapse

Constructor Details

#initialize(configuration_attributes:, logger:) ⇒ Kitchen::Terraform::System

#initialize prepares a new instance of the class.

Parameters:

  • configuration_attributes (::Hash)

    a mapping of configuration attributes.

  • logger (Kitchen::Logger)

    a logger to log messages.

Options Hash (configuration_attributes:):

  • :attrs_outputs (Hash{String=>String})

    a mapping of InSpec attribute names to Terraform output names

  • :hosts (Array<String>)

    a list of static hosts in the system.

  • :hosts_output (String)

    the name of a Terraform output which contains one or more hosts in the system.

  • :name (String)

    the name of the system.

  • :profile_locations (Array<String>)

    a list of the locations of InSpec profiles.



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kitchen/terraform/system.rb', line 40

def initialize(configuration_attributes:, logger:)
  self.attrs = {}
  self.attrs_outputs = configuration_attributes.fetch :attrs_outputs do
    {}
  end.dup
  self.configuration_attributes = configuration_attributes
  self.hosts = configuration_attributes.fetch :hosts do
    []
  end.dup
  self.logger = logger
end

Instance Method Details

#to_sString

Returns a string representation of the system.

Returns:

  • (String)

    a string representation of the system.



53
54
55
# File 'lib/kitchen/terraform/system.rb', line 53

def to_s
  configuration_attributes.fetch(:name).dup
end

#verify(fail_fast:, outputs:, variables:) ⇒ self

#verify verifies the system by executing InSpec.

Parameters:

  • fail_fast (Boolean)

    a toggle to control the fast or slow failure of InSpec.

  • outputs (Hash)

    the Terraform outputs to be utilized as InSpec profile attributes.

  • variables (Hash)

    the Terraform variables to be utilized as InSpec profile attributes.

Returns:

  • (self)

Raises:

  • (Kitchen::ClientError, Kitchen::TransientFailure)

    if verifying the system fails.



64
65
66
67
68
69
70
# File 'lib/kitchen/terraform/system.rb', line 64

def verify(fail_fast:, outputs:, variables:)
  resolve_and_execute fail_fast: fail_fast, outputs: outputs, variables: variables

  self
rescue ::Kitchen::TransientFailure => error
  raise ::Kitchen::TransientFailure, "Verifying the '#{self}' system failed:\n\t#{error.message}"
end