Class: Kitchen::Terraform::OutputsReader

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

Overview

OutputsReader is the class of objects which read Terraform output variables.

Instance Method Summary collapse

Constructor Details

#initialize(connection:) ⇒ Kitchen::Terraform::OutputsReader

#initialize prepares a new instance of the class.

Parameters:



47
48
49
50
# File 'lib/kitchen/terraform/outputs_reader.rb', line 47

def initialize(connection:)
  self.connection = connection
  self.no_outputs_defined = /no\\ outputs\\ defined/
end

Instance Method Details

#read(command:) {|json_outputs| ... } ⇒ self

#read reads the output variables.

Parameters:

Yield Parameters:

  • json_outputs (String)

    the output variables as a string of JSON.

Returns:

  • (self)

Raises:

  • (Kitchen::TransientFailure)

    if running the output command fails.



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kitchen/terraform/outputs_reader.rb', line 29

def read(command:)
  json_outputs = "{}"

  begin
    json_outputs = connection.execute command
  rescue ::Kitchen::StandardError => error
    no_outputs_defined.match ::Regexp.escape error.original.to_s or raise ::Kitchen::TransientFailure, error.message
  end

  yield json_outputs: json_outputs

  self
end