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

Passing complex objects to the tf.plan(tf_vars=...) doesn't work #67

Closed
MrImpossibru opened this issue Jan 19, 2023 · 3 comments
Closed

Comments

@MrImpossibru
Copy link
Contributor

MrImpossibru commented Jan 19, 2023

Hello,

I've met an issue with passing complex variables to the tf.plan.

That doesn't work:
tf.plan(output = True, tf_vars = { "pep_spec": { "pep1": "test" } })
because of:
cmd_args = ('-no-color', '-input=false', '-var', "pep_spec={'pep1': 'test'}", ...)

Error is: "Single quotes are not valid. Use double quotes (") to enclose strings."

That works:
tf.plan(output = True, tf_vars = { "pep_spec": "{\"pep1\"=\"test\"}" })
and that:
tf.plan(output = True, tf_vars = { "pep_spec": "{\"pep1\":\"test\"}" })
but that is unusable.

It looks like a super small problem. Could it be fixed ASAP?

@MrImpossibru
Copy link
Contributor Author

Since I can't just easily create a Pull request I'll write the change down:
Lines 147-149 of the tftest.py:
cmd_args += list(itertools.chain.from_iterable( ("-var", "{}={}".format(k, json.dumps(v) if isinstance(v, (dict, list)) else v)) for k, v in tf_vars.items() ))

Terraform documentation about that - https://developer.hashicorp.com/terraform/language/values/variables#variables-on-the-command-line

@ludoo @marshall7m could you please take a look? Thanks

@ludoo
Copy link
Collaborator

ludoo commented Jan 20, 2023

Thanks for this, I did not have time to check this issue yet. Let me have a proper look today. :)

@ludoo
Copy link
Collaborator

ludoo commented Jan 20, 2023

So, usage in your case should be:

tf.plan(output = True, pep_spec='{ "pep1": "test" }')

Just pass in one variable at a time as a string. You can check our Fabric repo's tests for examples on how to do that.

I am going to close this, feel free to reopen if the above is unclear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants