Class: Kitchen::Transport::Terraform

Overview

The Terraform transport is responsible for the integration with the Terraform CLI.

Configuration Attributes

The configuration attributes of the transport control the behaviour of the Terraform commands that are run. Within the Test Kitchen configuration file, these attributes must be declared in the transport mapping along with the plugin name.

transport:
  name: terraform
  a_configuration_attribute: some value

client

This attribute contains the pathname of the Terraform client to be used by Kitchen-Terraform.

If the value is not an absolute pathname or a relative pathname then Kitchen-Terraform will attempt to find the value in the directories of the ) PATH.

The pathname of any executable file which implements the interfaces of the following Terraform client commands may be specified: apply; destroy; get; init; validate; workspace.

Type

Scalar

Required

False

Default

terraform

Example

client: /usr/local/bin/terraform

Example

client: ./bin/terraform

Example

client: terraform

command_timeout

This attribute controls the number of seconds that the plugin will wait for Terraform commands to finish running.

Type

Integer

Required

False

Default

600

Example

command_timeout: 1200

root_module_directory

This attribute contains the path to the directory which contains the root Terraform module to be tested.

Type

Scalar

Required

False

Default

The working directory of the Test Kitchen process.

Example

root_module_directory: /path/to/terraform/root/module/directory

Ruby Interface

This class implements the interface of Kitchen::Configurable which requires the following Reek suppressions: :reek:MissingSafeMethod { exclude: [ finalize_config! ] }

Version:

  • 2

Instance Method Summary collapse

Methods included from Kitchen::Terraform::Configurable

included

Methods included from Kitchen::Terraform::ConfigAttribute::RootModuleDirectory

#config_root_module_directory_default_value, included, to_sym

Methods included from Kitchen::Terraform::ConfigAttributeCacher

#define_cache, extended

Methods included from Kitchen::Terraform::ConfigAttribute::Client

#config_client_default_value, #doctor_config_client, included, to_sym

Constructor Details

#initialize(config = {}) ⇒ Kitchen::Transport::Terraform

#initialize prepares a new instance of the class.

Parameters:

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

    the transport configuration.



116
117
118
# File 'lib/kitchen/transport/terraform.rb', line 116

def initialize(config = {})
  super config
end

Instance Method Details

#connection(state, &block) ⇒ Kitchen::Terraform::Transport::Connection

#connection creates a new Connection, configured by a merging of configuration and state data.

Parameters:

  • state (Hash)

    mutable instance state.

Returns:

Raises:

  • (Kitchen::Transport::TransportFailed)

    if a connection could not be returned.



78
79
80
81
82
# File 'lib/kitchen/transport/terraform.rb', line 78

def connection(state, &block)
  options = connection_options config.to_hash.merge state

  ::Kitchen::Terraform::Transport::Connection.new options, &block
end

#doctor(_state) ⇒ Boolean

doctor checks the system and configuration for common errors.

Parameters:

  • _state (Hash)

    the mutable Kitchen instance state.

Returns:

  • (Boolean)

    true if any errors are found; false if no errors are found.



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/kitchen/transport/terraform.rb', line 88

def doctor(_state)
  errors = false

  methods.each do |method|
    next if !method.match? /doctor_config_.*/

    error = send method
    errors = errors || error
  end

  errors
end

#finalize_config!(instance) ⇒ self

#finalize_config! invokes the super implementation and then initializes the strategies.

Parameters:

  • instance (Kitchen::Instance)

    an associated instance.

Returns:

  • (self)

Raises:

  • (Kitchen::ClientError)

    if the instance is nil.



106
107
108
109
110
# File 'lib/kitchen/transport/terraform.rb', line 106

def finalize_config!(instance)
  super instance

  self
end