Class: Kitchen::Terraform::SystemHostsResolver

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

Overview

SystemHostsResolver is the class of objects which resolve the hosts of a system which are contained in Terraform outputs.

Instance Method Summary collapse

Constructor Details

#initialize(outputs:) ⇒ Kitchen::Terraform::SystemHostsResolver

#initialize prepares a new instance of the class.

Parameters:

  • outputs (Hash)

    a map of Terraform output variables.



28
29
30
# File 'lib/kitchen/terraform/system_hosts_resolver.rb', line 28

def initialize(outputs:)
  self.outputs = Hash[outputs]
end

Instance Method Details

#resolve(hosts:, hosts_output:) ⇒ self

#resolve reads the specified Terraform output and stores the value in a list of hosts.

Parameters:

  • hosts (Array)

    the list of hosts.

  • hosts_output (String)

    the name of the Terraform output which contains hosts.

Returns:

  • (self)

Raises:

  • (Kitchen::ClientError)

    if the specified Terraform output is not found.



38
39
40
41
42
43
44
45
46
47
48
49
# 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