MCPcopy Create free account
hub / github.com/beelit94/python-terraform / Terraform

Class Terraform

python_terraform/terraform.py:39–460  ·  view source on GitHub ↗

Wrapper of terraform command line tool. https://www.terraform.io/

Source from the content-addressed store, hash-verified

37
38
39class Terraform:
40 """Wrapper of terraform command line tool.
41
42 https://www.terraform.io/
43 """
44
45 def __init__(
46 self,
47 working_dir: Optional[str] = None,
48 targets: Optional[Sequence[str]] = None,
49 state: Optional[str] = None,
50 variables: Optional[Dict[str, str]] = None,
51 parallelism: Optional[str] = None,
52 var_file: Optional[str] = None,
53 terraform_bin_path: Optional[str] = None,
54 is_env_vars_included: bool = True,
55 ):
56 """
57 :param working_dir: the folder of the working folder, if not given,
58 will be current working folder
59 :param targets: list of target
60 as default value of apply/destroy/plan command
61 :param state: path of state file relative to working folder,
62 as a default value of apply/destroy/plan command
63 :param variables: default variables for apply/destroy/plan command,
64 will be override by variable passing by apply/destroy/plan method
65 :param parallelism: default parallelism value for apply/destroy command
66 :param var_file: passed as value of -var-file option,
67 could be string or list, list stands for multiple -var-file option
68 :param terraform_bin_path: binary path of terraform
69 :type is_env_vars_included: bool
70 :param is_env_vars_included: included env variables when calling terraform cmd
71 """
72 self.is_env_vars_included = is_env_vars_included
73 self.working_dir = working_dir
74 self.state = state
75 self.targets = [] if targets is None else targets
76 self.variables = dict() if variables is None else variables
77 self.parallelism = parallelism
78 self.terraform_bin_path = (
79 terraform_bin_path if terraform_bin_path else "terraform"
80 )
81 self.var_file = var_file
82 self.temp_var_files = VariableFiles()
83
84 # store the tfstate data
85 self.tfstate = None
86 self.read_state_file(self.state)
87
88 def __getattr__(self, item: str) -> Callable:
89 def wrapper(*args, **kwargs):
90 cmd_name = str(item)
91 if cmd_name.endswith("_cmd"):
92 cmd_name = cmd_name[:-4]
93 logger.debug("called with %r and %r", args, kwargs)
94 return self.cmd(cmd_name, *args, **kwargs)
95
96 return wrapper

Callers 15

wrapperFunction · 0.90
test_cmdMethod · 0.90
test_applyMethod · 0.90
test_optionsMethod · 0.90
test_state_dataMethod · 0.90
test_state_defaultMethod · 0.90
test_override_defaultMethod · 0.90
test_outputMethod · 0.90

Calls

no outgoing calls

Tested by 15

wrapperFunction · 0.72
test_cmdMethod · 0.72
test_applyMethod · 0.72
test_optionsMethod · 0.72
test_state_dataMethod · 0.72
test_state_defaultMethod · 0.72
test_override_defaultMethod · 0.72
test_outputMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…