Class: Ruby::Terraform::Commands::PlanCommand

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ExecutionSupport

#execute, #tf_binary

Constructor Details

#initialize(opts = {}) ⇒ PlanCommand

Returns a new instance of PlanCommand.



11
12
13
14
15
# File 'lib/ruby/terraform/commands/plan_command.rb', line 11

def initialize(opts = {})
  @dir = opts[:dir]
  @state = opts[:state]
  @vars = opts[:vars]
end

Instance Attribute Details

#dirObject

Returns the value of attribute dir.



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

def dir
  @dir
end

#stateObject

Returns the value of attribute state.



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

def state
  @state
end

#varsObject

Returns the value of attribute vars.



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

def vars
  @vars
end

Instance Method Details

#commandObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby/terraform/commands/plan_command.rb', line 17

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

  cmd += ['-state', state] if state

  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