class Kitchen::Terraform::Command::Apply

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>

Attributes

color[RW]
lock[RW]
lock_timeout[RW]
parallelism[RW]
var[RW]
var_file[RW]

Public Class Methods

new(config:) click to toggle source

initialize prepares a new instance of the class.

@param config [Hash] the configuration of the driver. @option config [Boolean] :color a toggle of colored output from the Terraform client. @option config [Boolean] :lock a toggle of locking for the Terraform state file. @option config [Integer] :lock_timeout the number of seconds that the Terraform client will wait for a lock

on the state to be obtained during operations.

@option config [Integer] :parallelism the number of concurrent operations to use while Terraform walks the

resource graph.

@option config [Array<String>] :variable_files a list of pathnames of Terraform variable files to evaluate. @option config [Hash{String=>String}] :variables a mapping of Terraform variables to evaluate. @return [Kitchen::Terraform::Command::Apply]

# 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

Public Instance Methods

to_s() click to toggle source

@return [String] the command with flags.

# 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