When running command line tools like Terraform it's important to be aware of which command line interpreters and other layers your command will pass through on the way to the command you are eventually running.
On a Unix system like Linux or Mac OS X your command line will typically be interpreted by a shell like bash
or zsh
. Unix-style shells follow the convention that the '
character marks sequences of characters to be interpreted totally literally, and so with a command line substring like -var='foo=bar baz'
the shell will be the one to handle those '
, removing them in the process, causing the final argument sent to the program to be -var=foo=bar baz
, which happens to be the syntax that Terraform expects for this argument and so it works.
Unfortunately on Windows the conventions are rather different. Your command lines might be handled by the Windows command interpreter (cmd.exe
) or by some other interpreter like PowerShell. Each has its own conventions for processing a command line, which means the same command line can be interpreted differently depending on which interpreter you are using.
For running Terraform I would suggest ensuring that you are using the Windows command interpreter if possible, because its command line processing rules are relatively simple: it doesn't interpret quote marks at all and just passes the full command line arguments into the program as a single string. However, that does mean that on Windows a command line like -var='foo=bar baz'
will pass to Terraform written exactly like that, with the '
quotes still present, and thus command line parsing will fail.
Terraform on Windows follows the typical command line parsing conventions used by software written in C or using the Windows API function that parses command lines, and part of those conventions is the use of "
to indicate sequences of characters where spaces should be taken literally, and so when running Terraform on Windows using the Windows command interpreter you need to enclose literal sequences of characters in "
and then escape any literal "
characters with a backslash, giving something like this:
-var="ips=[\"123.456.111\",\"123.456.222\"]"
Since you intend to populate this from a variable in your automation tool, this will only work if that automation tool has a mode where it'll automatically escape quote marks with a backslash, otherwise the result won't be valid.
Dealing with all of the different layers of parsing on a templated command line like this can be pretty messy, so it's often easier to instead place the variable values in a .tfvars
file and then pass the filename on the command line. In that case Terraform will parse the contents of that file directly, without any interference from command line interpreters, and so you only need to deal with Terraform's own language and not the extra layered shell languages on top.
ips
is not declared in the root module, not that it's passed incorrectly. How does your (root) module look like? More importantly how does yourvariables.tf
in there look like and does it have a correct declaration ofips
? Looking at the error message I guess not. – yvesonlineinfrastructure/terraform/dev
? You set a working directory in the task definition so that'll be treated as the main module. It looks like this is a module for a specific stage/environment. But I'm only guessing and people on SO can't help further without seeing the actual Terraform code ininfrastructure/terraform
. – yvesonline