Base Project Structure
Let's create a structure as follows.
mkdir -p ./project/{vars,scripts,files,services,ansible}
touch ./project/{main.pkr.hcl,packer.pkr.hcl,variables.pkr.hcl,locals.pkr.hcl,data.pkr.hcl}
tree project
project
βββ files
βββ locals.pkr.hcl
βββ main.pkr.hcl
βββ packer.pkr.hcl
βββ scripts
βββ services
βββ variables.pkr.hcl
βββ vars
5 directories, 4 files
Directories:
files: This directory will contain all files that are not scriptsscripts: All scripts we will execute we will place hereservices: All services we will activate in the operating system we can place here- These services are a maneuver to launch some configuration after image initialization
vars: Here we will have the input files to fill in the variables that do not have default values or some that we want to redefineansible: We could have a set of playbooks to be executed with ansible in this folder that we didn't define, but here's the tip.
Packer base files remembering it has to be .pkr.hcl
main.pkr.hclIn this file we will declare the sources and the build blockpacker.pkr.hclIn this file we will declare configurations for packer, such as version and pluginsvariables.pkr.hclIn this file we will declare the variables we will uselocals.pkr.hclIf any variable is defined at runtime by a function or interpolation, it will be created in this file.data.pkr.hclThis file will be used to deliver several possible images.
The project will continue with explanations in the next steps. The idea is to study while creating the project as you learn.