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

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

terraform validate \
  [-no-color] \
  <directory>

Terraform < 0.15.0

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.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/kitchen/terraform/provisioner/converge.rb', line 85

def initialize(config:, logger:, version_requirement:, workspace_name:)
  self.complete_config = config.to_hash.merge workspace_name: workspace_name
  client = complete_config.fetch :client
  self.client_version = ::Gem::Version.new "0.0.0"
  self.command_executor = ::Kitchen::Terraform::CommandExecutor.new(
    client: client,
    logger: logger,
  )
  self.logger = logger
  self.options = {
    cwd: complete_config.fetch(:root_module_directory),
    timeout: complete_config.fetch(:command_timeout),
  }
  self.workspace_name = workspace_name
  initialize_commands
  initialize_outputs_handlers client: client, logger: logger
  self.variables = complete_config.fetch :variables
  self.variables_manager = ::Kitchen::Terraform::VariablesManager.new
  self.verify_version = ::Kitchen::Terraform::VerifyVersion.new(
    config: complete_config,
    logger: logger,
    version_requirement: version_requirement,
  )
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.



69
70
71
72
73
74
75
76
# File 'lib/kitchen/terraform/provisioner/converge.rb', line 69

def call(state:)
  read_client_version
  verify_version.call version: client_version
  execute_workflow
  save_variables_and_outputs state: state

  self
end