class Kitchen::Terraform::SystemHostsResolver
SystemHostsResolver
is the class of objects which resolve the hosts of a system which are contained in Terraform
outputs.
Attributes
outputs[RW]
Public Class Methods
new(outputs:)
click to toggle source
initialize prepares a new instance of the class.
@param outputs [Hash] a map of Terraform
output variables. @return [Kitchen::Terraform::SystemHostsResolver]
# File lib/kitchen/terraform/system_hosts_resolver.rb, line 28 def initialize(outputs:) self.outputs = Hash[outputs] end
Public Instance Methods
resolve(hosts:, hosts_output:)
click to toggle source
resolve
reads the specified Terraform
output and stores the value in a list of hosts.
@param hosts [Array] the list of hosts. @param hosts_output [String] the name of the Terraform
output which contains hosts. @raise [Kitchen::ClientError] if the specified Terraform
output is not found. @return [self]
# File lib/kitchen/terraform/system_hosts_resolver.rb, line 38 def resolve(hosts:, hosts_output:) hosts.concat Array resolved_output(hosts_output: hosts_output).fetch :value self rescue ::KeyError raise( ::Kitchen::ClientError, "Resolving the system hosts failed due to the absence of the 'value' key from the '#{hosts_output}' " \ "Terraform output of the Kitchen instance state. This error indicates that the output format of " \ "`terraform output -json` is unexpected." ) end
Private Instance Methods
resolved_output(hosts_output:)
click to toggle source
# File lib/kitchen/terraform/system_hosts_resolver.rb, line 55 def resolved_output(hosts_output:) outputs.fetch hosts_output.to_sym rescue ::KeyError raise( ::Kitchen::ClientError, "Resolving the system hosts failed due to the absence of the '#{hosts_output}' key from the Terraform " \ "outputs of the Kitchen instance state. This error indicates either that `kitchen converge` must be " \ "executed again to update the Terraform outputs or that the wrong key was provided." ) end