Skip to content

Commit

Permalink
[feature] added support to pass a complex dict (#69)
Browse files Browse the repository at this point in the history
* [feature] added support to pass a complex dict
to the tf_vars parameter

* [feature] added some tests

* [cleanup]

* fix linting

Co-authored-by: Nikolai Shmatenkov <[email protected]>
Co-authored-by: Ludo <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2023
1 parent 6804937 commit 707a604
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions test/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@
({'tf_var_file': 'foo.tfvar'}, ['-var-file=foo.tfvar']),
({'tf_var_file': ['foo.tfvar', 'bar.tfvar']}, [
'-var-file=foo.tfvar', '-var-file=bar.tfvar']),
({'tf_vars': {'text': 'text'}}, ['-var', 'text=text']),
({'tf_vars': {'number': 0}}, ['-var', 'number=0']),
({'tf_vars': {'bool': False}}, ['-var', 'bool=False']),
({'tf_vars': {'dict': {'text': 'text'}}},
['-var', 'dict={"text": "text"}']),
({'tf_vars': {'list': ['item1', 'item2']}},
['-var', 'list=["item1", "item2"]']),
({'tf_vars': {'dict': {'list': ['item1', 'item2']}}},
['-var', 'dict={"list": ["item1", "item2"]}']),
)


Expand Down
5 changes: 4 additions & 1 deletion tftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ def parse_args(init_vars=None, tf_vars=None, targets=None, **kw):
if tf_vars:
cmd_args += list(
itertools.chain.from_iterable(
("-var", "{}={}".format(k, v)) for k, v in tf_vars.items()))
("-var",
"{}={}".format(k, json.dumps(v) if isinstance(v, (dict, list)) else v))
for k, v in tf_vars.items()
))
if targets:
cmd_args += [("-target={}".format(t)) for t in targets]
if kw.get('tf_var_file'):
Expand Down

0 comments on commit 707a604

Please sign in to comment.