Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up / explain 'packer init' use #11541

Closed
pwillis-els opened this issue Jan 29, 2022 · 4 comments · Fixed by #13044
Closed

Clean up / explain 'packer init' use #11541

pwillis-els opened this issue Jan 29, 2022 · 4 comments · Fixed by #13044
Labels
docs enhancement sync to jira For issues that need to be imported to Packer internal JIRA backlog
Milestone

Comments

@pwillis-els
Copy link
Contributor

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request.

Description

The packer init command does not explain the [config.pkr.hcl|folder/] option. I have tried to use it and I just get errors. Don't know what this option is for or how to use it.

The Documentation on Packer init command does not explain this config.pkr.hcl option.

I assumed I could pass in the same .pkr.hcl values-only file that is passed using -var-file to packer build. However, if you do that, packer init dies with errors.

$ packer init /home/willis2/git/repo/env/nonprod/us-east-1/dev/packer.sh.pkr.hcl
Error: Unsupported argument

  on /home/willis2/git/repo/env/nonprod/us-east-1/dev/packer.sh.pkr.hcl line 3:
   3: asg_subnets_name = "hgraph.non-prod.private_subnet"

An argument named "asg_subnets_name" is not expected here.

Error: Unsupported argument

  on /home/willis2/git/repo/env/nonprod/us-east-1/dev/packer.sh.pkr.hcl line 4:
   4: elb_subnets_name = "hgraph.non-prod.private_subnet"

An argument named "elb_subnets_name" is not expected here.

Error: Unsupported argument

  on /home/willis2/git/repo/env/nonprod/us-east-1/dev/packer.sh.pkr.hcl line 13:
  13: instance_type = "t3a.medium"

An argument named "instance_type" is not expected here.

Error: Unsupported argument

  on /home/willis2/git/repo/env/nonprod/us-east-1/dev/packer.sh.pkr.hcl line 20:
  20: config_repo_folder = "modules/root/aws-jenkins-cluster/provisioning/"

An argument named "config_repo_folder" is not expected here.

Current packer init --help output:

Usage: packer init [options] [config.pkr.hcl|folder/]

  Install all the missing plugins required in a Packer config. Note that Packer
  does not have a state.

  This is the first command that should be executed when working with a new
  or existing template.

  This command is always safe to run multiple times. Though subsequent runs may
  give errors, this command will never delete anything.

Options:
  -upgrade                     On top of installing missing plugins, update
                               installed plugins to the latest available
                               version, if there is a new higher one. Note that
                               this still takes into consideration the version
                               constraint of the config.

Use Case(s)

Any relevant use-cases that you see.

Potential configuration

Potential References

@nywilken
Copy link
Contributor

nywilken commented Feb 2, 2022

Hi @pwillis-els thanks for opening up this issue. We can clear this up a bit for sure. I'll work on getting a quick doc PR open to help out.

In the meantime, the packer init command will try to load any template file ending in pkr.hcl for variable definitions (like packer.sh.pkr.hcl) we recommend using the extensions .pkrvars.hcl and .auto.pkrvars.hcl. This way you can run packer init in the containing directory and the variable definition files will get ignored automatically.

Trying to run packer init against a variable file should fail as it is not in the expected HCL format. I hope this helps a bit.

@nywilken nywilken added backport/website Backport PR changes to `stable-website` and latest release branch docs and removed backport/website Backport PR changes to `stable-website` and latest release branch labels Feb 2, 2022
@nywilken nywilken added the sync to jira For issues that need to be imported to Packer internal JIRA backlog label Sep 30, 2022
@github-actions
Copy link

This issue has been synced to JIRA for planning.

JIRA ID: HPR-750

@starkmatt
Copy link

+1 On this

Any updates?
We're building some Automated Pipelines in gitlab and one of our initial stages is running a packer init during the MR which fails as we're defining all of our vars in .pkvars.hcl files.
Error we get is

Error: Unset variable "mem_size"
A used variable must be set or have a default value; see
https://packer.io/docs/templates/hcl_templates/syntax for details.

init should be able to view the pkvars file or at least not fail on an init because they're being defined in var files.
Perhaps an init shouldn't be run in this case?

@nywilken nywilken added this to the 1.10.0 milestone Oct 16, 2023
@nywilken nywilken modified the milestones: 1.10.0, 1.11.0 Jan 12, 2024
nywilken pushed a commit that referenced this issue Jun 13, 2024
Adds additional examples and help regarding the use of `packer init`.

Ref: #11541

Signed-off-by: Ryan Johnson <ryan@tenthirtyam.org>
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
docs enhancement sync to jira For issues that need to be imported to Packer internal JIRA backlog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants