{"id":21134089,"url":"https://github.com/horgix/packer-builder-defaultconf","last_synced_at":"2026-06-29T19:31:40.523Z","repository":{"id":95051352,"uuid":"100058573","full_name":"Horgix/packer-builder-defaultconf","owner":"Horgix","description":"Repository used as a minimal example for Packer builder default configuration","archived":false,"fork":false,"pushed_at":"2017-08-21T12:04:56.000Z","size":7118,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-24T04:07:16.433Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Horgix.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-11T18:05:51.000Z","updated_at":"2017-08-21T12:01:01.000Z","dependencies_parsed_at":"2023-06-11T23:15:14.013Z","dependency_job_id":null,"html_url":"https://github.com/Horgix/packer-builder-defaultconf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Horgix/packer-builder-defaultconf","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Horgix%2Fpacker-builder-defaultconf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Horgix%2Fpacker-builder-defaultconf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Horgix%2Fpacker-builder-defaultconf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Horgix%2Fpacker-builder-defaultconf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Horgix","download_url":"https://codeload.github.com/Horgix/packer-builder-defaultconf/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Horgix%2Fpacker-builder-defaultconf/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34941025,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-29T02:00:05.398Z","response_time":58,"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":[],"created_at":"2024-11-20T06:23:06.993Z","updated_at":"2026-06-29T19:31:40.505Z","avatar_url":"https://github.com/Horgix.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Packer Builder - DefaultConf\n\n**This repository is no longer updated in any way since it was just a quick\ndemo for myself**\n\nThis repository intends to be used as a demo for a question I asked myself\nabout default configuration values for Packer plugins.\n\nThe main question is: **How to properly assign defaults to some configurations\nfields of a Packer Builder?**. This can, of course, probably be applied to\nother components such as provisionners and post-processors.\n\n## How to run this demo\n\n1. Setup requirements:\n\n```bash\nglide install\n```\n\n2. Go to either `defaultconf_preset` or `defaultconf_2` depending of which solution\n   you want to see/test:\n\n```bash\ncd defaultconf_preset/\n# OR\ncd defaultconf_postcmp/\n```\n\n3. Build:\n\n```bash\n# This will just compile the plugin binary\nmake\n```\n\n4. Run a really simple call to this builder:\n\n```bash\n# This will call a \"packer build\" on a really simple configuration\nmake test\n```\n\n## Considered solutions\n\nLet's take this usecase, made-of for this demo:\n\n- I have 2 Parameters for my Builder\n    1. `Create`, a boolean that represents if we should create something or not\n    2. `Number`, an integer that represents the number of things to create\n- I want `Create` to default to `true`\n- I want `Number` to default to `42`\n\n### Solution 1 - Pass defaults to `config.Decode()`\n\nThe\n[`Decode()`](https://github.com/hashicorp/packer/blob/master/helper/config/decode.go#L14)\nfunction of Packer doesn't look like it is able to take default values to\nassign if some parameters are not found in the configuration, neither does the\nunderlying [mapstructure](https://github.com/mitchellh/mapstructure) library\n\n\n- I can't just go the if `IntParam == 0 { IntParam = 42 }` way after the call\n  to config.Decode(), because then it wouldn't allow people to explicitely give\n  IntParam: 0 as parameter\n- I could have a separate function like InitConfig() that is called right\n  before config.Decode(), but that seems a bit weird to me (I will do it if\n  that's the only way, but expected to be able to do something cleaner)\n\n### Solution 2\n\nIdea:\n\n\u003e Let's just have something that initializes the Config with default values\n\u003e before the `config.Decode()` happens\n\nProblem:\n\nThe `config.Decode()` initializes a totally new config and assigns it,\noverriding pre-set values. This is demonstrated in the `defaultconf_preset`\ndirectory:\n\n```raw\nNewBuilder(): Creating new Builder...\nNewBuilder(): Initializing new Config...\nNewBuilder(): Assigning value Create = true\nNewBuilder(): Assigning value Number = 42\nNewBuilder(): Created new Builder. Returning.\n[...]\nPrepare(): Starting...\nPrepare(): Current config:  \u0026{{  false false  map[]} {\u003cnil\u003e map[] map[] false   } true 42}\nPrepare(): Create config Parameter:  true\nPrepare(): Number config Parameter:  42\nPrepare(): Calling config.Decode()...\nPrepare(): Called config.Decode()\nPrepare(): Current config:  \u0026{{defaultconf defaultconf false false  map[]} {\u003cnil\u003e map[] map[] false   } false 0}\nPrepare(): Create config Parameter:  false\nPrepare(): Number config Parameter:  0\nPrepare(): Prepared. Returning.\n```\n\n### Solution 3\n\nIdea:\n\n\u003e Let's check the values after the `config.Decode()` and change them to\n\u003e defaults if the user hasn't changed them\n\nProblem:\n\n**There is no way to know if the user defined a value or not**, we can just\ncheck if the value is the type's default one; what if the user (him/her)self\ndefined it to the type's default? This is demonstrated in the\n`defaultconf_postcmp` directory.\n\n### Solution 4\n\nSuggested by *mcbadass* on IRC (`#packer-tool` on Freenode).\n\nJust accept strings as parameters, and parse/sanitize it.\n\n- `Create` would then no longer be a boolean, but a string, and we would then\n  be able to differenciate empty string\n\nwait. In any way, such a thing is counter-intuitive and it would be required to\nread the documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhorgix%2Fpacker-builder-defaultconf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhorgix%2Fpacker-builder-defaultconf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhorgix%2Fpacker-builder-defaultconf/lists"}