From 042f4b7bfb82329726f36c54b761feff9ac23c47 Mon Sep 17 00:00:00 2001 From: Matthew Hooker Date: Wed, 9 Nov 2016 16:05:52 -0800 Subject: [PATCH] fix documentation wrt command line variables. --- .../docs/templates/user-variables.html.md | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/website/source/docs/templates/user-variables.html.md b/website/source/docs/templates/user-variables.html.md index 69a6b08bc..d2a634b88 100644 --- a/website/source/docs/templates/user-variables.html.md +++ b/website/source/docs/templates/user-variables.html.md @@ -118,10 +118,6 @@ As you can see, the `-var` flag can be specified multiple times in order to set multiple variables. Also, variables set later on the command-line override earlier set variables if it has already been set. -Finally, variables set from the command-line override all other methods of -setting variables. So if you specify a variable in a file (the next method -shown), you can override it using the command-line. - ### From a File Variables can also be set from an external JSON file. The `-var-file` flag reads @@ -147,8 +143,24 @@ The `-var-file` flag can be specified multiple times and variables from multiple files will be read and applied. As you'd expect, variables read from files specified later override a variable set earlier if it has already been set. -And as mentioned above, no matter where a `-var-file` is specified, a `-var` -flag on the command line will always override any variables from a file. +Combining the the -var and -var-file flags together also works how you'd +expect. Flags set later in the command override flags set earlier. So, for +example, in the following command with the above variables.json file: + +``` {.text} +$ packer build \ + -var 'aws_access_key=bar' \ + -var-file=variables.json \ + -var 'aws_secret_key=baz' \ + template.json +``` + +results in the following variables: + +| Variable | Value | +| --- | --- | +| aws_access_key | foo | +| aws_secret_key | baz | # Recipes