Class: Kitchen::Terraform::Command::Apply

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

Overview

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>

Instance Method Summary collapse

Constructor Details

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

#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/apply.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/apply.rb', line 61

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