fix terraform import cmd is a reseved word of python
This commit is contained in:
parent
ddc9a1ed34
commit
38222a42f5
2 changed files with 33 additions and 7 deletions
18
README.md
18
README.md
|
@ -10,13 +10,25 @@ python-terraform is a python module provide a wrapper of `terraform` command lin
|
||||||
pip install python-terraform
|
pip install python-terraform
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
####For any terraform command
|
#### For any terraform command
|
||||||
|
|
||||||
from python_terraform import Terraform
|
from python_terraform import Terraform
|
||||||
t = Terraform()
|
t = Terraform()
|
||||||
return_code, stdout, stderr = t.<cmd_name>(*arguments, **options)
|
return_code, stdout, stderr = t.<cmd_name>(*arguments, **options)
|
||||||
|
|
||||||
####For any argument
|
**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
|
||||||
simply pass the string to arguments of the method, for example,
|
simply pass the string to arguments of the method, for example,
|
||||||
|
|
||||||
terraform apply target_dir
|
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
|
terraform import aws_instance.foo i-abcd1234
|
||||||
--> <instance>.import('aws_instance.foo', 'i-abcd1234')
|
--> <instance>.import('aws_instance.foo', 'i-abcd1234')
|
||||||
|
|
||||||
####For any options
|
#### For any options
|
||||||
|
|
||||||
* dash to underscore
|
* dash to underscore
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@ import re
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
ch = logging.StreamHandler(sys.stdout)
|
||||||
|
logging.getLogger().addHandler(ch)
|
||||||
current_path = os.path.dirname(os.path.realpath(__file__))
|
current_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
|
||||||
STRING_CASES = [
|
STRING_CASES = [
|
||||||
|
@ -23,11 +25,18 @@ STRING_CASES = [
|
||||||
]
|
]
|
||||||
|
|
||||||
CMD_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'}) ,
|
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
|
assert s in result
|
||||||
|
|
||||||
@pytest.mark.parametrize(*CMD_CASES)
|
@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)
|
tf = Terraform(working_dir=current_path)
|
||||||
ret, out, err = method(tf)
|
ret, out, err = method(tf)
|
||||||
assert expected_output in out
|
assert expected_output in out
|
||||||
assert ret == 0
|
assert expected_ret_code == ret
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("folder", "variables", "var_files", "expected_output", "options"),
|
("folder", "variables", "var_files", "expected_output", "options"),
|
||||||
|
@ -161,3 +170,8 @@ class TestTerraform(object):
|
||||||
tf = Terraform(working_dir=current_path, variables={'test_var': 'test'})
|
tf = Terraform(working_dir=current_path, variables={'test_var': 'test'})
|
||||||
ret, out, err = tf.fmt(diff=True)
|
ret, out, err = tf.fmt(diff=True)
|
||||||
assert ret == 0
|
assert ret == 0
|
||||||
|
|
||||||
|
def test_import(self):
|
||||||
|
tf = Terraform(working_dir=current_path)
|
||||||
|
tf.cmd('import', 'aws_instance.foo', 'i-abc123')
|
||||||
|
assert False
|
||||||
|
|
Loading…
Reference in a new issue