Class: Kitchen::Terraform::Driver::Destroy

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

Overview

A Test Kitchen instance is destroyed 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>

Selecting or Creating the Test Terraform Workspace

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

terraform workspace select <name>

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

terraform workspace new <name>

Destroying the Terraform State

The state is destroyed by running a command like the following example:

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

Selecting the Default Terraform Workspace

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

terraform workspace select <name>

Deleting the Test Terraform Workspace

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

terraform workspace delete <name>

Instance Method Summary collapse

Constructor Details

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

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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/kitchen/terraform/driver/destroy.rb', line 81

def initialize(config:, connection:, logger:, version_requirement:, workspace_name:)
  self.complete_config = config.to_hash.merge upgrade_during_init: false, 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.destroy = ::Kitchen::Terraform::Command::Destroy.new config: complete_config
  self.workspace_delete_test = ::Kitchen::Terraform::Command::WorkspaceDelete.new config: complete_config
  self.workspace_new_test = ::Kitchen::Terraform::Command::WorkspaceNew.new config: complete_config
  self.workspace_select_test = ::Kitchen::Terraform::Command::WorkspaceSelect.new config: complete_config
  self.workspace_select_default = ::Kitchen::Terraform::Command::WorkspaceSelect.new(
    config: complete_config.merge(workspace_name: "default"),
  )
  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.



65
66
67
68
69
70
71
# File 'lib/kitchen/terraform/driver/destroy.rb', line 65

def call
  read_client_version
  verify_version.call version: client_version
  execute_workflow

  self
end