Class: Kitchen::Terraform::CommandExecutor

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

Overview

CommandExecutor is the class of objects which execute Terraform CLI commands.

Instance Method Summary collapse

Constructor Details

#initialize(client:, logger:) ⇒ Kitchen::Terraform::CommandExecutor

#initialize prepares a new instance of the class.

Parameters:

  • client (String)

    the pathname of the Terraform client.

  • logger (Kitchen::Logger)

    a logger for logging messages.



29
30
31
32
# File 'lib/kitchen/terraform/command_executor.rb', line 29

def initialize(client:, logger:)
  self.client = client
  self.logger = logger
end

Instance Method Details

#run(command:, options:) {|standard_output| ... } ⇒ self

#run executes a client command.

Parameters:

  • command (String)

    the command to run.

  • options (Hash)

    options which adjust the execution of the command.

Options Hash (options:):

  • :timeout (Integer)

    the maximum duration in seconds to run the command.

  • :cwd (String)

    the directory in which to run the command.

Yield Parameters:

  • standard_output (String)

    the standard output of the command.

Returns:

  • (self)

Raises:

  • (Kitchen::TransientFailure)

    if running the command results in failure.



43
44
45
46
47
48
49
50
51
# File 'lib/kitchen/terraform/command_executor.rb', line 43

def run(command:, options:, &block)
  ::Kitchen::Terraform::ShellOut.new(
    command: "#{client} #{command}",
    logger: logger,
    options: options,
  ).run(&block)

  self
end