Hi @brianpham thanks for reaching out. The use of environment variables with HCL can be a little tricky because they are referenced differently from what they are named. More specifically, the PKR_VAR prefix is needed to tell Packer that it is an environment variable it should know about, but when you reference the variable you have to drop the PKR_VAR prefix. Below is an example HCL file to illustrate the usage.
Please let me know if this helps you move forward with the build or if you have any other questions. In the meantime, I’ll see about adding a few more examples to the HCL variables documentation. Cheers!
It would be really nice to have the ‘env’ functionality back in HCL2. having to pass environment variables this way is a pain and the idea of storing things like secrets in flat text files isn’t great, especially when you’re using AWS STS. It reminds me of early Terraform with TF_VAR for your creds before it supported AWS_PROFILE.
Hi @SwampDragons.
Could you tell me, Is it possible at this moment to use ‘env’ function with the default value (if env var is absent)? Can env var have another than PKR_VAR_<SOME_VAR> to override the default value in the hcl file?
Many thanks in advance.