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.



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

def initialize(command:, logger:, options:)
  self.command = command
  self.logger = logger
  self.shell_out = ::Mixlib::ShellOut.new(
    command,
    options.merge(
      environment: { "LC_ALL" => nil, "TF_IN_AUTOMATION" => "true", "TF_WARN_OUTPUT_ERRORS" => "1" },
      live_stream: logger,
    )
  )
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.



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

def run
  execute_workflow

  yield standard_output: shell_out.stdout

  self
end