diff --git a/README.md b/README.md index 5a7a0f7..86a4d92 100644 --- a/README.md +++ b/README.md @@ -16,11 +16,12 @@ python-terraform is a python module provide a wrapper of `terraform` command lin t = Terraform() return_code, stdout, stderr = t.(*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 t = Terraform() - return_code, stdout, stderr = t._method(*arguments, **options) + return_code, stdout, stderr = t._cmd(*arguments, **options) or just call cmd method directly diff --git a/python_terraform/__init__.py b/python_terraform/__init__.py index 769350e..8eee5ab 100644 --- a/python_terraform/__init__.py +++ b/python_terraform/__init__.py @@ -64,8 +64,11 @@ class Terraform(object): def __getattr__(self, item): 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)) - return self.cmd(item, *args, **kwargs) + return self.cmd(cmd_name, *args, **kwargs) return wrapper diff --git a/test/test_terraform.py b/test/test_terraform.py index 961c155..6ff8e3b 100644 --- a/test/test_terraform.py +++ b/test/test_terraform.py @@ -173,5 +173,6 @@ class TestTerraform(object): def test_import(self): tf = Terraform(working_dir=current_path) - tf.cmd('import', 'aws_instance.foo', 'i-abc123') - assert False + ret, out, err = tf.import_cmd('aws_instance.foo', 'i-abc1234', no_color=IsFlagged) + assert 'Import complete!' in out + assert 1 == ret