Terraform - Nuget package directory variable

Hi,

In one of our Octopus builds we’ve got a step where official Terraform template is used.
In documentation I found that we may override terraform.exe file which is used by Octopus by setting “Octopus.Action.Terraform.CustomTerraformExecutable” to absolute path of the file.

My plan is to include terraform.exe file as part of Nuget package, however, I couldn’t find any variable where Nuget package will be unpackged onto Octopus server.

Is there any variable on Terraform Plan/Apply/Destroy steps for Nuget package location, i.e. “C:/Octopus/[auto_generated_timestamp]/” ?

Thanks,
Mat

Hi,

Thanks for getting in touch.

To see where a package was installed to, assuming you are using Custom Deployment Scripts in the package step itself, you could use Octopus.Action.Package.InstallationDirectoryPath

E.g.

Write-host "Installed to $($OctopusParameters["Octopus.Action.Package.InstallationDirectoryPath"])"

Here is a list of possible system variables available.

If you wanted to run the “Deploy a Package” step then have another step that references that package location later in your deployment process, you could use an output variable to reference that earlier step.

E.g.

Octopus.Action[_EarlierStepNameHere_].Output.Package.InstallationDirectoryPath

In your case, you could deploy your package (that contains your version of terraform.exe), then use that variable above to reference the path to the deployed package.

You could also use a Custom Installation Directory on your package step so you can predict where the package will be deployed to. That should then be available via the Octopus.Action.Package.CustomInstallationDirectory system variable (see this in the system variables link above).

Hope this helps. Let me know how you go.

Cheers
Mark

Hi Mark,

Thank you for your help.

Unfortunately I’m not using Custom Deployment Scripts but Terraform Deployments.

I would like to override Octopus.Action.Terraform.CustomTerraformExecutable which requires absolute path to “terraform.exe” file which is included in the nuget package.

It doesn’t seems to work with InstallationDirectoryPath, however, as a next step I’ll try to use Powershell step to deploy my Nuget Package into separate folder and use that folder as a parameter for Octopus.Action.Terraform.CustomTerraformExecutable.

I’ll let you know if that works.

Thanks,
Mateusz

PS: is there any chance to see source code for Terraform Deployments steps or Run a script step?

Hi Mateusz,

Ah sorry, yes that makes sense now. Hopefully it’s not too inconvenient to have a separate deploy package step then reference the location via the output variable.

Regarding our source code, the command-line tool that’s invoked by Tentacle (or Server) during a deployment is called Calamari and is available publicly if you’d like to check it out.

However in the case of Terraform, I believe Octopus (or the worker) will simply call terraform.exe with the arguments directly. I.e. The Octopus UI sets a bunch of properties on the step/action. During a deployment, we have action handlers in C# that respond to this particular “terraform apply” action and we build up a command (and arguments) to execute this terraform.exe apply... command via PowerShell.

Our Octopus source code is private/closed source, but we have provided source-code licenses for enterprise customers. If you’re an enterprise customer and would like me to chase this up, please let me know.

In regards to the variables, I’m not sure if this will help, but to see a list of possible variables that are available during a deployment, you can enable variable logging and then checkout the verbose logs on the task log. This may give some insights about the package variables you can reference.

Cheers
Mark

Hi Mark,

Thank you for your message.

I managed to sort it out by including additional script execution step just before Terraform Deployment steps. Inside of it I’m just copying terraform.exe file to static location (C:/terraform/terraform.exe) which is set on " Octopus.Action.Terraform.CustomTerraformExecutable"

My build process looks like that:
image

Thank you for your help.

Mat

Mateusz, your solution was really helpful but I wish it included the script content you used to copy the file within “Update terraform.exe”.