Any way of passing command
to local-exec
provisioner as array,
instead of a really long string?
provisioner "local-exec" {
command = "knife solo bootstrap -N ${self.name} -j '{\"mysql\": {\"server_root_password\": \"${var.mysql_root_password}\"}}' --no-berkshelf --no-host-key-verify -i ${var.pvt_key} -r ${var.run_list.db} ${var.remote_user}@${self.ipv4_address} | tee -a ${self.name}.log
}
Also, https://github.com/hashicorp/hcl/issues/34
If you agree, I can try and cook up a pull request.
Are you saying that you'd like the command to be specified as a list of raw arguments to execute rather than as a command string to run through the shell? Or are you asking for the ability to execute multiple commands each as its own list item?
Note that in the former case you wouldn't be able to do what you showed in your example because it is the shell that handles the |
syntax, creating multiple child processes and setting up their standard handles to make the pipe behavior work.
In the latter case I don't think it would make your example any shorter because you seem to only be running one command anyway.
So I think I'm not understanding what you're looking for. Can you share an example of what you expect your example would look like after your pull request were implemented?
Well, what I wanted to accomplish was something like this:
provisioner "local-exec" {
command = [
"knife solo bootstrap -N ${self.name}",
"-j '{\"mysql\": {\"server_root_password\": \"${var.mysql_root_password}\"}}'",
"--no-berkshelf --no-host-key-verify",
"-i ${var.pvt_key} -r ${var.run_list.db}",
"${var.remote_user}@${self.ipv4_address} | tee -a ${self.name}.log"
]
}
Basically, just a way to split this long command into something shorter and more readable.
As I said in hcl issue, any way to split / concatenate string will be fine,
but array command seems like easiest way to implement it.
Pipe was there just copy/pasted from actual command and is not really important for my use case.
Oh okay... so you just want to have the provisioner take the array and join it on spaces to make a string, to avoid having a really long line.
There is another syntax in Terraform to allow multi-line strings:
provisioner "local-exec" {
command = <<EOT
knife solo bootstrap -N ${self.name}
-j '{"mysql": {"server_root_password": "${var.mysql_root_password}"}}'
--no-berkshelf
--no-host-key-verify
-i ${var.pvt_key}
-r ${var.run_list.db}
${var.remote_user}@${self.ipv4_address}
| tee -a ${self.name}.log
EOT
}
(I didn't actually test the above so maybe I didn't nail the syntax quite right, but you can see a further example the heredoc syntax in the aws_iam_user_policy
example.)
I worry that making the command an array would be confusing for users that have a relatively-simple command and don't understand why it isn't just a string, or those who might confuse it for a list of separate commands to run.
Yeah, this seems like it should work.
I couldn't find anything regarding heredocs in docs or tests for neither hcl or terraform,
so I thought it's not supported.
Thanks
it doesn't work on windows (multiple commands)
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Oh okay... so you just want to have the provisioner take the array and join it on spaces to make a string, to avoid having a really long line.
There is another syntax in Terraform to allow multi-line strings:
(I didn't actually test the above so maybe I didn't nail the syntax quite right, but you can see a further example the heredoc syntax in the
aws_iam_user_policy
example.)I worry that making the command an array would be confusing for users that have a relatively-simple command and don't understand why it isn't just a string, or those who might confuse it for a list of separate commands to run.