python-terraform icon indicating copy to clipboard operation
python-terraform copied to clipboard

auto-approve parameter is overwritten.

Open msmaryrussell opened this issue 4 years ago • 6 comments

The apply function in init.py seems to overwrite auto-approve. I have made a local change in my copy of the code and it works by first checking if auto-approve has been set

I've added the if statement before the if not default['auto-approve']: default['auto-approve'] = (skip_plan == True)

I would like to contribute this fix if possible but starting with opening the issue - already mentioned in an issue opened in 2018 "Terraform ignore -auto-approve=True"

msmaryrussell avatar Apr 21 '20 14:04 msmaryrussell

yes for me while using executing terraform from windows when i use terraform apply functioni am getting " flag provided but not defined: -auto-approve " error.

narasimha18sv avatar May 05 '20 18:05 narasimha18sv

Yes this does happen, I will look at a fix.

Spikeophant avatar May 05 '20 18:05 Spikeophant

I will address this in the rewrite I am going to do soon. If you'd like to help with the rewrite, or even planning for the rewrite let me know.

Spikeophant avatar May 13 '20 16:05 Spikeophant

yes definitely I can help. Please let me know how we can collaborate.

narasimha18sv avatar May 14 '20 11:05 narasimha18sv

It seems like providing the variable skip_plan will do the same thing. Correct?

It doesn't actually seem to skip the plan, but instead sets the auto-approve variable accordingly.

kingsleyadam avatar Jun 24 '20 15:06 kingsleyadam

First of all, thanks for this tool.

It seems I've been bitten by this bug too:

Code snippet:

apply_rc, apply_stdout, apply_stderr = tf_apply.apply(
	no_color = IsNotFlagged,
	auto_approve  = IsFlagged,
)

...results in (as per ps -ef): terraform apply -var-file=/tmp/tmpxwdl2e2y.tfvars.json -input=false -auto-approve -auto-approve=false

OTOH, if I don't provide the auto_approve flag, that is:

apply_rc, apply_stdout, apply_stderr = tf_apply.apply(
	no_color = IsNotFlagged,
)

then ps shows: terraform apply -var-file=/tmp/tmpq_m51ld9.tfvars.json -input=false -auto-approve=false.

It seems -auto-approve=false is forcibly introduced by python_terraform code. Also notice that -auto-approve is a flag on Terraform 1.5.5, so it should be just -auto-approve instead of -auto-approve=[true|false].

NOTE: The following options did terraform apply as intended:

  • Using apply method:
apply_rc, apply_stdout, apply_stderr = tf_apply.apply(
	no_color = IsNotFlagged,
	skip_plan = True,
	capture_output = True,
)

this turned into terraform apply -var-file=/tmp/tmp3972qoeq.tfvars.json -input=false -auto-approve=true

Testing right with terraform, it results that both -auto-approve and -auto-approve=[true|false] do the same thing (-auto-approve being equivalent to -auto-approve=true).

  • Using cmd method: This below also works as expected (terraform apply -auto-approve):
apply_rc, apply_stdout, apply_stderr = tf_apply.cmd(
	'apply',
	'-auto-approve',
	capture_output = True,
)

Also, this seems related to #45.

next-jesusmanuelnavarro avatar Apr 08 '24 07:04 next-jesusmanuelnavarro