Packer Configuration Basics

Every Packer configuration starts with something like this:

1{
2 "min_packer_version": "1.0.0",
3 "variables": {
4 "foo": "bar",
5 "empty_var": ""
6 },
7 "builders": [
8 {...},
9 ],
10 "provisioners": [
11 {...}
12 ],
13}

Here's what those sections are used for:

  1. Min version: in case you use specific features that require a certain version of Packer (I rarely use this)
  2. Variables: User-defined variables. They can have a value, or can be empty (in which case you can add the value using the CLI when calling Packer)
  3. Builders: Define what providers to use as builders (We'll use amazon-ebs to create a AMI we can use for launching ec2 instances)
  4. Provisioners: Essentially the scripts we run on the server to set everything up the way we want it

Variables

We have a few variables we'll use for our configuration - mostly with default values:

1{
2 "min_packer_version": "1.0.0",
3 "variables": {
4 "infra_name": "cloudcasts",
5 "infra_env": "",
6 "aws_region": "us-east-2",
7 "aws_instance": "t3.small"
8 },
9 "builders": [
10 {...},
11 ],
12 "provisioners": [
13 {...}
14 ],
15}

Don't miss out

Sign up to learn when new content is released! Courses are in production now.