Class: Kitchen::Terraform::Provisioner::Converge

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/terraform/provisioner/converge.rb

Overview

A Test Kitchen instance is converged through the following steps.

Selecting the Test Terraform Workspace

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

terraform workspace select <name>

Updating the Terraform Dependency Modules

The dependency modules are updated by running a command like the following example:

terraform get -update <directory>

Validating the Terraform Root Module

The root module is validated by running a command like the following example:

terraform validate \
  [-no-color] \
  [-var=<variables.first>...] \
  [-var-file=<variable_files.first>...] \
  <directory>

Applying the Terraform State Changes

The state changes are applied by running a command like the following example:

terraform apply\
  -lock=<lock> \
  -lock-timeout=<lock_timeout>s \
  -input=false \
  -auto-approve=true \
  [-no-color] \
  -parallelism=<parallelism> \
  -refresh=true \
  [-var=<variables.first>...] \
  [-var-file=<variable_files.first>...] \
  <directory>

Retrieving the Terraform Output

The outputs are retrieved by running a command like the following example:

terraform output -json

Instance Method Summary collapse

Constructor Details

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

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



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/kitchen/terraform/provisioner/converge.rb', line 77

def initialize(config:, logger:, version_requirement:, workspace_name:)
  client = config.fetch :client
  hash_config = config.to_hash.merge workspace_name: workspace_name
  self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
    client: client,
    logger: logger,
  )
  self.logger = logger
  self.options = { cwd: config.fetch(:root_module_directory), timeout: config.fetch(:command_timeout) }
  self.workspace_name = workspace_name
  self.apply = ::Kitchen::Terraform::Command::Apply.new config: config
  self.get = ::Kitchen::Terraform::Command::Get.new
  self.output = ::Kitchen::Terraform::Command::Output.new
  initialize_outputs_handlers client: client, logger: logger
  self.validate = ::Kitchen::Terraform::Command::Validate.new config: config
  self.workspace_select = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: hash_config
  self.variables = config.fetch :variables
  self.variables_manager = ::Kitchen::Terraform::VariablesManager.new
  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

#call(state:) ⇒ self

#call executes the action.

Parameters:

  • state (Hash)

    the Kitchen instance state.

Returns:

  • (self)

Raises:

  • (Kitchen::TransientFailure)

    if a command fails.



62
63
64
65
66
67
68
# File 'lib/kitchen/terraform/provisioner/converge.rb', line 62

def call(state:)
  verify_version.call command: version, options: options
  execute_workflow
  save_variables_and_outputs state: state

  self
end