Closed karelorigin closed 3 weeks ago
Unfortunately there is currently no support for complex data types – only strings. You could convert it to a JSON in Terraform using jsonencode
and decode it in Packer using jsondecode
.
I might implement this in the future, though.
Ah, I see. I figured it was due to some kind of type conversion limitation. The jsonencode/decode solution should do the trick for now :)
Just for the record: Currently variables are passed to Packer using the -var
command line parameter. I'm considering changing this and implement it the following way:
/tmp
or %USERPROFILE%/AppData/Local/Tmp
) with all variables-var-file
parameter to use that JSON fileThis has multiple advantages:
Hi @simaotwx,
Thanks for the update. I always thought this provider simply imported Packer as a library rather than calling it externally. Is that not possible? And if so, wouldn't that make temporary files unnecessary?
Hi @karelorigin it does import Packer, however currently it only invokes the Main function, passing the command line parameters as an array to said Main function. To isolate the address space (heap and stack) as well as the environment, the provider is invoked as a program in "Packer mode", effectively acting as if it was the Packer binary itself. That was the easiest and most straightforward way to embed Packer without many modifications, however, I'd be happy to explore better options.
Personally, I'm relying on Terraform Cloud to manage TF state and it doesn't seem very fond of files on disk (even in the tmp directory). I've even created my own provider to work around it, so I think anything relying on too many local sources is likely to break.
That's a good point. We use Terraform Cloud, too, and I don't know how /tmp behaves there. Complex data types can also be passed on the command line but I fear that it would cause issues related to the command line length and encoding.
Could this not be implemented using the https://github.com/hashicorp/terraform-plugin-sdk/issues/248 DynamicPseudoType and then just quote the var passed to packer e.g. -var 'list=["foo". "bar"]'
Will attempt to implement this using DynamicPseudoType
in the next round of updates.
I have implemented partial support for this in the 0.16.0 release. Please let me know if it's enough to support your use case.
Version 0.16.0 supports string lists as this issue asks for. I'm going to close this issue for that reason.
results in