def run_terraform(self, tfvar_file):
"""Return a apply terraform after template rendered."""
path = os.path.dirname(self.args.output)
tfvar_file = os.path.join(path, tfvar_file)
self.get_lambda_versions_file(tfvar_file)
affirm = ['true', 'y', 'yes']
decline = ['', 'false', 'n', 'no']
tf_cmds = {
'apply': 'terraform apply -var-file={} {}'.format(tfvar_file, path),
'plan': 'terraform plan -var-file={} {}'.format(tfvar_file, path)
}
quit_cmds = ['q', 'quit']
while True:
run_tf = input("Run terraform? [y/N] ").lower()
if run_tf in affirm + decline:
run_tf = run_tf not in decline
break
print('Try again.')
if run_tf is True:
while True:
tf_cmd = input("terraform apply or plan? [apply/plan/quit] ")
if tf_cmd in tf_cmds:
subprocess.call(tf_cmds[tf_cmd], shell=True)
break
if tf_cmd.lower() in quit_cmds:
break
print('Try again.')
return
print('command to show plan:\n\t{}'.format(tf_cmds['plan']))
print('command to apply:\n\t{}'.format(tf_cmds['apply']))
评论列表
文章目录