diff --git a/website/source/docs/templates/user-variables.html.md b/website/source/docs/templates/user-variables.html.md index ae11b00bf..dfc26728a 100644 --- a/website/source/docs/templates/user-variables.html.md +++ b/website/source/docs/templates/user-variables.html.md @@ -90,6 +90,10 @@ only within default values for user variables, user variables remain as the single source of input to a template that a user can easily discover using `packer inspect`. +-> **Why can't I use `~` for home variable?** `~` is an special variable +that is evaluated by shell during a variable expansion. As packer doesn't run +inside a shell, it won't expand `~`. + ## Setting Variables Now that we covered how to define and use variables within a template, the next @@ -162,3 +166,24 @@ provisioner only run if the `do_nexpose_scan` variable is non-empty. "command": "if [ ! -z \"{{user `do_nexpose_scan`}}\" ]; then python -u trigger_nexpose_scan.py; fi" } ``` + +## Using HOME Variable + +In order to use `$HOME` variable, you can create a `home` variable in packer: + +``` {.javascript} +"variables" { + "home": "{{env `HOME`}}" +} +``` + +And this will be available to be used in the rest of the template, ie: + +``` {.javascript} +{ + "builders": [{ + "type":"google", + "account_file": "{{ user `home` }}/.secrets/gcp-{{ user `env` }}.json" + }] +} +```