Class: Kitchen::Terraform::SystemBastionHostResolver

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

Overview

SystemBastionHostResolver is the class of objects which resolve a bastion host of a system which may be either dynamically obtained from a Terraform output variable or statically defined.

Instance Method Summary collapse

Constructor Details

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

#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_bastion_host_resolver.rb', line 28

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

Instance Method Details

#resolve(bastion_host:, bastion_host_output:) {|bastion_host| ... } ⇒ self

#resolve resolves a bastion host from either the specified Terraform output or the static value.

Parameters:

  • bastion_host (String)

    a statically defined host.

  • bastion_host_output (String)

    the name of the Terraform output which contains a bastion host.

Yield Parameters:

  • bastion_host (String)

    the bastion host.

Returns:

  • (self)

Raises:

  • (Kitchen::ClientError)

    if the specified Terraform output is not found.



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/kitchen/terraform/system_bastion_host_resolver.rb', line 39

def resolve(bastion_host:, bastion_host_output:)
  if !bastion_host.empty?
    yield bastion_host: bastion_host
  elsif !bastion_host_output.empty?
    yield bastion_host: resolved_output(bastion_host_output: bastion_host_output).fetch(:value)
  end

  self
rescue ::KeyError
  raise(
    ::Kitchen::ClientError,
    "Resolving the system bastion host failed due to the absence of the 'value' key from the " \
    "'#{bastion_host_output}' Terraform output of the Kitchen instance state. This error indicates that the " \
    "output format of `terraform output -json` is unexpected."
  )
end