lib/terragov/cli.rb in terragov-0.3.1.1 vs lib/terragov/cli.rb in terragov-0.3.2
- old
+ new
@@ -235,11 +235,11 @@
cmd = "#{cmd} #{opt}" if opt
Terragov::Terraform.new.execute(cmd, varfiles, backend, project_dir, do_dryrun, be_verbose)
end
- def run_deployment(file, group, command)
+ def run_deployment(file, group, command, force)
abort("Must set deployment file: --file") unless file
abort("Must set command to run: --command") unless command
abort("Cannot find deployment file: #{file}") unless File.exist?(file)
deployment_file = YAML.load_file(File.expand_path(file))
@@ -248,15 +248,23 @@
if deployment_config.nil?
abort("Deployment configuration must be an array of projects to run")
end
if command == 'plan' || command == 'apply'
+ if force && command == 'apply'
+ command = "#{command} -auto-approve"
+ end
+
deployment_config.each do |proj|
$project = proj
run_terraform_cmd(command, nil, true)
end
elsif command == 'destroy'
+ if force
+ command = "#{command} -force"
+ end
+
deployment_config.reverse.each do |proj|
$project = proj
run_terraform_cmd(command, nil, true)
end
else
@@ -266,20 +274,25 @@
def run
command :plan do |c|
c.syntax = 'terragov plan'
c.description = 'Runs a plan of your code'
- c.action do |_args, _options|
+ c.action do |_args, options|
run_terraform_cmd(c.name)
end
end
command :apply do |c|
c.syntax = 'terragov apply'
c.description = 'Apply your code'
- c.action do |_args, _options|
- run_terraform_cmd(c.name)
+ c.option '--force', 'Force apply'
+ c.action do |_args, options|
+ if options.force
+ run_terraform_cmd("#{c.name} -auto-approve")
+ else
+ run_terraform_cmd(c.name)
+ end
end
end
command :destroy do |c|
c.syntax = 'terragov destroy'
@@ -298,14 +311,15 @@
c.syntax = 'terragov deploy -f <deployment file>'
c.description = 'Deploy a group of projects as specified in a deployment configuration'
c.option '-f', '--file STRING', 'Specify deployment file'
c.option '-g', '--group STRING', 'Specify group that you wish to deploy'
c.option '-c', '--command STRING', 'What command to run: apply, plan or destroy.'
+ c.option '--force', 'Force apply or destroy'
c.action do |_args, options|
group = options.group.nil? ? 'default' : options.group
- run_deployment(options.file, group, options.command)
+ run_deployment(options.file, group, options.command, options.force)
end
end
command :clean do |c|
c.syntax = 'terragov clean'