class Kitchen::Terraform::SystemAttrsOutputsResolver
SystemAttrsOutputsResolver
is the class of objects which resolve for systems the attrs which are derived from Terraform
outputs.
Attributes
attrs[RW]
Public Class Methods
new(attrs:)
click to toggle source
initialize prepares a new instance of the class.
@param attrs [Hash] a container for attributes. @return [Kitchen::Terraform::SystemAttrsOutputsResolver]
# File lib/kitchen/terraform/system_attrs_outputs_resolver.rb, line 28 def initialize(attrs:) self.attrs = attrs end
Public Instance Methods
resolve(attrs_outputs:, outputs:)
click to toggle source
resolve
fetches Terraform
outputs and associates them with InSpec
attributes.
@param attrs_outputs [Hash{String=>String}] a mapping of InSpec
attribute names to Terraform
output names. @param outputs [Hash{String=>Hash}] Terraform
outputs. @raise [Kitchen::ClientError] if the resolution fails. @return [self]
# File lib/kitchen/terraform/system_attrs_outputs_resolver.rb, line 38 def resolve(attrs_outputs:, outputs:) resolve_defaults outputs: outputs resolve_configuration attrs_outputs: attrs_outputs self end
Private Instance Methods
resolve_configuration(attrs_outputs:)
click to toggle source
# File lib/kitchen/terraform/system_attrs_outputs_resolver.rb, line 49 def resolve_configuration(attrs_outputs:) attrs_outputs.each_pair do |attr_name, output_name| begin attrs.store attr_name.to_s, attrs.fetch("output_#{output_name}") rescue ::KeyError raise( ::Kitchen::ClientError, "Resolving the system attributes from outputs failed due to the absence of the '#{output_name}' key " \ "from the Terraform outputs in the Kitchen instance state. This error indicates that the available " \ "Terraform outputs need to be updated with `kitchen converge` or that the wrong key was provided." ) end end end
resolve_defaults(outputs:)
click to toggle source
# File lib/kitchen/terraform/system_attrs_outputs_resolver.rb, line 64 def resolve_defaults(outputs:) outputs.each_pair do |output_name, output_body| begin attrs.store output_name.to_s, attrs.store("output_#{output_name}", output_body.fetch(:value)) rescue ::KeyError raise( ::Kitchen::ClientError, "Resolving the system attributes from outputs failed due to the absence of the 'value' key from the " \ "'#{output_name}' Terraform output in the Kitchen instance state. This error indicates that the output " \ "format of `terraform output -json` is unexpected." ) end end end