Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix list handling #66

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading