From 4843208ed1dcb4c3fa1428930f23efc7ff0fe392 Mon Sep 17 00:00:00 2001 From: costimuraru Date: Thu, 29 Aug 2019 19:33:30 +0300 Subject: [PATCH] Add auto-approve to terraform destroy --- src/ops/terraform/terraform_cmd_generator.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ops/terraform/terraform_cmd_generator.py b/src/ops/terraform/terraform_cmd_generator.py index 1c361f04..08179761 100644 --- a/src/ops/terraform/terraform_cmd_generator.py +++ b/src/ops/terraform/terraform_cmd_generator.py @@ -119,6 +119,8 @@ def generate(self, args): else: variables_file = ' ' + auto_approve = '-auto-approve' if args.auto_approve else '' + if args.subcommand == 'plan': generate_module_templates = True terraform_refresh_command = '' @@ -157,10 +159,6 @@ def generate(self, args): # todo maybe this deserves a better implementation later generate_module_templates = True - auto_approve = '' - if args.auto_approve: - auto_approve = '-auto-approve' - self.inventory_generator.clear_cache() if args.skip_plan: # Run Terraform apply without running a plan first @@ -198,14 +196,15 @@ def generate(self, args): "{terraform_init_command}" \ "terraform plan -destroy " \ "-refresh=true {vars} {variables_file} {state_argument} && " \ - "terraform destroy {vars} {variables_file} {state_argument} -refresh=true".format( + "terraform destroy {vars} {variables_file} {state_argument} -refresh=true {auto_approve}".format( root_dir=self.root_dir, terraform_path=terraform_path, variables_file=variables_file, vars=vars, state_argument=state_argument, terraform_init_command=terraform_init_command, - remove_local_cache=remove_local_cache + remove_local_cache=remove_local_cache, + auto_approve=auto_approve ) elif args.subcommand == 'output': cmd = "cd {root_dir}/{terraform_path} && " \