From 0ee8caae72281ad9df5595f9be9ebcb573499365 Mon Sep 17 00:00:00 2001 From: Aashiq Dheeraj Date: Thu, 23 Jan 2025 19:09:35 -0500 Subject: [PATCH 1/4] fix bug in handling for lists --- bin/tflocal | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/tflocal b/bin/tflocal index 779c7d7..4ac6b17 100755 --- a/bin/tflocal +++ b/bin/tflocal @@ -306,6 +306,8 @@ def generate_s3_backend_config() -> str: prefix=" " * 4) config_options += f"\n{value}" continue + elif isinstance(value, list): + value = json.dumps(value) else: value = f'"{str(value)}"' config_options += f'\n {key} = {value}' From 82599c8da55ebe3e3d6fc825451dc9d533f89c80 Mon Sep 17 00:00:00 2001 From: Aashiq Dheeraj Date: Fri, 24 Jan 2025 10:47:34 -0500 Subject: [PATCH 2/4] better string formatting for list + comment --- bin/tflocal | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/tflocal b/bin/tflocal index 4ac6b17..ba5b72b 100755 --- a/bin/tflocal +++ b/bin/tflocal @@ -307,7 +307,10 @@ def generate_s3_backend_config() -> str: config_options += f"\n{value}" continue elif isinstance(value, list): - value = json.dumps(value) + # TODO this will break if it's a list of dicts or other complex object + # this serialization logic should probably be moved to a separate recursive function + as_string = [f'"{item}"' for item in value] + value = f'[{", ".join(as_string)}]' else: value = f'"{str(value)}"' config_options += f'\n {key} = {value}' From 8b18116ad1eb25515cad48e7fe095be5f6c201ae Mon Sep 17 00:00:00 2001 From: Aashiq Dheeraj Date: Mon, 27 Jan 2025 10:41:25 -0500 Subject: [PATCH 3/4] test --- tests/test_apply.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/test_apply.py b/tests/test_apply.py index 2c44b2b..ad913b5 100644 --- a/tests/test_apply.py +++ b/tests/test_apply.py @@ -294,6 +294,7 @@ def test_s3_backend_configs_merge(monkeypatch): encryption = true use_path_style = true acl = "bucket-owner-full-control" + shared_config_files = ["~/.aws/config","~/other/config"] } } resource "aws_s3_bucket" "test-bucket" { @@ -317,7 +318,9 @@ def check_override_file_backend_extra_content(override_file): return result.get("use_path_style") is True and \ result.get("encryption") is True and \ - result.get("acl") == "bucket-owner-full-control" + result.get("acl") == "bucket-owner-full-control" and \ + isinstance(result.get("shared_config_files"), list) and \ + len(result.get("shared_config_files")) == 2 @pytest.mark.parametrize("endpoints", [ From 6fb7788f43f77880090328a451349cff04f47e64 Mon Sep 17 00:00:00 2001 From: Aashiq Dheeraj Date: Mon, 27 Jan 2025 11:17:10 -0500 Subject: [PATCH 4/4] TODO's in tests dir for python version compat --- tests/test_apply.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_apply.py b/tests/test_apply.py index ad913b5..afe292b 100644 --- a/tests/test_apply.py +++ b/tests/test_apply.py @@ -13,6 +13,8 @@ import pytest import hcl2 +# TODO set up the tests to run with tox so we can run the tests with different python versions + THIS_PATH = os.path.abspath(os.path.dirname(__file__)) ROOT_PATH = os.path.join(THIS_PATH, "..") @@ -452,6 +454,7 @@ def get_version(): def deploy_tf_script(script: str, cleanup: bool = True, env_vars: Dict[str, str] = None, user_input: str = None): + # TODO the delete keyword was added in python 3.12, and the README and setup.cfg claims compatibility with earlier python versions with tempfile.TemporaryDirectory(delete=cleanup) as temp_dir: with open(os.path.join(temp_dir, "test.tf"), "w") as f: f.write(script)