Skip to main content

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 scripts
  • scripts: All scripts we will execute we will place here
  • services: 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 redefine
  • ansible: 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.hcl In this file we will declare the sources and the build block
  • packer.pkr.hcl In this file we will declare configurations for packer, such as version and plugins
  • variables.pkr.hcl In this file we will declare the variables we will use
  • locals.pkr.hcl If any variable is defined at runtime by a function or interpolation, it will be created in this file.
  • data.pkr.hcl This 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.