How can I use Octopus variable substitution for a list object variable in my Terraform Script?

Using Octopus variable substitution for a “list” variable in your Terraform Script can be accomplished in multiple ways. The key, however, is to properly manage the variable syntax in your modules.

For the examples below, we have a list of valid DNS servers that we have assigned to an Octopus variable named 'dns.servers.’

If you are declaring and defining your variables in the root module of your configuration, you can use your Octopus variable directly in the default value. Note the location of the square brackets.

The second (more flexible) way to accomplish this is by the use of a .tfvars file. In the module where your variable will be used, define the type as a “list.”

Create a variable definitions file with a filename ending in .tfvars. This file will contain only variable name assignments. Add your variable name (that you declared in your module) and the corresponding Octopus variable into this file.

Note: In the two examples below, square brackets may be added in either your .tfvars file or in your .tf file.

The .tfvars file can be specified in the “Custom terraform apply parameters” section of your “Apply a Terraform Template” step using “-var-file=myvars.tfvars"