Class: Ruby::Terraform::Commands::DestroyCommand

Inherits:
Object
  • Object
show all
Includes:
ExecutionSupport
Defined in:
lib/ruby/terraform/commands/destroy_command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ExecutionSupport

#execute, #tf_binary

Constructor Details

#initialize(opts = {}) ⇒ DestroyCommand

Returns a new instance of DestroyCommand.



12
13
14
15
16
17
18
19
20
21
# File 'lib/ruby/terraform/commands/destroy_command.rb', line 12

def initialize(opts = {})
  @dir = opts[:dir]
  @state = opts[:state]
  @vars = opts[:vars]
  @auto_approve = if opts[:auto_approve].nil?
                    true
                  else
                    opts[:auto_approve]
                  end
end

Instance Attribute Details

#auto_approveObject

Returns the value of attribute auto_approve.



10
11
12
# File 'lib/ruby/terraform/commands/destroy_command.rb', line 10

def auto_approve
  @auto_approve
end

#dirObject

Returns the value of attribute dir.



7
8
9
# File 'lib/ruby/terraform/commands/destroy_command.rb', line 7

def dir
  @dir
end

#stateObject

Returns the value of attribute state.



8
9
10
# File 'lib/ruby/terraform/commands/destroy_command.rb', line 8

def state
  @state
end

#varsObject

Returns the value of attribute vars.



9
10
11
# File 'lib/ruby/terraform/commands/destroy_command.rb', line 9

def vars
  @vars
end

Instance Method Details

#commandObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/ruby/terraform/commands/destroy_command.rb', line 23

def command
  cmd = %W[#{tf_binary} destroy]

  cmd += ['-state', state] if state
  cmd += ['-auto-approve'] if auto_approve

  if vars
    vars.each do |key, value|
      var_value = value.is_a?(String) ? value : JSON.generate(value)
      cmd += ['-var', "#{key}=#{var_value}"]
    end
  end

  cmd += [dir] if dir
  cmd
end