Octopus Terraform - List Object Variable Replacement Issue

Hello Support,

Currently attempting to setup Octopus/NuGet integration using a ProGet server, as my package host. However I am at a loss in regards to how I need to configure the variable replacement for a ‘list’. When the replacement piece within Octopus attempts to replace the information with the Octopus variable within the resource, it does not remove the double quotes surrounding the variable.

As such it errors in relation to configuration and the object within the Terraform resource needing to be a list. Please reference the below screenshots and GitHub repository for more information.

FYI, this is a trial 30 day license so that I can vet out this solution and offer it as an option to individuals at my work place. Please reach out to me with additional questions/requirements, I’m most likely just doing this wrong.

GitHub Repostiory: https://github.com/Condoamanti/terraform/tree/octopus
Pastbin Logs:
Octopus Error Log - https://pastebin.com/Mi1ENM2i
Octopus Step Template - https://pastebin.com/NSNUDuYc

Octopus Error - https://imgur.com/a/eoiIZRW
Project Configuration - https://imgur.com/a/Pr2Ef6a
Variable Configuration - https://imgur.com/a/Um64WHc

Octopus Project Work Files From Server:
Virus Total Scan - https://www.virustotal.com/gui/file/06625118d6fa2d828ce00a35a4a5e698ab16ca945945a8bf4fff29eddfac47f9/details
UPLOADFILES Link - https://ufile.io/y49mo6l0

Please reference within the .ZIP file on line 82

Hi John

Thanks for getting in touch! Sorry for the delay in getting back to you.

Thanks also for passing through lots of details - it’s helped a lot in diagnosis.

On this line you’re telling Terraform that it’s a string by wrapping quotes around it:

      dns_server_list = "${var.vsphere_virtual_machine_dns_server_list}"

If you change this to:

      dns_server_list = ${var.vsphere_virtual_machine_dns_server_list}

You should be good.

Just checking, are you expecting to pass this variable in from Octopus? I would recommend using a tfvars files for your variable values - one with local test values, and one that has octopus variable replacements in it, that you can refer to from Octopus.

Let me know how this goes.


Hello Matt,

Thanks for getting back to me, so I currently am using Teamcity to do a terraform validation/ init/lint on the code after replacing ‘#{’ with ‘${var.’ which then verifies if the code is good or not at that level. From there I repull and create a package for octopus to use. Thank you for all our help!

Code on build agent - https://imgur.com/a/Vdyu26p
Screenshot of error Teamcity web- https://imgur.com/a/qJflyI3

Step3 of 5 Screenshot - https://imgur.com/a/WlOblRf
Step4 of 5 Screenshot - https://imgur.com/a/fQIPCWH

Pastebin Teamcity Error Raw - https://pastebin.com/ukjx9iFa

Hi John

To make sure I understand fully… If you wrap it in quotes, it works in teamcity with the init, but not in Octopus, but if you remove the quotes, it no longer works in teamcity?

I highly suspect you’ll have more luck with using .tfvars files to set the variables, and use the same template in both places.

Let me know how you go with that.


Hello Matt,

Unfortunately I am at a loss in regards to what you mean. For variable substitution to work from a Terraform file to octopus the variable ‘must’ be in #{variable} format matching an octopus variable. However if you have this within a file and attempt to run Terraform native on the file with the octopus variable, it is my understanding that it will fail due to syntax issues.

*PS … I just realized I could paste/attach images… so sorry for external linking to stuff.

Can you please provide a reference code subset for this scenario so that I can understand in more depth?
Step Template Replace Variables:

Diagram For Workflow:

Hi John,

Matt has gone on holidays, I’ll try to help you out.

I think Matt is suggesting the use of tfvar file for each environment where Terraform will be executed. Have an Octopus variable file that will contain the Octopus substitution syntax, and another file that has whatever syntax is required where it will run. You can apply the files individually: https://learn.hashicorp.com/terraform/getting-started/variables.html#from-a-file.

You can select the variable files to use in Octopus: https://octopus.com/docs/deployment-examples/terraform-deployments/apply-terraform#additional-variable-files.

I hope this helps steer you in the right direction.


Hello Shane,

Unfortunately I don’t believe this will work, as I need to validate /lint that the code is good via terraform before doing Octopus substitutions. I find it limiting that Octopus cannot manage ‘list’ objects for terraform correctly. Do you know if this is something that can be requested/voted on and if so, where do I submit this?

Thank you,

EDIT: I was able to get this to work, by modifying the file with teamcity, prior to packing/uploading the nuget file for octopus. This however is very hackish, and believe this is as stated a limitation in the octopus variable replacement. For a production environment, this is not sustainable/trusted as it is modifying the code after the validation step… please provide a link or way for me to submit a request for a fix/feature within octopus.

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