Skip to content

Commit

Permalink
fix list handling (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
wisefool769 authored Jan 28, 2025
1 parent e623ff6 commit a11c6be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bin/tflocal
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ def generate_s3_backend_config() -> str:
prefix=" " * 4)
config_options += f"\n{value}"
continue
elif isinstance(value, list):
# 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}'
Expand Down
8 changes: 7 additions & 1 deletion tests/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, "..")
Expand Down Expand Up @@ -294,6 +296,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" {
Expand All @@ -317,7 +320,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", [
Expand Down Expand Up @@ -449,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)
Expand Down

0 comments on commit a11c6be

Please sign in to comment.