Class: Kitchen::Terraform::Transport::Connection

Inherits:
Kitchen::Transport::Exec::Connection
  • Object
show all
Defined in:
lib/kitchen/terraform/transport/connection.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

Instance Method Details

#execute(command) ⇒ String

#execute executes a Terraform CLI command on the local host.

Parameters:

  • command (String)

    the Terraform command to be executed locally.

Returns:

  • (String)

    the standard output of the command.

Raises:

  • (Kitchen::Transport::TransportFailed)

    if the command does not exit successfully.



33
34
35
36
37
# File 'lib/kitchen/terraform/transport/connection.rb', line 33

def execute(command)
  super "#{client} #{command}"

  stdout
end

#run_command(command, options = {}) ⇒ String

#run_command executes a command in a subshell on the local running system.

Parameters:

  • command (String)

    the command to be executed locally.

  • options (Hash) (defaults to: {})

    additional configuration of the command.

Returns:

  • (String)

    the standard output of the command.

Raises:

  • (Kitchen::ShellOut::ShellCommandFailed)

    if the command fails.

  • (Kitchen::StandardError)

    for all other unexpected exceptions.



46
47
48
49
50
51
52
# File 'lib/kitchen/terraform/transport/connection.rb', line 46

def run_command(command, options = {})
  self.stdout = super command, options.merge(
    cwd: root_module_directory,
    environment: environment.merge("LC_ALL" => nil, "TF_IN_AUTOMATION" => "true"),
    timeout: command_timeout,
  )
end