Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • nimrod/tf
1 result
Select Git revision
Show changes
Commits on Source (2)
......@@ -52,10 +52,10 @@ end with :code:`.tfvars`, a :code:`-var-file` argument is added. For example:
:code:`-var-file=prod/a.tfvars` and :code:`-var-file=prod/b.tfvars`.
By default :code:`tf` invokes :code:`terraform`, but if you're using a
different tool (like `OpenTofu <https://opentofu.org/>`_ you can set the
:code:`TF_CLI` environment variable to that tool name. If you wish to know the
exact command :code:`tf` is running set the :code:`TF_DEBUG` environment
variable to :code:`1` and the command will printed before the it's invoked.
different tool (like `OpenTofu <https://opentofu.org/>`_) you can set the
:code:`TF_CLI` environment variable to that tool's name. If you wish to know
the exact command :code:`tf` is running set the :code:`TF_DEBUG` environment
variable to :code:`1` and the command will printed before it's invoked.
License
-------
......
......@@ -83,6 +83,23 @@ def wrapper():
print(f"Can't find {TF_CLI}.", file=sys.stderr)
sys.exit(1)
# We can't add -var-file to an apply command with a plan. So we check all
# of the args after the apply arg and if all of them are switches we assume
# that a plan isn't specified (technically the plan file can also start
# with a "-" and look like a switch, but let's not go there).
if command == "apply":
apply_index = sys.argv.index("apply")
if not all(
map(lambda x: x.startswith("-"), sys.argv[apply_index + 1 :])
):
# No all args are switches, so a plan is specified and we don't add
# the -var-file switch.
try:
os.execvp(TF_CLI, args) # nosec
except FileNotFoundError:
print(f"Can't find {TF_CLI}.", file=sys.stderr)
sys.exit(1)
# We need to add the var files after the Terraform command (if we add it
# before Terraform doesn't accept them) but not at the end (not to modify
# other argument that accept optional values). So we add them right after
......