update
This commit is contained in:
parent
a0975baeb1
commit
4ebdc607dc
4 changed files with 26 additions and 3 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
*.pyc
|
|
@ -9,8 +9,9 @@ log = logging.getLogger(__name__)
|
|||
class Terraform:
|
||||
def __init__(self, targets=None, state='terraform.tfstate', variables=None):
|
||||
self.targets = [] if targets is None else targets
|
||||
self.state = state
|
||||
self.variables = dict() if variables is None else variables
|
||||
|
||||
self.state = state
|
||||
self.state_data = None
|
||||
self.parallelism = 50
|
||||
|
||||
|
@ -33,11 +34,13 @@ class Terraform:
|
|||
|
||||
def _run_cmd(self, cmd):
|
||||
log.debug('command: ' + cmd)
|
||||
|
||||
p = subprocess.Popen(
|
||||
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
||||
out, err = p.communicate()
|
||||
ret_code = p.returncode
|
||||
log.debug('output: ' + out)
|
||||
|
||||
if ret_code == 0:
|
||||
log.debug('error: ' + err)
|
||||
self.read_state()
|
||||
|
@ -50,8 +53,7 @@ class Terraform:
|
|||
parameters = []
|
||||
parameters += self._generate_targets(targets)
|
||||
parameters += self._generate_var_string(variables)
|
||||
# hard code 19 for splunk aws limit on us-west-2 region,
|
||||
# todo move parallelism?
|
||||
|
||||
parameters = \
|
||||
['terraform', 'destroy', '-force', '-state=%s' % self.state] + \
|
||||
parameters
|
||||
|
|
0
test/__init__.py
Normal file
0
test/__init__.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from terraform import Terraform
|
||||
|
||||
|
||||
class TestTerraform:
|
||||
def test_apply(self):
|
||||
tf = Terraform()
|
||||
|
||||
tf.apply()
|
||||
|
||||
def test_refresh(self):
|
||||
tf = Terraform()
|
||||
|
||||
tf.refresh()
|
||||
|
||||
def test_destroy(self):
|
||||
tf = Terraform()
|
||||
|
||||
tf.destroy()
|
||||
|
||||
|
Loading…
Reference in a new issue