class Kitchen::Driver::Terraform

The driver is the bridge between Test Kitchen and Terraform. It manages the {www.terraform.io/docs/state/index.html state} of the Terraform root module by shelling out and running Terraform commands.

Commands

The following command-line commands are provided by the driver.

kitchen create

{include:Kitchen::Terraform::Driver::Create}

kitchen destroy

{include:Kitchen::Terraform::Driver::Destroy}

Configuration Attributes

The configuration attributes of the driver control the behaviour of the Terraform commands that are run. Within the {kitchen.ci/docs/getting-started/kitchen-yml Test Kitchen configuration file}, these attributes must be declared in the driver mapping along with the plugin name.

driver:
  name: terraform
  a_configuration_attribute: some value

backend_configurations

{include:Kitchen::Terraform::ConfigAttribute::BackendConfigurations}

client

{include:Kitchen::Terraform::ConfigAttribute::Client}

color

{include:Kitchen::Terraform::ConfigAttribute::Color}

command_timeout

{include:Kitchen::Terraform::ConfigAttribute::CommandTimeout}

lock

{include:Kitchen::Terraform::ConfigAttribute::Lock}

lock_timeout

{include:Kitchen::Terraform::ConfigAttribute::LockTimeout}

parallelism

{include:Kitchen::Terraform::ConfigAttribute::Parallelism}

plugin_directory

{include:Kitchen::Terraform::ConfigAttribute::PluginDirectory}

root_module_directory

{include:Kitchen::Terraform::ConfigAttribute::RootModuleDirectory}

variable_files

{include:Kitchen::Terraform::ConfigAttribute::VariableFiles}

variables

{include:Kitchen::Terraform::ConfigAttribute::Variables}

verify_version

{include:Kitchen::Terraform::ConfigAttribute::VerifyVersion}

Ruby Interface

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

@example Describe the create command

kitchen help create

@example Create a Test Kitchen instance

kitchen create default-ubuntu

@example Describe the destroy command

kitchen help destroy

@example Destroy a Test Kitchen instance

kitchen destroy default-ubuntu

@version 2

Attributes

action_failed[RW]
create_strategy[RW]
destroy_strategy[RW]

Public Class Methods

new(config = {}) click to toggle source

initialize prepares a new instance of the class.

@param config [Hash] the driver configuration. @return [Kitchen::Driver::Terraform]

Calls superclass method
# File lib/kitchen/driver/terraform.rb, line 222
def initialize(config = {})
  super config
  self.action_failed = ::Kitchen::Terraform::Raise::ActionFailed.new logger: logger
end

Public Instance Methods

create(_state) click to toggle source

Creates a Test Kitchen instance by initializing the working directory and creating a test workspace.

@param _state [Hash] the mutable instance and driver state. @raise [Kitchen::ActionFailed] if the result of the action is a failure. @return [void]

# File lib/kitchen/driver/terraform.rb, line 176
def create(_state)
  create_strategy.call
rescue => error
  action_failed.call message: error.message
end
destroy(_state) click to toggle source

Destroys a Test Kitchen instance by initializing the working directory, selecting the test workspace, deleting the state, selecting the default workspace, and deleting the test workspace.

@param _state [Hash] the mutable instance and driver state. @raise [Kitchen::ActionFailed] if the result of the action is a failure. @return [void]

# File lib/kitchen/driver/terraform.rb, line 188
def destroy(_state)
  destroy_strategy.call
rescue => error
  action_failed.call message: error.message
end
finalize_config!(instance) click to toggle source

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

@param instance [Kitchen::Instance] an associated instance. @raise [Kitchen::ClientError] if the instance is nil. @return [self] @see Kitchen::Configurable#finalize_config!

# File lib/kitchen/driver/terraform.rb, line 200
def finalize_config!(instance)
  super instance
  self.create_strategy = ::Kitchen::Terraform::Driver::Create.new(
    config: config,
    logger: logger,
    version_requirement: version_requirement,
    workspace_name: workspace_name,
  )
  self.destroy_strategy = ::Kitchen::Terraform::Driver::Destroy.new(
    config: config,
    logger: logger,
    version_requirement: version_requirement,
    workspace_name: workspace_name,
  )

  self
end