question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Init vars escape issue

See original GitHub issue

When backend-config is passed to a subprocess with init_vars it is not properly escaped. Example

import tftest
import logging

logging.basicConfig(level=logging.DEBUG)


if __name__ == "__main__":
    tf = tftest.TerraformTest('.', None, "terraform")
    backend_config = {
        "bucket": "bucket_name",
        "key": "dummy.tfstate",
        "region": "us-east-1",
    }
    tf.setup(init_vars=backend_config, cleanup_on_exit=False)

Output

DEBUG:tftest:['init', ('-no-color', '-input=false', "-backend-config='bucket=bucket_name'", "-backend-config='key=dummy.tfstate'", "-backend-config='region=us-east-1'")]
CRITICAL:tftest:Error running command init: 1 Initializing modules...
Downloading git::ssh://...
...


Initializing the backend...

Error: Invalid backend configuration argument

The backend configuration argument "'bucket" given on the command line is not
expected for the selected backend type.


Error: Invalid backend configuration argument

The backend configuration argument "'key" given on the command line is not
expected for the selected backend type.


Error: Invalid backend configuration argument

The backend configuration argument "'region" given on the command line is not
expected for the selected backend type.


Traceback (most recent call last):
  File "pr.py", line 14, in <module>
    tf.setup(init_vars=backend_config, cleanup_on_exit=False)
  File "/Users/vtk/.virtualenvs/qa/lib/python3.7/site-packages/tftest.py", line 309, in setup
    return self.init(plugin_dir=plugin_dir, init_vars=init_vars, backend=backend)
  File "/Users/vtk/.virtualenvs/qa/lib/python3.7/site-packages/tftest.py", line 317, in init
    return self.execute_command('init', *cmd_args).out
  File "/Users/vtk/.virtualenvs/qa/lib/python3.7/site-packages/tftest.py", line 397, in execute_command
    raise TerraformTestError(message)
tftest.TerraformTestError: Error running command init: 1 Initializing modules...
Downloading git::ssh://...
...

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
ludoocommented, Nov 26, 2020

Released as v1.5.4 can you test it and see if the issue is fixed?

https://pypi.org/project/tftest/1.5.4/

0reactions
ludoocommented, Jun 22, 2022

Hello - looks like this is a bug when using gcs as the backend as well. I’ve had to remove the quotes.

You mean we should reopen this? Can you provide a simple repro?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with escaping variables - Terraform - HashiCorp Discuss
I am using vRA provider in my TF code and passing several variables via bash command line, these variables will then be passed...
Read more >
escaping closure captures mutating 'self' parameter" in init()?
As the error said, in the escaping closure, you're capturing and mutating self (actually self.toggle ). This is not allowed. Even if you...
Read more >
bash - Escape a variable for use as content of another script
I couldn't find any related question that isn't about how to escape variables for direct consumption within a script or by other programs....
Read more >
Cannot use $ character in build variables (#17069) - GitLab
Having users aware that they need to escape the $ with static warning message, or some dynamic way only if $ is detected...
Read more >
Do not escape > within a bash variable - Stack Overflow
Storing Bash code in variables is a recipe for (un)escaping bugs. Not to mention how dramatically the script's behavior can change due to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found