lib/terragov/terraform.rb in terragov-0.2.3 vs lib/terragov/terraform.rb in terragov-0.2.4
- old
+ new
@@ -1,21 +1,20 @@
module Terragov
class Terraform
-
def package_check(package)
unless system("which #{package} >/dev/null")
abort("Must install #{package}") unless HighLine.agree("Can't find #{package}. Install using Homebrew?")
- if system("which brew >/dev/null")
+ if system('which brew >/dev/null')
system("brew install #{package}")
else
- abort("Error: cannot find brew")
+ abort('Error: cannot find brew')
end
end
end
- def execute(command, vars, backend, directory, dryrun=false, verbose=false)
- packages = [ 'terraform', 'sops' ]
+ def execute(command, vars, backend, directory, dryrun = false, verbose = false)
+ packages = %w[terraform sops]
packages.each do |pkg|
package_check(pkg)
end
@@ -27,25 +26,23 @@
Dir.chdir directory
init(backend, dryrun, verbose)
full_command = "bash -c 'terraform #{command} #{vars}'"
- if dryrun
- puts full_command
- else
- puts "#{command} command: #{full_command}" if verbose
- abort("There was an issue running the command") unless system(full_command)
- end
+ run(full_command, dryrun, verbose)
end
- def init(backend_file, dryrun=false, verbose=false)
+ def init(backend_file, dryrun = false, verbose = false)
init_cmd = "terraform init -backend-config #{backend_file}"
+ run(init_cmd, dryrun, verbose)
+ end
+
+ def run(command, dryrun = false, verbose = false)
if dryrun
- puts init_cmd
+ puts command
else
- puts "init command: #{init_cmd}" if verbose
- abort("Issue running: terraform init -backend-config #{backend_file}") unless system(init_cmd)
+ puts command if verbose
+ abort("There was an issue running the command: #{command}") unless system(full_command)
end
end
-
end
end