Terraform -chdir

Would like to use Octopus to deploy Terraform configs. Currently our terraform configs are structured like this:
-Modules

  • Dev
  • QA
  • Prod
    The Env directories have the terraform backend config for the relevant environment.
    We run terraform as “Terraform -chdir=QA plan -var-file=“QA.tfvars””.
    Using Octopus is there a way I can use -chdir=QA ?

Hi Dominic,

Thanks for your question. From what I can tell, there does not appear to be a way to define a command line parameter before the terraform subcommand (plan in this case). I think you have a couple options though. If you are bundling your terraform config into a package (which I assume that you are because you’re mentioning files/directories), and if the environments in your Octopus instance match the names of the directories you mentioned above (Dev, QA, Prod), then you could use the parameter in the package section to reference the Octopus built in variable #{Octopus.Environment.Name}. For example:

If however, your Octopus environment names don’t match the path names in your package, and you can’t change that, I think as a last resort you could always fall back and use a more primitive step template like the Run a Script step template. Here you could simulate what the built in step template does and define whatever parameters you need. Of course you would still need some dynamic way to refer to your path-based environments.

Hope this helps.

Phil