beelit94 / python-terraform

MIT License
475 stars 171 forks source link

Apply plan file? #67

Open rojopolis opened 5 years ago

rojopolis commented 5 years ago

Sorry if this has been discussed, I didn't find anything in the archive... I'm attempting to apply a plan created in a previous step using this python-terraform, however, it seems that all command always include a -var-file argument which prevents apply from accepting a plan file:

Error: Can't set variables when applying a saved plan
The -var and -var-file options cannot be used when applying a saved plan file,
because a saved plan includes the variable values that were set when it was
created.

Is there a way to override this behavior?

Spikeophant commented 5 years ago

I can't think of one offhand, I have hit this issue at work as well. I worked around it by not passing a saved plan in for what I was doing that was acceptable.

szaher commented 5 years ago

I having the same issue with terraform 0.12 @Spikeophant I have tried the workaround, it didn't work with me. The problem is generate_cmd function is always returning a variables file even if there are no variables and this is not accepted by terraform 0.12

Spikeophant commented 5 years ago

Hmm my tests aren't failing around that on my box with TF 0.12.12 on it. I will take another look at this, I have a few days off work and am planning on cutting a fresh release, I'll add this to the list of issues I want to take care of.

szaher commented 5 years ago

Can you guys provided how did you run it without providing a saved plan ? Still doesn't work with me on tf 0.12.12

Spikeophant commented 5 years ago

tf = Terraform(working_dir='.')

you could have logic here to run and check a plan.

tf.apply(capture_output=False, input=False, skip_plan=True)

abstein2 commented 5 years ago

As a temporary workaround, if you add var=None to your apply command, it bypasses the issue. For example:

tf.plan(out="init.tfplan")
tf.apply("init.tfplan", var=None)

Tested with Terraform v0.12.12

https://github.com/beelit94/python-terraform/blob/bda8b97e596138cbfbbe4c373b8524a705df626e/python_terraform/__init__.py#L232-L235 Since value is being set to None, it jumps over the creation of the var-file.

Thanks for all your hard work on the project so far!

Spikeophant commented 5 years ago

I am pulling this in as a bug to be fixed for the next release, which should be towards the end of this month, I fixed the tests for 0.12 so I can start actually doing bug work and have some confidence I didn't break everything. I am also planning to drop support for under tf 0.12 with the next release, just FYI. I'm also going to start managing the backlog of bugs with milestones so there's visibility into what's going on and it would be easier for others to contribute.

arkrishna1986 commented 3 years ago

Hi @Spikeophant This issue still exists and not been addressed yet....I tried lot of options earlier and atlast found this issue...:) Can you please update if this issue can be fixed or not..??

one more query: 1)Do you have support for Linode Cloud provider in this repo??if not,Can you please guide me how i can add linode support here...

Regards Ram