Class: Cloudshaper::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudshaper/command.rb

Overview

Wraps terraform command execution

Direct Known Subclasses

Remote

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stack, command) ⇒ Command

Returns a new instance of Command.



6
7
8
9
10
# File 'lib/cloudshaper/command.rb', line 6

def initialize(stack, command)
  @stack = stack
  @command = options_for(command)
  prepare
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



4
5
6
# File 'lib/cloudshaper/command.rb', line 4

def command
  @command
end

Instance Method Details

#envObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/cloudshaper/command.rb', line 12

def env
  vars = {}
  @stack.module.each_variable { |k, v| vars["TF_VAR_#{k}"] = v[:default] }
  @stack.module.secrets.each do |_provider, secrets|
    secrets.each do |k, v|
      vars[k.to_s] = v
    end
  end
  vars
end

#executeObject



23
24
25
26
# File 'lib/cloudshaper/command.rb', line 23

def execute
  Process.waitpid(spawn(env, @command, chdir: @stack.stack_dir))
  fail 'Command failed' unless $CHILD_STATUS.to_i == 0
end