Class: Cloudshaper::Command
- Inherits:
-
Object
- Object
- Cloudshaper::Command
- Defined in:
- lib/cloudshaper/command.rb
Overview
Wraps terraform command execution
Direct Known Subclasses
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
Instance Method Summary collapse
- #env ⇒ Object
- #execute ⇒ Object
-
#initialize(stack, command) ⇒ Command
constructor
A new instance of Command.
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 = (command) prepare end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
4 5 6 |
# File 'lib/cloudshaper/command.rb', line 4 def command @command end |
Instance Method Details
#env ⇒ Object
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 |
#execute ⇒ Object
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 |