{"id":15481536,"url":"https://github.com/mikeschinkel/packer-vars","last_synced_at":"2026-03-15T12:07:32.300Z","repository":{"id":62676579,"uuid":"561614478","full_name":"mikeschinkel/packer-vars","owner":"mikeschinkel","description":"Repo to illustrate a pain when using HashiCorp's Packer for at least one use-case","archived":false,"fork":false,"pushed_at":"2022-11-04T05:34:08.000Z","size":13,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"working","last_synced_at":"2025-10-10T14:28:24.265Z","etag":null,"topics":["packer","packer-builder","packer-template","packer-templates","warnings"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikeschinkel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-11-04T04:32:34.000Z","updated_at":"2025-05-12T19:51:11.000Z","dependencies_parsed_at":"2022-11-04T10:00:54.916Z","dependency_job_id":null,"html_url":"https://github.com/mikeschinkel/packer-vars","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mikeschinkel/packer-vars","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeschinkel%2Fpacker-vars","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeschinkel%2Fpacker-vars/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeschinkel%2Fpacker-vars/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeschinkel%2Fpacker-vars/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikeschinkel","download_url":"https://codeload.github.com/mikeschinkel/packer-vars/tar.gz/refs/heads/working","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikeschinkel%2Fpacker-vars/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28002253,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-24T02:00:07.193Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["packer","packer-builder","packer-template","packer-templates","warnings"],"created_at":"2024-10-02T05:04:48.196Z","updated_at":"2025-12-24T12:15:43.761Z","avatar_url":"https://github.com/mikeschinkel.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Packer Vars Example \n\n## Or, why does it have to be this hard?\n\nThis repo was created to provide an example to illustrate my comments on this Github issue for @nywilken who so graciously offered to understand the use-case and possibly even address the difficulty of my use-case.\n\n## Use-case\nBasically the use-case did the following, **each with its own `.pkr.hcl` file**. This process assumes an 'ova-builder` VM on VMware vCenter that will have been created by a different Packer template.\n\n| Step      | Description                                                                  |\n|-----------|------------------------------------------------------------------------------|\n| `setup`   | Ensures the 'ova-builder` VM is running and the vCenter has required config. |\n| `clean`   | Ensures the VM is in a clean state, e.g. prior artifacts deleted.            |\n| `app`     | Build a GoLang app on the VM.                                                |\n| `iso`     | Builds a Linux ISO containing the GoLang App.                                |\n| `upload`  | Uploads the build ISO to a vCenter Datastore.                                |\n| `install` | Installs the ISO to create a new 'App' VM on vCenter.                        |\n| `export`  | Exports the App VM back down to 'ova-builder' as an OVA file.                |\n| `jfrog`   | Uploads the resulant OVA to jFrog Artifactory.                               |\n\n\nThe above is even a simplification but is hopefully detailed enough to give a clear picture of the process.\n\n## Example\nAside from the code being proprietary and owned by a former client it would be far too complex to serve as a clarifying example, so I create the simplest example I could to illustrate the problem.\n\nThis example has two (2) steps: `step1` and `step2` and their respective Packer templates are `./step1/step1.pkr.hcl` and `./step2/step2.pkr.hcl`.  The example also has a shared `/vars.json` which contains shared vars for logging into SSH and one var for each step, `step1_var=foo` and `step2_var=bar`, respectively. \n\nAll these steps do is they both use the null builder to reach into a Linux machine via SSH and then run an inline script echoing their variable's value.\n\n### Running the working example\nTo see this example work:\n\n1. Make sure you have Packer installed _(of course)_,\n2. Clone this repo to a macOS or Linux machine.\n3. Ensure you are in the `working` branch, which is the repo's default.\n4. Change the `ssh_*` properties in `./vars.json` to point to a host, user and password of a computer or VM you can SSH into, and then  \n4. Run `make`\n\n\n## The Problem\nThe problem is that Packer requires you to declare `step2_var` in `./step1/step1.pkr.hcl` even though /step1/step1.pkr.hcl` never references or otherwise uses `step2_var`, — as the following table illustrates:\n\n| Step    | Packer Template         | Template Uses\u003cbr\u003eproperty in\u003cbr\u003e`./vars.json` | Template does\u003cbr\u003eNOT use: |           \n|---------|-------------------------|-----------------------------------------------|---------------------------|\n| `step1` | `./step1/step1.pkr.hcl` | `step1_var=foo`                               | `step2_var`               |\n| `step2` | `./step2/step2.pkr.hcl` | `step2_var=bar`                               | `step1_var`               |\n\n\n### Running the \"warnings\" example\n\nTo experience the problem this repo is trying to illustrate:\n\n1. Make sure performed the steps for the `working` example first.\n2. Checkout the `warnings` branch.\n2. Run `make`\n\n\nYou should get the following output; notice the **warnings**:\n\n```\npacker build -force -var-file=\"./vars.json\" \"step1\"\nWarning: Undefined variable\n\nA \"step2_var\" variable was set but was not found in known variables. To declare\nvariable \"step2_var\", place this block in one of your .pkr files, such as\nvariables.pkr.hcl\n\n\nnull.step2: output will be in this color.\n\n==\u003e null.step2: Using SSH communicator to connect: iso-builder.local\n==\u003e null.step2: Waiting for SSH to become available...\n==\u003e null.step2: Connected to SSH!\n==\u003e null.step2: Provisioning with shell script: /var/folders/fg/1dfmwyrx3wxbhj5lbdqpt7bw0000gn/T/packer-shell1383820945\n    null.step2: We are running step 'foo'\nBuild 'null.step2' finished after 658 milliseconds 319 microseconds.\n\n==\u003e Wait completed after 658 milliseconds 394 microseconds\n\n==\u003e Builds finished. The artifacts of successful builds are:\n--\u003e null.step2: Did not export anything. This is the null builder\npacker build -force -var-file=\"./vars.json\" \"step2\"\nWarning: Undefined variable\n\nA \"step1_var\" variable was set but was not found in known variables. To declare\nvariable \"step1_var\", place this block in one of your .pkr files, such as\nvariables.pkr.hcl\n\n\nnull.step2: output will be in this color.\n\n==\u003e null.step2: Using SSH communicator to connect: iso-builder.local\n==\u003e null.step2: Waiting for SSH to become available...\n==\u003e null.step2: Connected to SSH!\n==\u003e null.step2: Provisioning with shell script: /var/folders/fg/1dfmwyrx3wxbhj5lbdqpt7bw0000gn/T/packer-shell2044896123\n    null.step2: We are running step 'bar'\nBuild 'null.step2' finished after 373 milliseconds 507 microseconds.\n\n==\u003e Wait completed after 373 milliseconds 568 microseconds\n\n==\u003e Builds finished. The artifacts of successful builds are:\n--\u003e null.step2: Did not export anything. This is the null builder\n\n```\n\n## The Desired Solution\n\nSimply provide a command-line switch that will suppress those warnings.\n\n## Epilogue\n\nI tested this in Packer `1.18.3` but I _swear_ that earlier versions of Packer threw errors and failed to buiild instead of throwing warnings. Or at least that is what I remember. \n\nSo a warning is not as bad as an error, and if it never threw an error and always provided a warning then, as they say, my bad. \n\nBut still, a command-line switch to suppress would be much appreciated.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikeschinkel%2Fpacker-vars","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikeschinkel%2Fpacker-vars","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikeschinkel%2Fpacker-vars/lists"}