Class: Kitchen::Terraform::Driver::Create

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

Overview

A Test Kitchen instance is created through the following steps.

Initializing the Terraform Working Directory

The working directory is initialized by running a command like the following example:

terraform init \
  -input=false \
  -lock=<lock> \
  -lock-timeout=<lock_timeout>s \
  [-no-color] \
  [-upgrade] \
  -force-copy \
  -backend=true \
  [-backend-config=<backend_configurations[0]> ...] \
  -get=true \
  -get-plugins=true \
  [-plugin-dir=<plugin_directory>] \
  -verify-plugins=true \
  <root_module_directory>

Creating or Selecting the Test Terraform Workspace

The workspace is created by running a command like the following example:

terraform workspace new <name>

The workspace is selected by running a command like the following example:

terraform workspace select <name>

Instance Method Summary collapse

Constructor Details

#initialize(config:, logger:, version_requirement:, workspace_name:) ⇒ Kitchen::Terraform::Driver::Create

#initialize prepares a new instance of the class.

Parameters:

  • config (Hash)

    the configuration of the driver.

  • logger (Kitchen::Logger)

    a logger for logging messages.

  • version_requirement (Gem::VersionRequirement)

    the required version of the Terraform client.

  • workspace_name (String)

    the name of the Terraform workspace to select or to create.

Options Hash (config:):

  • :client (String)

    the pathname of the Terraform client.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/kitchen/terraform/driver/create.rb', line 60

def initialize(config:, logger:, version_requirement:, workspace_name:)
  hash_config = config.to_hash.merge upgrade_during_init: true, workspace_name: workspace_name
  self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
    client: config.fetch(:client),
    logger: logger,
  )
  self.init = ::Kitchen::Terraform::Command::Init.new config: hash_config
  self.logger = logger
  self.options = { cwd: config.fetch(:root_module_directory), timeout: config.fetch(:command_timeout) }
  self.workspace_name = workspace_name
  self.workspace_new = ::Kitchen::Terraform::Command::WorkspaceNew.new config: hash_config
  self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: hash_config
  self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
    command_executor: command_executor,
    config: config,
    logger: logger,
    version_requirement: version_requirement,
  )
  self.version = ::Kitchen::Terraform::Command::Version.new
end

Instance Method Details

#callself

#call executes the action.

Returns:

  • (self)

Raises:

  • (Kitchen::TransientFailure)

    if a command fails.



44
45
46
47
48
49
50
# File 'lib/kitchen/terraform/driver/create.rb', line 44

def call
  verify_version.call command: version, options: options
  initialize_directory
  create_or_select_workspace

  self
end