gpt4 book ai didi

terraform - python terraform应用自动批准不起作用

转载 作者:行者123 更新时间:2023-12-03 16:38:38 24 4
gpt4 key购买 nike

我有一个执行 terraform 计划和应用的 python 代码。

from python_terraform import *

class terraform(object):

@staticmethod
def execute(action):
print(action)
tf = Terraform(
working_dir='/Users/kheshav/PROJECTS/terraform/demo_supinfo/tf_files')
approve = {"auto-approve": True}
if action is "PLAN":
"""
return_code, stdout, stderr = tf.plan(
capture_output=True)
"""
tf.plan(no_color=IsFlagged, refresh=False, capture_output=True)
return_code, stdout, stderr = tf.plan()
print(stdout)
elif action == "APPLY":
return_code, stdout, stderr = tf.apply(
capture_output=True, auto_approve=True, **approve)
elif action == "DESTROY":
return_code, stdout, stderr = tf.destroy(
capture_output=True, auto_approve=True, **approve)
elif action == "OUTPUT":
stdout = tf.output(
capture_output=True)
return stdout

PLAN 部分工作正常,但应用部分正在等待"is",即使我已指定 {auto-approve: True} .有关信息,我正在使用 python 3.7 和 python-terraform 模块 0.10.1

应用部分挂起,如果我退出脚本,我会得到以下输出:
Traceback (most recent call last):
File "main.py", line 85, in <module>
handle_command(command, channel)
File "main.py", line 23, in handle_command
response = terraform.execute("APPLY")
File "/Users/kheshav/PROJECTS/terraform/demo_supinfo/chatbot/terraform.py", line 26, in execute
print("APPLYING")
File "/Users/kheshav/.pyenv/versions/demo_supinfo/lib/python3.7/site-packages/python_terraform/__init__.py", line 113, in apply
return self.cmd('apply', *args, **option_dict)
File "/Users/kheshav/.pyenv/versions/demo_supinfo/lib/python3.7/site-packages/python_terraform/__init__.py", line 299, in cmd
out, err = p.communicate()
File "/Users/kheshav/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py", line 939, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
File "/Users/kheshav/.pyenv/versions/3.7.3/lib/python3.7/subprocess.py", line 1681, in _communicate
ready = selector.select(timeout)
File "/Users/kheshav/.pyenv/versions/3.7.3/lib/python3.7/selectors.py", line 415, in select
fd_event_list = self._selector.poll(timeout)
KeyboardInterrupt

谢谢

最佳答案

想出了如何在没有提示输入yes的情况下使其工作。使用最新的 0.10.1 版本的 python-terraform。

tf = Terraform(working_dir='my/path')

tf.init()
tf.plan()
tf.apply(skip_plan=True)

# then later
tf.destroy()

似乎 auto_approve 变量与 skip_plan ( see here ) 相关联。

关于terraform - python terraform应用自动批准不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56868223/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com