class Kitchen::Terraform::SystemBastionHostResolver
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.
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::SystemBastionHostResolver]
# File lib/kitchen/terraform/system_bastion_host_resolver.rb, line 28 def initialize(outputs:) self.outputs = Hash[outputs] end
Public Instance Methods
resolve(bastion_host:, bastion_host_output:) { |bastion_host: bastion_host| ... }
click to toggle source
resolve
resolves a bastion host from either the specified Terraform
output or the static value.
@param bastion_host [String] a statically defined host. @param bastion_host_output [String] the name of the Terraform
output which contains a bastion host. @yieldparam bastion_host [String] the bastion host. @raise [Kitchen::ClientError] if the specified Terraform
output is not found. @return [self]
# 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
Private Instance Methods
resolved_output(bastion_host_output:)
click to toggle source
# File lib/kitchen/terraform/system_bastion_host_resolver.rb, line 60 def resolved_output(bastion_host_output:) outputs.fetch bastion_host_output.to_sym rescue ::KeyError raise( ::Kitchen::ClientError, "Resolving the system bastion host failed due to the absence of the '#{bastion_host_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