class Kitchen::Terraform::System
System
is the class of objects which are verified by the Terraform
Verifier
.
Attributes
Public Class Methods
initialize prepares a new instance of the class.
@param configuration_attributes
[::Hash] a mapping of configuration attributes. @param logger [Kitchen::Logger] a logger to log messages. @option configuration_attributes
[Hash{String=>String}] :attrs_outputs a mapping of InSpec
attribute names to
Terraform output names
@option configuration_attributes
[Array<String>] :hosts a list of static hosts in the system. @option configuration_attributes
[String] :hosts_output the name of a Terraform
output which contains one or
more hosts in the system.
@option configuration_attributes
[String] :name the name of the system. @option configuration_attributes
[Array<String>] :profile_locations a list of the locations of InSpec
profiles. @return [Kitchen::Terraform::System]
# 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
Public Instance Methods
@return [String] a string representation of the system.
# File lib/kitchen/terraform/system.rb, line 53 def to_s configuration_attributes.fetch(:name).dup end
verify
verifies the system by executing InSpec
.
@param fail_fast [Boolean] a toggle to control the fast or slow failure of InSpec
. @param outputs [Hash] the Terraform
outputs to be utilized as InSpec
profile attributes. @param variables [Hash] the Terraform
variables to be utilized as InSpec
profile attributes. @raise [Kitchen::ClientError, Kitchen::TransientFailure] if verifying the system fails. @return [self]
# 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
Private Instance Methods
# File lib/kitchen/terraform/system.rb, line 76 def execute_inspec_runner(fail_fast:, options:) ::Kitchen::Terraform::InSpecFactory.new(fail_fast: fail_fast, hosts: hosts).build( options: options, profile_locations: configuration_attributes.fetch(:profile_locations), ).exec end
# File lib/kitchen/terraform/system.rb, line 83 def inspec_options(outputs:) ::Kitchen::Terraform::InSpecOptionsFactory.new(outputs: outputs).build( attributes: attrs, system_configuration_attributes: configuration_attributes, ) end
# File lib/kitchen/terraform/system.rb, line 90 def resolve(outputs:, variables:) ::Kitchen::Terraform::SystemAttrsInputsResolver.new(attrs: attrs).resolve inputs: variables ::Kitchen::Terraform::SystemHostsResolver.new(outputs: outputs).resolve( hosts: hosts, hosts_output: configuration_attributes.fetch(:hosts_output), ) if configuration_attributes.key? :hosts_output ::Kitchen::Terraform::SystemAttrsOutputsResolver.new(attrs: attrs).resolve( attrs_outputs: attrs_outputs, outputs: outputs, ) rescue ::Kitchen::ClientError => error raise ::Kitchen::ClientError, "Verifying the '#{self}' system failed:\n\t#{error.message}" end
# File lib/kitchen/terraform/system.rb, line 104 def resolve_and_execute(fail_fast:, outputs:, variables:) logger.warn "Verifying the '#{self}' system..." resolve outputs: outputs, variables: variables execute_inspec_runner fail_fast: fail_fast, options: inspec_options(outputs: outputs) logger.warn "Finished verifying the '#{self}' system." end