model.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:downtoearth 作者: cleardataeng 项目源码 文件源码
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']))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号