Module: Kitchen::Pulumi::ShellOut

Defined in:
lib/kitchen/pulumi/shell_out.rb

Overview

Module orchestrating calls to the Pulumi CLI

Class Method Summary collapse

Class Method Details

.run(cmd:, duration: 7200, logger:, &block) ⇒ Object

Shells out to the Pulumi CLI


12
13
14
15
16
17
18
19
20
21
# File 'lib/kitchen/pulumi/shell_out.rb', line 12

def self.run(cmd:, duration: 7200, logger:, &block)
  cmds = Array(cmd)
  block ||= ->(stdout) { stdout }
  shell_out(commands: cmds, duration: duration, logger: logger, &block)
rescue ::Errno::EACCES, ::Errno::ENOENT,
       ::Mixlib::ShellOut::InvalidCommandOption,
       ::Mixlib::ShellOut::CommandTimeout,
       ::Mixlib::ShellOut::ShellCommandFailed => e
  raise(::Kitchen::Pulumi::Error, "Error: #{e.message}")
end

.shell_out(commands:, duration: 7200, logger:) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kitchen/pulumi/shell_out.rb', line 23

def self.shell_out(commands:, duration: 7200, logger:)
  commands.each do |command|
    shell_out = ::Mixlib::ShellOut.new(
      "pulumi #{command}",
      live_stream: logger,
      timeout: duration,
    )

    logger.warn("Running #{shell_out.command}")

    shell_out.run_command
    shell_out.error!
    yield(stdout: shell_out.stdout)
  end
end