Class: Kitchen::Terraform::Command::Destroy

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

Overview

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>

Instance Method Summary collapse

Constructor Details

#initialize(config:) ⇒ Kitchen::Terraform::Command::Destroy

#initialize prepares a new instance of the class.

Parameters:

  • config (Hash)

    the configuration of the driver.

Options Hash (config:):

  • :color (Boolean)

    a toggle of colored output from the Terraform client.

  • :lock (Boolean)

    a toggle of locking for the Terraform state file.

  • :lock_timeout (Integer)

    the number of seconds that the Terraform client will wait for a lock on the state to be obtained during operations.

  • :parallelism (Integer)

    the number of concurrent operations to use while Terraform walks the resource graph.

  • :variable_files (Array<String>)

    a list of pathnames of Terraform variable files to evaluate.

  • :variables (Hash{String=>String})

    a mapping of Terraform variables to evaluate.



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

def initialize(config:)
  self.color = ::Kitchen::Terraform::CommandFlag::Color.new enabled: config.fetch(:color)
  self.lock = config.fetch :lock
  self.lock_timeout = ::Kitchen::Terraform::CommandFlag::LockTimeout.new duration: config.fetch(:lock_timeout)
  self.parallelism = config.fetch :parallelism
  self.var_file = ::Kitchen::Terraform::CommandFlag::VarFile.new pathnames: config.fetch(:variable_files)
  self.var = ::Kitchen::Terraform::CommandFlag::Var.new arguments: config.fetch(:variables)
end

Instance Method Details

#to_sString

Returns the command with flags.

Returns:

  • (String)

    the command with flags.



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/kitchen/terraform/command/destroy.rb', line 61

def to_s
  "destroy " \
  "-auto-approve " \
  "-lock=#{lock} " \
  "#{lock_timeout} " \
  "-input=false " \
  "#{color} " \
  "-parallelism=#{parallelism} " \
  "-refresh=true " \
  "#{var} " \
  "#{var_file}"
end