Skip to content

Instantly share code, notes, and snippets.

@maliciousgroup
Created April 8, 2021 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maliciousgroup/559c0d5ca12f943a3d0afc978c66ffa7 to your computer and use it in GitHub Desktop.
Save maliciousgroup/559c0d5ca12f943a3d0afc978c66ffa7 to your computer and use it in GitHub Desktop.
from python_terraform import *
def create_resources(template: str, variables: dict) -> str:
count = 0
while count < 10:
tf = Terraform()
tf.init(template)
_, stdout, stderr = tf.apply(
template,
capture_output=True,
no_color=IsFlagged,
skip_plan=True,
state=f"{template.split('/')[-1]}.tfstate",
var=variables)
if stdout:
return stdout
elif stderr:
count += 1
continue
return stderr
def destroy_resources(template: str, variables: dict) -> str:
count = 0
while count < 10:
tf = Terraform()
_, stdout, stderr = tf.destroy(
template,
capture_output=False,
no_color=IsFlagged,
state=f"{template.split('/')[-1]}.tfstate",
var=variables)
if stdout:
return stdout
elif stderr:
count += 1
continue
return stderr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment