Provider Terraform Plan to Apply Step

Is there a way to provide the Terraform plan output file to a Terraform apply step? Currently we have a plan step and apply step, but the apply step does plan/apply instead of referencing a generate plan file which is more desirable.

Hey @Kyle.Engibous - this is possible using the customized parameters for the Terraform steps. The main caveat is that you’ll need to ensure that your steps run from the same location, so they can use the correct output file (or use some sort of shared storage to help with this aspect)

Here’s a small sample -

Using a dead simple

terraform {
  required_version = ">= 0.12.26"

output "hello_world" {
  value = "Hello, World!"

Here’s the important bits on my set up of the Plan step - the --out=/tmp/tfplan.#{Octopus.Release.Number} configuration will allow it to save to the worker the step is running on, and the Octopus System Variable helps keep it in sync with the releases (note any re-releases will overwrite the existing saved plan file, so a deployment based variable might be a bit better here):

Here’s the saved plans from my testing:

Finally, here’s the setup for the Apply step. One quick note, I set the template source to be “Source code” to show that it is using the plan to grab the output variable for this step:

And finally, here’s the task output so you can see that it grabbed the plan as intended (note the black highlighted lines for the executed commands):

Hopefully that helps, let me know if you have any questions or run into any issues!

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.