Class: Kitchen::Terraform::ShellOut

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

Overview

Terraform commands are run by shelling out and using the command-line interface. The shell out environment includes the TF_IN_AUTOMATION environment variable as specified by the Running Terraform in Automation guide.

Instance Method Summary collapse

Constructor Details

#initialize(command:, logger:, options:) ⇒ Kitchen::Terraform::CommandExecutor

#initialize prepares a new instance of the class.

Parameters:

  • command (String)

    the command to run.

  • logger (Kitchen::Logger)

    a logger for logging messages.

  • options (Hash)

    options which adjust the execution of the command.



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/kitchen/terraform/shell_out.rb', line 34

def initialize(command:, logger:, options:)
  self.command = command
  self.logger = logger
  self.shell_out = ::Mixlib::ShellOut.new(
    command,
    {
      environment: { "LC_ALL" => nil, "TF_IN_AUTOMATION" => "true" },
      live_stream: logger,
    }.merge(options)
  )
end

Instance Method Details

#run {|standard_output| ... } ⇒ self

#run executes a command.

Yield Parameters:

  • standard_output (String)

    the standard output of the command.

Returns:

  • (self)

Raises:

  • (Kitchen::TransientFailure)

    if running the command results in failure.



51
52
53
54
55
56
57
# File 'lib/kitchen/terraform/shell_out.rb', line 51

def run
  execute_workflow

  yield shell_out.stdout

  self
end