adding readme and test
This commit is contained in:
parent
38222a42f5
commit
733b8006c5
3 changed files with 10 additions and 5 deletions
|
@ -16,11 +16,12 @@ python-terraform is a python module provide a wrapper of `terraform` command lin
|
||||||
t = Terraform()
|
t = Terraform()
|
||||||
return_code, stdout, stderr = t.<cmd_name>(*arguments, **options)
|
return_code, stdout, stderr = t.<cmd_name>(*arguments, **options)
|
||||||
|
|
||||||
**Note**: method name same as reserved keyword like `import` could be called directly by using the following
|
**Note**: method name same as reserved keyword like `import` could be called directly
|
||||||
|
by adding `_cmd` after command name
|
||||||
|
|
||||||
from python_terraform import Terraform
|
from python_terraform import Terraform
|
||||||
t = Terraform()
|
t = Terraform()
|
||||||
return_code, stdout, stderr = t.<cmd_name>_method(*arguments, **options)
|
return_code, stdout, stderr = t.<cmd_name>_cmd(*arguments, **options)
|
||||||
|
|
||||||
or just call cmd method directly
|
or just call cmd method directly
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,11 @@ class Terraform(object):
|
||||||
|
|
||||||
def __getattr__(self, item):
|
def __getattr__(self, item):
|
||||||
def wrapper(*args, **kwargs):
|
def wrapper(*args, **kwargs):
|
||||||
|
cmd_name = str(item)
|
||||||
|
if cmd_name.endswith('_cmd'):
|
||||||
|
cmd_name = cmd_name[:-4]
|
||||||
logging.debug('called with %r and %r' % (args, kwargs))
|
logging.debug('called with %r and %r' % (args, kwargs))
|
||||||
return self.cmd(item, *args, **kwargs)
|
return self.cmd(cmd_name, *args, **kwargs)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
|
@ -173,5 +173,6 @@ class TestTerraform(object):
|
||||||
|
|
||||||
def test_import(self):
|
def test_import(self):
|
||||||
tf = Terraform(working_dir=current_path)
|
tf = Terraform(working_dir=current_path)
|
||||||
tf.cmd('import', 'aws_instance.foo', 'i-abc123')
|
ret, out, err = tf.import_cmd('aws_instance.foo', 'i-abc1234', no_color=IsFlagged)
|
||||||
assert False
|
assert 'Import complete!' in out
|
||||||
|
assert 1 == ret
|
||||||
|
|
Loading…
Reference in a new issue