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
Terraform >= 0.15.0

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

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

Terraform < 0.15.0

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

terraform init \
  -backend=true \
  [-backend-config=<backend_configurations[0]> ...] \
  -force-copy \
  -get=true \
  -get-plugins=true \
  -input=false \
  -lock=<lock> \
  -lock-timeout=<lock_timeout>s \
  [-no-color] \
  [-plugin-dir=<plugin_directory>] \
  [-upgrade=true] \
  -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:, connection:, 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.

  • connection (Kitchen::Terraform::Transport::Connection)

    a Terraform connection.

  • 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.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/kitchen/terraform/driver/create.rb', line 69

def initialize(config:, connection:, logger:, version_requirement:, workspace_name:)
  self.complete_config = config.to_hash.merge upgrade_during_init: true, workspace_name: workspace_name
  self.connection = connection
  self.client_version = ::Gem::Version.new "0.0.0"
  self.logger = logger
  self.workspace_name = workspace_name
  self.workspace_new = ::Kitchen::Terraform::Command::WorkspaceNew.new config: complete_config
  self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: complete_config
  self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
    config: complete_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::StandardError)

    if a command fails.



51
52
53
54
55
56
57
58
# File 'lib/kitchen/terraform/driver/create.rb', line 51

def call
  read_client_version
  verify_version.call version: client_version
  initialize_directory
  create_or_select_workspace

  self
end