Python binding for Terraform.
Project description
Python libterraform
Python binding for Terraform.
Installation
$ pip install libterraform
NOTE
- Please install version 0.3.1 or above, which solves the memory leak problem.
- This library does not support multithreading.
Usage
Terraform CLI
TerraformCommand is used to invoke various Terraform commands.
Now, support all commands (plan, apply, destroy etc.), and return a CommandResult object. The CommandResult
object has the following properties:
retcodeindicates the command return code. A value of 0 or 2 is normal, otherwise is abnormal.valuerepresents command output. Ifjson=Trueis specified when executing the command, the output will be loaded as json.jsonindicates whether to load the output as json.errorindicates command error output.
To get Terraform verison:
>>> from libterraform import TerraformCommand
>>> TerraformCommand().version()
<CommandResult retcode=0 json=True>
>>> _.value
{'terraform_version': '1.8.4', 'platform': 'darwin_arm64', 'provider_selections': {}, 'terraform_outdated': True}
>>> TerraformCommand().version(json=False)
<CommandResult retcode=0 json=False>
>>> _.value
'Terraform v1.8.4\non darwin_arm64\n'
To init and apply according to Terraform configuration files in the specified directory:
>>> from libterraform import TerraformCommand
>>> cli = TerraformCommand('your_terraform_configuration_directory')
>>> cli.init()
<CommandResult retcode=0 json=False>
>>> cli.apply()
<CommandResult retcode=0 json=True>
Additionally, run() can execute arbitrary commands, returning a tuple (retcode, stdout, stderr).
>>> TerraformCommand.run('version')
(0, 'Terraform v1.8.4\non darwin_arm64\n', '')
>>> TerraformCommand.run('invalid')
(1, '', 'Terraform has no command named "invalid".\n\nTo see all of Terraform\'s top-level commands, run:\n terraform -help\n\n')
Terraform Config Parser
TerraformConfig is used to parse Terraform config files.
For now, only supply TerraformConfig.load_config_dir method which reads the .tf and .tf.json files in the given
directory as config files and then combines these files into a single Module. This method returns (mod, diags)
which are both dict, corresponding to
the *Module
and hcl.Diagnostic structures in Terraform
respectively.
>>> from libterraform import TerraformConfig
>>> mod, _ = TerraformConfig.load_config_dir('your_terraform_configuration_directory')
>>> mod['ManagedResources'].keys()
dict_keys(['time_sleep.wait1', 'time_sleep.wait2'])
Version comparison
| libterraform | Terraform |
|---|---|
| 0.8.0 | 1.8.4 |
| 0.7.0 | 1.6.6 |
| 0.6.0 | 1.5.7 |
| 0.5.0 | 1.3.0 |
| 0.4.0 | 1.2.2 |
| 0.3.1 | 1.1.7 |
Building & Testing
If you want to develop this library, should first prepare the following environments:
Then, initialize git submodule:
$ git submodule init
$ git submodule update
pip install necessary tools:
$ pip install poetry pytest
Now, we can build and test:
$ poetry build -f wheel
$ pytest
Why use this library?
Terraform is a great tool for deploying resources. If you need to call the Terraform command in the Python program for deployment, a new process needs to be created to execute the Terraform command on the system. A typical example of this is the python-terraform library. Doing so has the following problems:
- Requires Terraform commands on the system.
- The overhead of starting a new process is relatively high.
This library compiles Terraform as a dynamic link library in advance, and then loads it for calling. So there is no need to install Terraform, nor to start a new process.
In addition, since the Terraform dynamic link library is loaded, this library can further call Terraform's internal capabilities, such as parsing Terraform config files.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file libterraform-0.8.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 48.7 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19ee4bb689f6b9b4fc445351941f1642a2b54fab23de530f29769ceb6fb2ea85
|
|
| MD5 |
b11009f240dd3e0985ba88685bb883bc
|
|
| BLAKE2b-256 |
2d0aa9619db80176aeb1cbd45d28364ad3441534db1dfdc726b879e7bb5500f2
|
File details
Details for the file libterraform-0.8.0-cp312-cp312-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp312-cp312-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 49.3 MB
- Tags: CPython 3.12, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cc4bd1d3c1722972281898ea3323853ea43d51a7e524e520861c0359dfc5502
|
|
| MD5 |
d0dc43736c6b127ebd4d95a0a1f59ab1
|
|
| BLAKE2b-256 |
91766836e7e4d7d23f27a622f513e9d8ca07bfa49c9fdba4dc6eabe2ae0e673c
|
File details
Details for the file libterraform-0.8.0-cp312-cp312-macosx_14_0_arm64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp312-cp312-macosx_14_0_arm64.whl
- Upload date:
- Size: 25.8 MB
- Tags: CPython 3.12, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d437ab3e27b43f5bf53dcc14e3e2a748e6345afa53a3be1c618e5f85164d8b93
|
|
| MD5 |
302bb3b17a8ac7b93ed97a9445a69f1c
|
|
| BLAKE2b-256 |
674f998d8b6bb978af390e02953db1fccec5671b5ee0844a60ebeee09afc2e06
|
File details
Details for the file libterraform-0.8.0-cp312-cp312-macosx_12_0_x86_64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp312-cp312-macosx_12_0_x86_64.whl
- Upload date:
- Size: 27.4 MB
- Tags: CPython 3.12, macOS 12.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d4d9e745f157b5164c8e02e8bf3714d3349e61279ecaa6256a031e982bf6b6e
|
|
| MD5 |
d1d81d713aabf36f4472dd2d43b97026
|
|
| BLAKE2b-256 |
b1a010924513f68b6a192d5e01daedcd0c8e9fa807bd5258d8279f0a7adba053
|
File details
Details for the file libterraform-0.8.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 48.7 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
806680187cf24b24d7e739f87584ad4ebc67cecb817f7634c8ccf35318bf3da3
|
|
| MD5 |
ae40470b47ba2ef33161d0673c2ea31f
|
|
| BLAKE2b-256 |
ec03c4fd8c7bf321d0dee392a1eff73c29bbbc282831b7c339ff2122e302a9f5
|
File details
Details for the file libterraform-0.8.0-cp311-cp311-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp311-cp311-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 49.3 MB
- Tags: CPython 3.11, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5799bbbf7af72d52799f4afbffae00dd8192d1ea70c89abfcbee2bb6c1841832
|
|
| MD5 |
deb712a9f151c7eeeaccef7d85318c5d
|
|
| BLAKE2b-256 |
0afbd96a91f352930ee4b59f106850b76f81222f7a787cdb98e95eafbfa75db1
|
File details
Details for the file libterraform-0.8.0-cp311-cp311-macosx_14_0_arm64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp311-cp311-macosx_14_0_arm64.whl
- Upload date:
- Size: 25.8 MB
- Tags: CPython 3.11, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
020773d41680ff301627115f523ed5bd3da713bf3209b2ff84283b2162601fe7
|
|
| MD5 |
ca39e5d4ec6c578d0630e6b89c284f37
|
|
| BLAKE2b-256 |
139f4545980723f129fb2ab749ca62c80b79d240b60c581133bffc694c850f6b
|
File details
Details for the file libterraform-0.8.0-cp311-cp311-macosx_12_0_x86_64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp311-cp311-macosx_12_0_x86_64.whl
- Upload date:
- Size: 27.4 MB
- Tags: CPython 3.11, macOS 12.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f74d297710913a2cabf4513763c274444f395695dd27102f0d3583bcef2952c2
|
|
| MD5 |
b814b176f0c65204cda1aeeef4da046b
|
|
| BLAKE2b-256 |
647fa0bd1eed5ecd076e8715456ad9fe6022c1b1e7888b7be141c11aa3de63fb
|
File details
Details for the file libterraform-0.8.0-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 48.7 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d97cda87e7b56ec443ad00ed26e15a18a75594d3c3a4bc027eb186c059a7810
|
|
| MD5 |
5b8f858b7b64cb333fce315d0f480d27
|
|
| BLAKE2b-256 |
051913d1427337de3f52fd3b0119b07aa2c2c1782e7f6022d6847ffc31b32482
|
File details
Details for the file libterraform-0.8.0-cp310-cp310-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp310-cp310-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 49.3 MB
- Tags: CPython 3.10, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abe854e96279e62a27a4b9ba6aa2077cf9d25854bddbba48edf43dcf78bbb066
|
|
| MD5 |
ecd9c1c70db944a5b8de3caab1ef6f1f
|
|
| BLAKE2b-256 |
7aaa43e65b896565a3bf617b761fae31a9f053f94e64d24cc1a628ad5ce1e8a8
|
File details
Details for the file libterraform-0.8.0-cp310-cp310-macosx_14_0_arm64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp310-cp310-macosx_14_0_arm64.whl
- Upload date:
- Size: 25.8 MB
- Tags: CPython 3.10, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8118429ae8c2ca8622c55785dde0a49206229222dda96c8378abccadef8e48e
|
|
| MD5 |
0b1852b89fbc27a9039539d7d16fe772
|
|
| BLAKE2b-256 |
52c325f123e75248f527e970205901f51abd3c4c732b80a5b8f078de253fe80c
|
File details
Details for the file libterraform-0.8.0-cp310-cp310-macosx_12_0_x86_64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp310-cp310-macosx_12_0_x86_64.whl
- Upload date:
- Size: 27.4 MB
- Tags: CPython 3.10, macOS 12.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e48548c9a6cdd572c42567ff45f7913c5689d4b1b7c225d1ded630f6d5960c8
|
|
| MD5 |
d6d2c1339eed72bb2bfd2b4dc30cb043
|
|
| BLAKE2b-256 |
ff21e35a739a909da2811d0f7ae70af2fe57a227b91130774626ea0b0a07c5ac
|
File details
Details for the file libterraform-0.8.0-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 48.7 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
026c59f5a9ca5077cd864def280a437f3167fdeabe402020da673637ff6e9c66
|
|
| MD5 |
d92ae7e03f3f5a4d4a162344801d012c
|
|
| BLAKE2b-256 |
4a2102c835fb8c06cf95d6babde41a2625b37f2fa99d295974a74ad1c6932c40
|
File details
Details for the file libterraform-0.8.0-cp39-cp39-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp39-cp39-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 49.3 MB
- Tags: CPython 3.9, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e315f5209d813a582edeb9fec06ec1a4b4828c0a3d3cdea9ca43a074f2c46908
|
|
| MD5 |
33dec3ccd9156c74cd56d48631a827a7
|
|
| BLAKE2b-256 |
01c37bba7faf7c1ad1e5802ed4a386d9c96eca498d45710cf12d1e3d3727848c
|
File details
Details for the file libterraform-0.8.0-cp39-cp39-macosx_14_0_arm64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp39-cp39-macosx_14_0_arm64.whl
- Upload date:
- Size: 25.8 MB
- Tags: CPython 3.9, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f278e76d52fd2249ae205272265f5b25b5ae6be986a10a4bc6663bdbdbf15a43
|
|
| MD5 |
d0b67870b0ad454a558dbf25bc31dacc
|
|
| BLAKE2b-256 |
c8d2347eeaaf3fa721cfb5e32c519b2e846955c8dae5349b6aa62dbbf84aa003
|
File details
Details for the file libterraform-0.8.0-cp39-cp39-macosx_12_0_x86_64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp39-cp39-macosx_12_0_x86_64.whl
- Upload date:
- Size: 27.4 MB
- Tags: CPython 3.9, macOS 12.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08316237f27826896d9c16e854eac50a97a24f79e2be09c92bd899ee1e079ee5
|
|
| MD5 |
df0dab552b3377f3a7750c3633412e84
|
|
| BLAKE2b-256 |
02614e7f4d14b3897a4a7005de573305204fa4fa77d936e7baa8c4d77b509572
|
File details
Details for the file libterraform-0.8.0-cp38-cp38-win_amd64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 48.7 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26e916834da828fb1b4d94b8f2888f32bd1b66e3b8b36438340ecb59f2e2bad5
|
|
| MD5 |
31e3e6b1fc89d70085bd5d1957762e35
|
|
| BLAKE2b-256 |
f0c1450b100bd1c2e17cf3b5f806eae220b3eac0889ba2a4ff07441031b4db93
|
File details
Details for the file libterraform-0.8.0-cp38-cp38-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp38-cp38-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 49.3 MB
- Tags: CPython 3.8, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0bb0607a26f5b5072a1aacc4d4a6d7f5b3e0517357a44414205364eedae1727
|
|
| MD5 |
e8b4469f90a428116f4d9cf49ef56656
|
|
| BLAKE2b-256 |
7b3f6fa710d9cedce2ecc2e7336a3595a406270a5cc4390d52882f0718410272
|
File details
Details for the file libterraform-0.8.0-cp38-cp38-macosx_14_0_arm64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp38-cp38-macosx_14_0_arm64.whl
- Upload date:
- Size: 25.8 MB
- Tags: CPython 3.8, macOS 14.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d53a2cc51469f06d6ec16c750bd7c86633c00e48dfa7e3dfe991eb62545cbcaf
|
|
| MD5 |
b211cb6e934d99b35340a57d03add203
|
|
| BLAKE2b-256 |
87d3c7d45eff57cfe563722f7c7679d724d25a0cd76cdbe1ba0ff4576b4fc9fb
|
File details
Details for the file libterraform-0.8.0-cp38-cp38-macosx_12_0_x86_64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp38-cp38-macosx_12_0_x86_64.whl
- Upload date:
- Size: 27.4 MB
- Tags: CPython 3.8, macOS 12.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f490e06de8f7651787bcac365fbebbbb37333d1e7594045a1616d7e6c385a64a
|
|
| MD5 |
aa4690b12ec186058295bd198bb6c8e8
|
|
| BLAKE2b-256 |
3cef7e739a31373ee668a7e98e00d67427fa922893ba21a5c02661148e619342
|
File details
Details for the file libterraform-0.8.0-cp37-cp37m-win_amd64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 48.7 MB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
077cc03b0bf59f526bc2ddbd2776cab939766b51781ae5494d9d272961c9063d
|
|
| MD5 |
a4b2caf8ec3d4edecfacfb080b88c20d
|
|
| BLAKE2b-256 |
7c21db26c6b7d28c6c64a5dcf10a1510dad27a80105e96d3507ee56b86552f53
|
File details
Details for the file libterraform-0.8.0-cp37-cp37m-manylinux_2_31_x86_64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp37-cp37m-manylinux_2_31_x86_64.whl
- Upload date:
- Size: 49.3 MB
- Tags: CPython 3.7m, manylinux: glibc 2.31+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f347dfa7d09ebd2f7aadaefc919aa463fd5ce6d2b40cd826ac4c37478a3166e3
|
|
| MD5 |
8b372e869ed8802d53c13c3a12b02c89
|
|
| BLAKE2b-256 |
12f62cf82829498ca61ecb8f63391929aabb36abb3b31f650c6171c2ab7721c1
|
File details
Details for the file libterraform-0.8.0-cp37-cp37m-macosx_12_0_x86_64.whl.
File metadata
- Download URL: libterraform-0.8.0-cp37-cp37m-macosx_12_0_x86_64.whl
- Upload date:
- Size: 27.4 MB
- Tags: CPython 3.7m, macOS 12.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.11 Darwin/23.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f92759b2353c453ab97783e63dd717e43f3904e008a7482c4cc4cbbaf0a6167
|
|
| MD5 |
083a555245b49fb9d36ec3c91bd6df12
|
|
| BLAKE2b-256 |
2ba901c48a08b501ddd140af0303947e30ccad4156f2c5d340139c45669c1bf6
|