Is there way of linking the steps to ensure that the same package is use between them?
My example is I have a terraform package I would like to have a log of the plan before applying the template. So I am using the Plan step then Apply step. When I come to create a release I have the ability for the plan step to pick a different version to the apply.
Any advice on how to ensure that my deployer users can only select 1 version of my terraform package for the the 2 steps?
Hi @sj.wright, thanks for reaching out.
I just want to clarify the issue you are facing. It sounds like you have a single project with both Terraform plan and apply steps, and creating the release potentially means selecting different package versions like in the screenshot below?
If that is the case then unfortunately there is no easy way in Octopus to force packages between steps to be the same.
One solution may be to use a a plain script step with a package reference as documented at https://octopus.com/blog/script-step-packages. The single package reference would include your terraform templates, and you would call the terraform executable yourself to do the plan and apply.
You could also write a script step to run at the start of the process to verify that the packages have the same versions. The
Octopus.Action.Package.PackageVersion variable is defined for each step e.g.
Octopus.Action[Terraform Plan Step].Package.PackageVersion and
Octopus.Action[Terraform Package Step].Package.PackageVersion. If these variables are not the same, an error can be thrown and the deployment will not progress.
As a note, turning on variable debugging (documented at https://octopus.com/docs/support/how-to-turn-on-variable-logging-and-export-the-task-log) will show you the available variables in the Octopus task logs.
Finally if your Terraform templates can be represented as a single combined file, a script step with an additional package reference could be used to extract the Terraform package, read the content of the file to an output variable (this is documented at https://octopus.com/docs/projects/variables/output-variables), and the output variable could be referenced in the Terraform script step. And example of what this looks like is shown below:
Thank you for your reply. The screenshot is the problem that I would like avoid where a single project with we 2 steps needing to use same package, but could end-up using the 2 different ones.
Thanks for the advice, I think the best option will be to have a template that will create plan and then apply.
Would it possible to add option on the terraform apply to output a plan first before running the apply?
This will solve the problem that I would like to resolve which is have a clear view of what the apply is going to do.
Hi Steve, sorry for the late reply.
The issue you have described has been raised a few times in the past, and it does make sense to provide a more first class solution. Unfortunately this is not a feature that is on our roadmap, so the workaround is the best solution today.