fix terraform import cmd is a reseved word of python

merge-requests/1/head
beelit94 7 years ago
parent ddc9a1ed34
commit 38222a42f5

@ -10,13 +10,25 @@ python-terraform is a python module provide a wrapper of `terraform` command lin
pip install python-terraform
## Usage
####For any terraform command
#### For any terraform command
from python_terraform import Terraform
t = Terraform()
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
from python_terraform import Terraform
t = Terraform()
return_code, stdout, stderr = t.<cmd_name>_method(*arguments, **options)
or just call cmd method directly
from python_terraform import Terraform
t = Terraform()
return_code, stdout, stderr = t.cmd(<cmd_name>, *arguments, **options)
####For any argument
#### For any argument
simply pass the string to arguments of the method, for example,
terraform apply target_dir
@ -24,7 +36,7 @@ simply pass the string to arguments of the method, for example,
terraform import aws_instance.foo i-abcd1234
--> <instance>.import('aws_instance.foo', 'i-abcd1234')
####For any options
#### For any options
* dash to underscore

@ -6,6 +6,8 @@ import re
import shutil
logging.basicConfig(level=logging.DEBUG)
ch = logging.StreamHandler(sys.stdout)
logging.getLogger().addHandler(ch)
current_path = os.path.dirname(os.path.realpath(__file__))
STRING_CASES = [
@ -23,11 +25,18 @@ STRING_CASES = [
]
CMD_CASES = [
['method', 'expected_output'],
['method', 'expected_output', 'expected_ret_code'],
[
[
lambda x: x.cmd('plan', 'var_to_output', no_color=IsFlagged, var={'test_var': 'test'}) ,
"doesn't need to do anything"
"doesn't need to do anything",
0
],
# try import aws instance
[
lambda x: x.cmd('import', 'aws_instance.foo', 'i-abcd1234', no_color=IsFlagged),
'Import complete!',
1
]
]
]
@ -73,11 +82,11 @@ class TestTerraform(object):
assert s in result
@pytest.mark.parametrize(*CMD_CASES)
def test_cmd(self, method, expected_output):
def test_cmd(self, method, expected_output, expected_ret_code):
tf = Terraform(working_dir=current_path)
ret, out, err = method(tf)
assert expected_output in out
assert ret == 0
assert expected_ret_code == ret
@pytest.mark.parametrize(
("folder", "variables", "var_files", "expected_output", "options"),
@ -161,3 +170,8 @@ class TestTerraform(object):
tf = Terraform(working_dir=current_path, variables={'test_var': 'test'})
ret, out, err = tf.fmt(diff=True)
assert ret == 0
def test_import(self):
tf = Terraform(working_dir=current_path)
tf.cmd('import', 'aws_instance.foo', 'i-abc123')
assert False

Loading…
Cancel
Save