lib/terragov/terraform.rb in terragov-0.2.5.2 vs lib/terragov/terraform.rb in terragov-0.3.0
- old
+ new
@@ -24,10 +24,14 @@
end
Dir.chdir directory
init(backend, dryrun, verbose)
+ if command == 'plan'
+ command = 'plan -detailed-exitcode'
+ end
+
full_command = "bash -c 'terraform #{command} #{vars}'"
run(full_command, dryrun, verbose)
end
@@ -39,10 +43,18 @@
def run(command, dryrun = false, verbose = false)
if dryrun
puts command
else
puts command if verbose
- abort("There was an issue running the command: #{command}") unless system(command)
+ system(command)
+
+ # Catch the output of "-detailed-exitcode"
+ if $?.exitstatus == 2
+ puts "Command completed successfully, but with updates available to apply"
+ exit 2
+ elsif $?.exitstatus != (0 or 2)
+ abort("There was an issue running command: #{command}")
+ end
end
end
end
end