From f9c43a310d4363282b52080f36c53d51b3a63ad0 Mon Sep 17 00:00:00 2001 From: Prodesire Date: Thu, 14 Sep 2023 16:04:01 +0800 Subject: [PATCH] Current version 0.5.0 using Terraform 1.3.0 - `fmt` supports multi dirs - `force_unlock` removes allow_missing_config - only python 3.7 and above are supported --- .github/workflows/release.yml | 6 +++--- .github/workflows/test.yml | 6 +++--- Makefile | 12 ++++++++++++ README.md | 7 ++++--- libterraform/__init__.py | 2 +- libterraform/cli.py | 13 ++++++++----- pyproject.toml | 4 ++-- terraform | 2 +- tests/cli/test_fmt.py | 8 +++++++- tests/cli/test_import.py | 13 ------------- tests/consts.py | 1 + tests/tf/sleep2/main.tf | 25 +++++++++++++++++++++++++ 12 files changed, 67 insertions(+), 32 deletions(-) create mode 100644 tests/tf/sleep2/main.tf diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9e8c817..01ef47b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,8 +9,8 @@ jobs: build: strategy: matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] - python-version: [ '3.6', '3.7', '3.8', '3.9', '3.10' ] + os: [ ubuntu-20.04, windows-latest, macos-latest ] + python-version: [ '3.7.9', '3.8.10', '3.9.13', '3.10.11', '3.11.5' ] runs-on: ${{ matrix.os }} steps: - name: Check out repository code @@ -18,7 +18,7 @@ jobs: - name: Set up GoLang uses: actions/setup-go@v2 with: - go-version: '1.17' + go-version: '1.18' - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7f8e20d..c330e36 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,8 +6,8 @@ jobs: test: strategy: matrix: - os: [ ubuntu-latest, windows-latest, macos-latest ] - python-version: [ '3.6', '3.7', '3.8', '3.9', '3.10' ] + os: [ ubuntu-20.04, windows-latest, macos-latest ] + python-version: [ '3.7.9', '3.8.10', '3.9.13', '3.10.11', '3.11.5' ] runs-on: ${{ matrix.os }} steps: - name: Check out repository code @@ -15,7 +15,7 @@ jobs: - name: Set up GoLang uses: actions/setup-go@v2 with: - go-version: '1.17' + go-version: '1.18' - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: diff --git a/Makefile b/Makefile index c275f44..ccf411d 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,18 @@ test: clean-pyc build: $(PY3) -m poetry build -f wheel +build-all: + $(PY3) -m poetry env use python3.7 + $(PY3) -m poetry build -f wheel + $(PY3) -m poetry env use python3.8 + $(PY3) -m poetry build -f wheel + $(PY3) -m poetry env use python3.9 + $(PY3) -m poetry build -f wheel + $(PY3) -m poetry env use python3.10 + $(PY3) -m poetry build -f wheel + $(PY3) -m poetry env use python3.11 + $(PY3) -m poetry build -f wheel + publish: $(PY3) -m poetry publish diff --git a/README.md b/README.md index 4b58e5d..d315779 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![libterraform](https://img.shields.io/pypi/v/libterraform.svg)](https://pypi.python.org/pypi/libterraform) [![libterraform](https://img.shields.io/pypi/l/libterraform.svg)](https://pypi.python.org/pypi/libterraform) [![libterraform](https://img.shields.io/pypi/pyversions/libterraform.svg)](https://pypi.python.org/pypi/libterraform) -[![Test](https://github.com/Prodesire/py-libterraform/actions/workflows/test.yml/badge.svg)](https://github.com/Prodesire/py-libterraform/actions/workflows/release.yml) +[![Test](https://github.com/Prodesire/py-libterraform/actions/workflows/test.yml/badge.svg)](https://github.com/Prodesire/py-libterraform/actions/workflows/test.yml) [![libterraform](https://img.shields.io/pypi/dm/libterraform)](https://pypi.python.org/pypi/libterraform) Python binding for [Terraform](https://www.terraform.io/). @@ -89,6 +89,7 @@ dict_keys(['time_sleep.wait1', 'time_sleep.wait2']) | libterraform | Terraform | |-------------------------------------------------------|-------------------------------------------------------------| +| [0.5.0](https://pypi.org/project/libterraform/0.5.0/) | [1.3.0](https://github.com/hashicorp/terraform/tree/v1.3.0) | | [0.4.0](https://pypi.org/project/libterraform/0.4.0/) | [1.2.2](https://github.com/hashicorp/terraform/tree/v1.2.2) | | [0.3.1](https://pypi.org/project/libterraform/0.3.1/) | [1.1.7](https://github.com/hashicorp/terraform/tree/v1.1.7) | @@ -96,8 +97,8 @@ dict_keys(['time_sleep.wait1', 'time_sleep.wait2']) If you want to develop this library, should first prepare the following environments: -- [GoLang](https://go.dev/dl/) (Version 1.17.x or 1.16.x) -- [Python](https://www.python.org/downloads/) (Version 3.6~3.10) +- [GoLang](https://go.dev/dl/) (Version 1.18+) +- [Python](https://www.python.org/downloads/) (Version 3.7~3.10) - GCC Then, initialize git submodule: diff --git a/libterraform/__init__.py b/libterraform/__init__.py index 6757f90..bb88edf 100644 --- a/libterraform/__init__.py +++ b/libterraform/__init__.py @@ -2,7 +2,7 @@ from ctypes import cdll, c_void_p from libterraform.common import WINDOWS -__version__ = '0.4.0' +__version__ = '0.5.0' root = os.path.dirname(os.path.abspath(__file__)) _lib_filename = 'libterraform.dll' if WINDOWS else 'libterraform.so' diff --git a/libterraform/cli.py b/libterraform/cli.py index 03629c4..9b3cbd4 100644 --- a/libterraform/cli.py +++ b/libterraform/cli.py @@ -584,7 +584,7 @@ def destroy( def fmt( self, - dir: str = None, + dir: Union[str, List[str]] = None, check: bool = False, no_color: bool = True, list: bool = None, @@ -626,7 +626,12 @@ def fmt( check=flag(check_input), recursive=flag(recursive), ) - args = [dir] if dir else None + if dir: + args = dir + if not isinstance(dir, List): + args = [dir] + else: + args = None retcode, stdout, stderr = self.run('fmt', args, options=options, chdir=self.cwd, check=check) return CommandResult(retcode, stdout, stderr, json=False) @@ -704,7 +709,6 @@ def import_resource( id: str, check: bool = False, config: str = None, - allow_missing_config: bool = None, input: bool = False, lock: bool = None, lock_timeout: str = None, @@ -745,7 +749,6 @@ def import_resource( to use to configure the provider. Defaults to pwd. If no config files are present, they must be provided via the input prompts or env vars. - :param allow_missing_config: True to allow import when no resource configuration block exists. :param input: False to disable interactive prompts. Note that some actions may require interactive prompts and will error if input is disabled. :param lock: False to not hold a state lock during backend migration. @@ -763,7 +766,6 @@ def import_resource( """ options.update( config=config, - allow_missing_config=flag(allow_missing_config), input=input, lock=lock, lock_timeout=lock_timeout, @@ -798,6 +800,7 @@ def output( :param json: Whether to load stdout as json. :param no_color: True to output not contain any color. :param state: Path to the state file to read. Defaults to "terraform.tfstate". + Ignored when remote state is used. :param raw: For value types that can be automatically converted to a string, will print the raw string directly, rather than a human-oriented representation of the value. diff --git a/pyproject.toml b/pyproject.toml index 4c95a44..8b88fa4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "libterraform" -version = "0.4.0" +version = "0.5.0" description = "Python binding for Terraform." authors = ["Prodesire "] license = "MIT" @@ -30,7 +30,7 @@ packages = [ include = ["libterraform/libterraform.so", "libterraform/libterraform.dll"] [tool.poetry.dependencies] -python = "^3.6" +python = "^3.7" [tool.poetry.dev-dependencies] pytest = "^7.0.1" diff --git a/terraform b/terraform index 129f62a..5c239ec 160000 --- a/terraform +++ b/terraform @@ -1 +1 @@ -Subproject commit 129f62ae6f340ad8cf006a2f4d25d391d35a027b +Subproject commit 5c239ecd6ac3a183bb4852940f2f2d1af1a766ce diff --git a/tests/cli/test_fmt.py b/tests/cli/test_fmt.py index 8df49ab..858bc03 100644 --- a/tests/cli/test_fmt.py +++ b/tests/cli/test_fmt.py @@ -1,7 +1,7 @@ import re from libterraform import TerraformCommand -from tests.consts import TF_SLEEP_DIR +from tests.consts import TF_SLEEP_DIR, TF_SLEEP2_DIR class TestTerraformCommandFmt: @@ -15,3 +15,9 @@ def test_fmt_dir(self): r = cli.fmt(TF_SLEEP_DIR, list=False, write=False, diff=False, recursive=True) assert r.retcode == 0, r.error assert r.value + + def test_fmt_dirs(self): + cli = TerraformCommand() + r = cli.fmt([TF_SLEEP_DIR, TF_SLEEP2_DIR], list=False, write=False, diff=False, recursive=True) + assert r.retcode == 0, r.error + assert r.value diff --git a/tests/cli/test_import.py b/tests/cli/test_import.py index 8c0c391..17420f6 100644 --- a/tests/cli/test_import.py +++ b/tests/cli/test_import.py @@ -11,16 +11,3 @@ def test_import(self, cli: TerraformCommand): assert 'Import does not generate resource configuration' not in r.value finally: cli.destroy() - - def test_import_missing(self, cli: TerraformCommand): - cli.destroy() - try: - r = cli.import_resource('time_sleep.missing', '1s,') - assert r.retcode == 1, r.value - - r = cli.import_resource('time_sleep.missing', '1s,', allow_missing_config=True) - assert r.retcode == 0, r.error - assert 'Import successful!' in r.value - assert 'Import does not generate resource configuration' in r.value - finally: - cli.destroy() diff --git a/tests/consts.py b/tests/consts.py index 542f3be..98c4336 100644 --- a/tests/consts.py +++ b/tests/consts.py @@ -3,3 +3,4 @@ ROOT = os.path.dirname(__file__) TF_DIR = os.path.join(ROOT, 'tf') TF_SLEEP_DIR = os.path.join(TF_DIR, 'sleep') +TF_SLEEP2_DIR = os.path.join(TF_DIR, 'sleep2') diff --git a/tests/tf/sleep2/main.tf b/tests/tf/sleep2/main.tf new file mode 100644 index 0000000..b9a5132 --- /dev/null +++ b/tests/tf/sleep2/main.tf @@ -0,0 +1,25 @@ +variable "sleep2_time1" { + type = string + default = "1s" +} + +variable "sleep2_time2" { + type = string + default = "1s" +} + +resource "time_sleep" "sleep2_wait1" { + create_duration = var.time1 +} + +resource "time_sleep" "sleep2_wait2" { + create_duration = var.time2 +} + +output "sleep2_wait1_id" { + value = time_sleep.wait1.id +} + +output "sleep2_wait2_id" { + value = time_sleep.wait2.id +}