Packer variables

28 views
Skip to first unread message

Christopher Campbell

unread,
Nov 8, 2019, 3:39:06 PM11/8/19
to Packer
Hi all, wanted to see if there is an easy way to use variables in powershell provisioner.

currently i have variable declared as the following and want to replace the [[key]] to be the variable but i am unable to find any examples on how to do this.

"variables":{
 "key_info": "1234567890"
}


      "type": "powershell",
      "inline": [
        
        "Start-Process -FilePath \"C:\\atmp\\vs_enterprise.exe\" -ArgumentList \"--add Microsoft.VisualStudio.Workload.Azure --productKey [[key]] --quiet\" -NoNewWindow -Wait"


      ]
    },



Sean Nolan

unread,
Nov 10, 2019, 11:53:42 PM11/10/19
to Packer
The value you put in the variables block is just a default, you can pass a value for the variable when you run the packer build. You can pass values on the command line with the var flag or put them in a file and refer to the file with the var-file flag on the command line.

Then in your template code you use the variable values with the user function {{user `varable`}}, so the line in your template code would be

"Start-Process -FilePath \"C:\\atmp\\vs_enterprise.exe\" -ArgumentList \"--add Microsoft.VisualStudio.Workload.Azure --productKey {{user `key_info`}} --quiet\" -NoNewWindow -Wait"

This is all explained in the documentation here:
Reply all
Reply to author
Forward
0 new messages