Skip to content

Commit e155a29

Browse files
authored
Merge pull request #1 from Prodesire/feat/lastest-tf
Update TF to 1.2.2
2 parents 693d30a + 46a30b9 commit e155a29

File tree

6 files changed

+38
-19
lines changed

6 files changed

+38
-19
lines changed

README.md

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ $ pip install libterraform
2424

2525
`TerraformCommand` is used to invoke various Terraform commands.
2626

27-
Now, support all commands (`plan`, `apply`, `destroy` etc.), and return a `CommandResult` object.
28-
The `CommandResult` object has the following properties:
27+
Now, support all commands (`plan`, `apply`, `destroy` etc.), and return a `CommandResult` object. The `CommandResult`
28+
object has the following properties:
2929

3030
- `retcode` indicates the command return code. A value of 0 or 2 is normal, otherwise is abnormal.
3131
- `value` represents command output. If `json=True` is specified when executing the command, the output will be loaded
@@ -40,11 +40,11 @@ To get Terraform verison:
4040
>>> TerraformCommand().version()
4141
<CommandResult retcode=0 json=True>
4242
>>> _.value
43-
{'terraform_version': '1.1.7', 'platform': 'darwin_arm64', 'provider_selections': {}, 'terraform_outdated': False}
43+
{'terraform_version': '1.2.2', 'platform': 'darwin_arm64', 'provider_selections': {}, 'terraform_outdated': False}
4444
>>> TerraformCommand().version(json=False)
4545
<CommandResult retcode=0 json=False>
4646
>>> _.value
47-
'Terraform v1.1.7\non darwin_arm64\n'
47+
'Terraform v1.2.2\non darwin_arm64\n'
4848
```
4949

5050
To `init` and `apply` according to Terraform configuration files in the specified directory:
@@ -62,7 +62,7 @@ Additionally, `run()` can execute arbitrary commands, returning a tuple `(retcod
6262

6363
```python
6464
>>> TerraformCommand.run('version')
65-
(0, 'Terraform v1.1.7\non darwin_arm64\n', '')
65+
(0, 'Terraform v1.2.2\non darwin_arm64\n', '')
6666
>>> TerraformCommand.run('invalid')
6767
(1, '', 'Terraform has no command named "invalid".\n\nTo see all of Terraform\'s top-level commands, run:\n terraform -help\n\n')
6868
```
@@ -85,14 +85,23 @@ respectively.
8585
dict_keys(['time_sleep.wait1', 'time_sleep.wait2'])
8686
```
8787

88+
## Version comparison
89+
90+
| libterraform | Terraform |
91+
|-------------------------------------------------------|-------------------------------------------------------------|
92+
| [0.4.0](https://pypi.org/project/libterraform/0.4.0/) | [1.2.2](https://github.com/hashicorp/terraform/tree/v1.2.2) |
93+
| [0.3.1](https://pypi.org/project/libterraform/0.3.1/) | [1.1.7](https://github.com/hashicorp/terraform/tree/v1.1.7) |
94+
8895
## Building & Testing
8996

9097
If you want to develop this library, should first prepare the following environments:
98+
9199
- [GoLang](https://go.dev/dl/) (Version 1.17.x or 1.16.x)
92100
- [Python](https://www.python.org/downloads/) (Version 3.6~3.10)
93101
- GCC
94102

95103
Then, initialize git submodule:
104+
96105
```bash
97106
$ git submodule init
98107
$ git submodule update
@@ -105,22 +114,23 @@ $ pip install poetry pytest
105114
```
106115

107116
Now, we can build and test:
117+
108118
```bash
109119
$ poetry build -f wheel
110120
$ pytest
111121
```
112122

113-
114123
## Why use this library?
115-
Terraform is a great tool for deploying resources. If you need to call the Terraform command in the Python program
116-
for deployment, a new process needs to be created to execute the Terraform command on the system. A typical example
117-
of this is the [python-terraform](https://github.com/beelit94/python-terraform) library.
118-
Doing so has the following problems:
124+
125+
Terraform is a great tool for deploying resources. If you need to call the Terraform command in the Python program for
126+
deployment, a new process needs to be created to execute the Terraform command on the system. A typical example of this
127+
is the [python-terraform](https://github.com/beelit94/python-terraform) library. Doing so has the following problems:
128+
119129
- Requires Terraform commands on the system.
120130
- The overhead of starting a new process is relatively high.
121131

122-
This library compiles Terraform as a **dynamic link library** in advance, and then loads it for calling.
123-
So there is no need to install Terraform, nor to start a new process.
132+
This library compiles Terraform as a **dynamic link library** in advance, and then loads it for calling. So there is no
133+
need to install Terraform, nor to start a new process.
124134

125-
In addition, since the Terraform dynamic link library is loaded, this library can further call Terraform's
135+
In addition, since the Terraform dynamic link library is loaded, this library can further call Terraform's
126136
**internal capabilities**, such as parsing Terraform config files.

libterraform/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from ctypes import cdll, c_void_p
33
from libterraform.common import WINDOWS
44

5-
__version__ = '0.3.1'
5+
__version__ = '0.4.0'
66

77
root = os.path.dirname(os.path.abspath(__file__))
88
_lib_filename = 'libterraform.dll' if WINDOWS else 'libterraform.so'

libterraform/cli.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from ctypes import *
33
from threading import Thread
4-
from typing import List, Sequence
4+
from typing import List, Sequence, Union
55

66
from libterraform import _lib_tf
77
from libterraform.common import json_loads, WINDOWS, CmdType
@@ -312,8 +312,8 @@ def plan(
312312
destroy: bool = None,
313313
refresh_only: bool = None,
314314
refresh: bool = None,
315-
replace: str = None,
316-
target: str = None,
315+
replace: Union[str, List[str]] = None,
316+
target: Union[str, List[str]] = None,
317317
vars: dict = None,
318318
var_files: List[str] = None,
319319
compact_warnings: bool = None,
@@ -354,6 +354,7 @@ def plan(
354354
:param replace: Force replacement of a particular resource instance using
355355
its resource address. If the plan would've normally produced an update or
356356
no-op action for this instance, Terraform will plan to replace it instead.
357+
You can use this option multiple times to replace more than one object.
357358
:param target: Limit the planning operation to only the given module, resource,
358359
or resource instance and all of its dependencies. You can use this option
359360
multiple times to include more than one object. This is for exceptional
@@ -975,6 +976,7 @@ def refresh(
975976
lock: bool = None,
976977
lock_timeout: str = None,
977978
no_color: bool = True,
979+
parallelism: int = None,
978980
**options,
979981
) -> CommandResult:
980982
"""Refer to https://www.terraform.io/docs/commands/refresh
@@ -1003,6 +1005,7 @@ def refresh(
10031005
same workspace.
10041006
:param lock_timeout: Duration to retry a state lock.
10051007
:param no_color: True to output not contain any color.
1008+
:param parallelism: Limit the number of concurrent operations. Defaults to 10.
10061009
:param options: More command options.
10071010
"""
10081011
options.update(
@@ -1014,6 +1017,7 @@ def refresh(
10141017
lock=lock,
10151018
lock_timeout=lock_timeout,
10161019
no_color=flag(no_color),
1020+
parallelism=parallelism,
10171021
)
10181022
retcode, stdout, stderr = self.run('refresh', options=options, chdir=self.cwd, check=check, json=json)
10191023
value = json_loads(stdout, split=True) if json else stdout

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "libterraform"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
description = "Python binding for Terraform."
55
authors = ["Prodesire <[email protected]>"]
66
license = "MIT"

terraform

Submodule terraform updated 459 files

tests/cli/test_refresh.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ def test_refresh_with_target(self, cli: TerraformCommand):
1414
r = cli.refresh(target='time_sleep.wait1')
1515
assert r.retcode == 0, r.error
1616
assert r.value
17+
18+
def test_refresh_with_parallelism(self, cli: TerraformCommand):
19+
r = cli.refresh(parallelism=2)
20+
assert r.retcode == 0, r.error
21+
assert r.value

0 commit comments

Comments
 (0)