Packer & TerraForm
A brief intro in automation using Packer and TerraForm
Today’s challenges
Increasingly complex infrastructure to setup
• Multiple environments for testing and production
• Evolution / Changing of infrastructure
• Documentation of infrastructure
• More than one server involved
Infrastructure as Code (IaC)
Infrastructure as Code (IaC) is the process of managing and provisioning computing
infrastructure (processes, bare-metal servers, virtual servers, etc.) and their configuration
through machine-processable definition files
• Cost (reduction)
• Speed (faster execution)
• and Risk (remove errors and security violations)
Introducing Packer and TerraForm
Packer
Packer is a tool for creating machine and container images
for multiple platforms from a single source configuration.
Treat server as immutable
Any configuration change results in a
completely new server
Allows for easier tools then Chef or Puppet
JSON configuration language
TerraForm
Terraform provides a common configuration to launch
infrastructure. Once launched, Terraform safely and
efficiently changes infrastructure as the configuration is
evolved
Describe infrastructure in a declarative way
Keep track of changes to the infrastructure
Changing infrastructure is accessible to entire
team
Rollback your infrastructure to a previous point
Why use Packer?
Standardise development environments and machine images.
Create near identical state infrastructure across multiple
environments
Why use TerraForm?
To orchestrate and create resources in your environments with ease
and simplicity
<plan> Objectives || Strategy || Design</plan>
Packer
https://www.packer.io/
Packer Concepts:
Builders
Provisioners
Parallel Builds
Post Processors
Building Images
Create a template
: configuration file used to define what
image we want built and how
Notes
Define the builders
Define provisioners
Define post-processors
Define variables (access keys etc)
<NB/>: Parallel Builds
Example
{
"builders": [],
"description": "A packer example template",
"min_packer_version": "0.8.0",
"provisioners": [],
"post-processors": [],
"variables": []
}
Builders
Amazon EC2 (AMI)
DigitalOcean
Docker
Google Compute Engine
OpenStack
VirtualBox
<Commands/>:
packer build
packer fix
packer inspect
packer validate
{
"variables": {
"aws_access_key": "YOURACCESSKEY",
"aws_secret_key": "YOURSECRETKEY",
"do_api_token": "YOURAPITOKEN"
},
"builders": [{
"type": "amazon-ebs",
"access_key": "{{user `aws_access_key`}}",
"secret_key": "{{user `aws_secret_key`}}",
"region": "us-east-1",
"source_ami": "ami-fce3c696",
"instance_type": "t2.micro",
"ssh_username": "ubuntu",
"ami_name": "packer-example {{timestamp}}"
},{
"type": "digitalocean",
"api_token": "{{user `do_api_token`}}",
"image": "ubuntu-14-04-x64",
"region": "nyc3",
"size": "512mb"
}],
"provisioners": [{
"type": "shell",
"inline": [
"sleep 30",
"sudo apt-get update",
"sudo apt-get install -y redis-server"
]
}]
}
TerraForm
https://www.terraform.io/
TerraForm Key Features:
Infrastructure as Code
Execution Plans
Resource Graph
Change Automation
TerraForm
: a tool for building, changing, and
versioning infrastructure safely and
efficiently.
Resources
Providers
terraform.tfstate: maps various resource
metadata to actual resource IDs so that Terraform
knows what it is managing
Input variables: variables.tf &
terraform.tfvars
Output variables
Example: main.tf
provider "aws" {
access_key = "ACCESS_KEY_HERE"
secret_key = "SECRET_KEY_HERE"
region = "us-east-1"
}
resource "aws_instance" "example" {
ami = "ami-0d729a60" #from packer build
instance_type = "t2.micro"
}
Templates
main.tf
variables.tf
terraform.tfvars
*.tpl (template resource)
<commands/>:
terraform validate
terraform plan
terraform apply
terraform destroy
# variables.tf
variable "web_count" {
type = "string"
description = "How many EC2 instances to deploy"
}
# terraform.tfvars
web_count = 2
aws_route53_zone_id = "YOURZONEID"
aws_access_key = "YOURACCESS"
aws_secret_key = "YOURSECRETKEYXXXXXXXXXXXXXXX"
….# snippet from main.tf
resource "template_file" "web_server_init" {
count = "${var.web_count}"
template = "${file("web_init.tpl")}"
vars {
hostname = "${lookup(var.web_hostnames, count.index)}"
device_name = "/dev/xvdf"
mount_point = "/srv/data"
}
}
#!/bin/bash -v
sudo mkfs -t ext4 ${device_name}
sudo mkdir ${mount_point}
sudo echo "${device_name} ${mount_point} ext4 defaults,nofail 0 2" >> /etc/fstab
Build Steps
Planning (Packer ->
TerraForm)
Plan reqs: packer builders / provisioners
Plan TerraForm resources/providers
Remote build (Packer)
Packer inspect/fix/validate
Packer build (store build artifact)-> update TF to use this
artifact/ami as a source
TerraForm Plan
Terraform validate > graph > plan
Store plan output
TerraForm Apply
Run terraform apply (or terraform destroy)
Commit .tfstate to VCS or remote backend.
Design Env Maintain
Packer and TerraForm
Packer build image TerraForm Apply
Store artifact
TerraForm update
Add resources
Destroy resources
Etc

More Related Content

PPTX
Packer, where DevOps begins
PPTX
Building Windows Images with Packer
PDF
A Introduction of Packer
PPTX
Introduction to Packer and Suitcase: A Packer-based OS Image Build System
PDF
London Hug 19/5 - Terraform in Production
PDF
Service Delivery Assembly Line with Vagrant, Packer, and Ansible
PPTX
Baking in the cloud with packer and puppet
PPTX
Packer
Packer, where DevOps begins
Building Windows Images with Packer
A Introduction of Packer
Introduction to Packer and Suitcase: A Packer-based OS Image Build System
London Hug 19/5 - Terraform in Production
Service Delivery Assembly Line with Vagrant, Packer, and Ansible
Baking in the cloud with packer and puppet
Packer

What's hot (19)

PDF
PDF
Docker 1.12 (dockercon recap)
PDF
(2016-06-11) Packer: Make Multi-Platform Images
PDF
OpenSource ToolChain for the Hybrid Cloud
PDF
AWS Elastic Container Service - DockerHN
PDF
Rackspace Hack Night - Vagrant & Packer
PDF
Usecase examples of Packer
PDF
Kubernetes Boston — Custom High Availability of Kubernetes
PDF
Build automated Machine Images using Packer
PDF
Developing Terraform Modules at Scale - HashiTalks 2021
PPTX
Terraform Modules and Continuous Deployment
PDF
PPTX
ILM - Pipeline in the cloud
PPT
Fake IT, until you make IT
PDF
Using Ansible for Deploying to Cloud Environments
PDF
Automating CloudStack with Puppet - David Nalley
PPTX
Automating aws infrastructure and code deployments using Ansible @WebEngage
ODP
Infrastructure as code with Puppet and Apache CloudStack
PDF
Hashicorp @ JUST EAT - Part 2
Docker 1.12 (dockercon recap)
(2016-06-11) Packer: Make Multi-Platform Images
OpenSource ToolChain for the Hybrid Cloud
AWS Elastic Container Service - DockerHN
Rackspace Hack Night - Vagrant & Packer
Usecase examples of Packer
Kubernetes Boston — Custom High Availability of Kubernetes
Build automated Machine Images using Packer
Developing Terraform Modules at Scale - HashiTalks 2021
Terraform Modules and Continuous Deployment
ILM - Pipeline in the cloud
Fake IT, until you make IT
Using Ansible for Deploying to Cloud Environments
Automating CloudStack with Puppet - David Nalley
Automating aws infrastructure and code deployments using Ansible @WebEngage
Infrastructure as code with Puppet and Apache CloudStack
Hashicorp @ JUST EAT - Part 2

Viewers also liked (20)

PDF
London HUG 19/5 - Kubernetes and vault
PPTX
PDF
Betabeers Barcelona - Buenas prácticas
PDF
How to improve your moodle site performance
PDF
Entorno de desarrollo rápido con Vagrant
PDF
Rapid Infrastructure Provisioning
PDF
Terraform
PDF
Terraform and cloud.ca
PPTX
PPTX
Infrastructure as Code: Introduction to Terraform
PPTX
Terraform
PDF
Vagrant y Docker - Guía práctica de uso
PDF
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
PPTX
Terraform at Scale
PDF
Terraform Introduction
PDF
Terraform: Cloud Configuration Management (WTC/IPC'16)
PDF
Etcd terraform by Alex Somesan
PPTX
2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...
PDF
Refactoring terraform
PDF
London HUG 14/4 - Deploying and Discovering at Scale with Consul and Nomad
London HUG 19/5 - Kubernetes and vault
Betabeers Barcelona - Buenas prácticas
How to improve your moodle site performance
Entorno de desarrollo rápido con Vagrant
Rapid Infrastructure Provisioning
Terraform
Terraform and cloud.ca
Infrastructure as Code: Introduction to Terraform
Terraform
Vagrant y Docker - Guía práctica de uso
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
Terraform at Scale
Terraform Introduction
Terraform: Cloud Configuration Management (WTC/IPC'16)
Etcd terraform by Alex Somesan
2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...
Refactoring terraform
London HUG 14/4 - Deploying and Discovering at Scale with Consul and Nomad

Similar to Automation with Packer and TerraForm (20)

PPTX
Hashicorp-Terraform_Packer_Vault-by Sushil
PDF
Infrastructure as Code: Manage your Architecture with Git
PDF
DevOps Enabling Your Team
PPTX
Infrastructure as code, using Terraform
PDF
Immutable AWS Deployments with Packer and Jenkins
PDF
Managing Infrastructure as Code
PDF
CDK Meetup: Rule the World through IaC
PDF
Infrastructure as Code: Manage your Architecture with Git
PDF
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
PPTX
Continuous Deployment with Amazon Web Services by Carlos Conde
PDF
Pulsar Architectural Patterns for CI/CD Automation and Self-Service_Devin Bost
PDF
Industrializing the creation of machine images and Docker containers for clou...
 
PDF
TechBeats #2
PPTX
Hitchhiker's guide to Cloud-Native Build Pipelines and Infrastructure as Code
PDF
Cloud-native .NET-Microservices mit Kubernetes @BASTAcon
PDF
Immutable Deployments with AWS CloudFormation and AWS Lambda
PDF
EC2 AMI Factory with Chef, Berkshelf, and Packer
PDF
Get you Java application ready for Kubernetes !
PDF
Microservice Automated Testing on Kubernetes
PPTX
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto
Hashicorp-Terraform_Packer_Vault-by Sushil
Infrastructure as Code: Manage your Architecture with Git
DevOps Enabling Your Team
Infrastructure as code, using Terraform
Immutable AWS Deployments with Packer and Jenkins
Managing Infrastructure as Code
CDK Meetup: Rule the World through IaC
Infrastructure as Code: Manage your Architecture with Git
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Continuous Deployment with Amazon Web Services by Carlos Conde
Pulsar Architectural Patterns for CI/CD Automation and Self-Service_Devin Bost
Industrializing the creation of machine images and Docker containers for clou...
 
TechBeats #2
Hitchhiker's guide to Cloud-Native Build Pipelines and Infrastructure as Code
Cloud-native .NET-Microservices mit Kubernetes @BASTAcon
Immutable Deployments with AWS CloudFormation and AWS Lambda
EC2 AMI Factory with Chef, Berkshelf, and Packer
Get you Java application ready for Kubernetes !
Microservice Automated Testing on Kubernetes
Orchestrating Docker with Terraform and Consul by Mitchell Hashimoto

Recently uploaded (20)

PPTX
Build automations faster and more reliably with UiPath ScreenPlay
PPTX
Presentation - Principles of Instructional Design.pptx
PDF
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
PDF
CEH Module 2 Footprinting CEH V13, concepts
PDF
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
PDF
Build Real-Time ML Apps with Python, Feast & NoSQL
PDF
Early detection and classification of bone marrow changes in lumbar vertebrae...
PPTX
Information-Technology-in-Human-Society.pptx
PDF
NewMind AI Journal Monthly Chronicles - August 2025
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PDF
substrate PowerPoint Presentation basic one
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PPTX
AQUEEL MUSHTAQUE FAKIH COMPUTER CENTER .
PDF
Introduction to MCP and A2A Protocols: Enabling Agent Communication
PDF
SaaS reusability assessment using machine learning techniques
PDF
Streamline Vulnerability Management From Minimal Images to SBOMs
PDF
The AI Revolution in Customer Service - 2025
PDF
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
PDF
Identification of potential depression in social media posts
Build automations faster and more reliably with UiPath ScreenPlay
Presentation - Principles of Instructional Design.pptx
Transform-Quality-Engineering-with-AI-A-60-Day-Blueprint-for-Digital-Success.pdf
CEH Module 2 Footprinting CEH V13, concepts
The-2025-Engineering-Revolution-AI-Quality-and-DevOps-Convergence.pdf
Build Real-Time ML Apps with Python, Feast & NoSQL
Early detection and classification of bone marrow changes in lumbar vertebrae...
Information-Technology-in-Human-Society.pptx
NewMind AI Journal Monthly Chronicles - August 2025
giants, standing on the shoulders of - by Daniel Stenberg
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
substrate PowerPoint Presentation basic one
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
AQUEEL MUSHTAQUE FAKIH COMPUTER CENTER .
Introduction to MCP and A2A Protocols: Enabling Agent Communication
SaaS reusability assessment using machine learning techniques
Streamline Vulnerability Management From Minimal Images to SBOMs
The AI Revolution in Customer Service - 2025
CXOs-Are-you-still-doing-manual-DevOps-in-the-age-of-AI.pdf
Identification of potential depression in social media posts

Automation with Packer and TerraForm

  • 1. Packer & TerraForm A brief intro in automation using Packer and TerraForm
  • 2. Today’s challenges Increasingly complex infrastructure to setup • Multiple environments for testing and production • Evolution / Changing of infrastructure • Documentation of infrastructure • More than one server involved
  • 3. Infrastructure as Code (IaC) Infrastructure as Code (IaC) is the process of managing and provisioning computing infrastructure (processes, bare-metal servers, virtual servers, etc.) and their configuration through machine-processable definition files • Cost (reduction) • Speed (faster execution) • and Risk (remove errors and security violations)
  • 4. Introducing Packer and TerraForm Packer Packer is a tool for creating machine and container images for multiple platforms from a single source configuration. Treat server as immutable Any configuration change results in a completely new server Allows for easier tools then Chef or Puppet JSON configuration language TerraForm Terraform provides a common configuration to launch infrastructure. Once launched, Terraform safely and efficiently changes infrastructure as the configuration is evolved Describe infrastructure in a declarative way Keep track of changes to the infrastructure Changing infrastructure is accessible to entire team Rollback your infrastructure to a previous point
  • 5. Why use Packer? Standardise development environments and machine images. Create near identical state infrastructure across multiple environments Why use TerraForm? To orchestrate and create resources in your environments with ease and simplicity
  • 6. <plan> Objectives || Strategy || Design</plan>
  • 8. Create a template : configuration file used to define what image we want built and how Notes Define the builders Define provisioners Define post-processors Define variables (access keys etc) <NB/>: Parallel Builds Example { "builders": [], "description": "A packer example template", "min_packer_version": "0.8.0", "provisioners": [], "post-processors": [], "variables": [] }
  • 9. Builders Amazon EC2 (AMI) DigitalOcean Docker Google Compute Engine OpenStack VirtualBox <Commands/>: packer build packer fix packer inspect packer validate { "variables": { "aws_access_key": "YOURACCESSKEY", "aws_secret_key": "YOURSECRETKEY", "do_api_token": "YOURAPITOKEN" }, "builders": [{ "type": "amazon-ebs", "access_key": "{{user `aws_access_key`}}", "secret_key": "{{user `aws_secret_key`}}", "region": "us-east-1", "source_ami": "ami-fce3c696", "instance_type": "t2.micro", "ssh_username": "ubuntu", "ami_name": "packer-example {{timestamp}}" },{ "type": "digitalocean", "api_token": "{{user `do_api_token`}}", "image": "ubuntu-14-04-x64", "region": "nyc3", "size": "512mb" }], "provisioners": [{ "type": "shell", "inline": [ "sleep 30", "sudo apt-get update", "sudo apt-get install -y redis-server" ] }] }
  • 11. TerraForm : a tool for building, changing, and versioning infrastructure safely and efficiently. Resources Providers terraform.tfstate: maps various resource metadata to actual resource IDs so that Terraform knows what it is managing Input variables: variables.tf & terraform.tfvars Output variables Example: main.tf provider "aws" { access_key = "ACCESS_KEY_HERE" secret_key = "SECRET_KEY_HERE" region = "us-east-1" } resource "aws_instance" "example" { ami = "ami-0d729a60" #from packer build instance_type = "t2.micro" }
  • 12. Templates main.tf variables.tf terraform.tfvars *.tpl (template resource) <commands/>: terraform validate terraform plan terraform apply terraform destroy # variables.tf variable "web_count" { type = "string" description = "How many EC2 instances to deploy" } # terraform.tfvars web_count = 2 aws_route53_zone_id = "YOURZONEID" aws_access_key = "YOURACCESS" aws_secret_key = "YOURSECRETKEYXXXXXXXXXXXXXXX" ….# snippet from main.tf resource "template_file" "web_server_init" { count = "${var.web_count}" template = "${file("web_init.tpl")}" vars { hostname = "${lookup(var.web_hostnames, count.index)}" device_name = "/dev/xvdf" mount_point = "/srv/data" } } #!/bin/bash -v sudo mkfs -t ext4 ${device_name} sudo mkdir ${mount_point} sudo echo "${device_name} ${mount_point} ext4 defaults,nofail 0 2" >> /etc/fstab
  • 13. Build Steps Planning (Packer -> TerraForm) Plan reqs: packer builders / provisioners Plan TerraForm resources/providers Remote build (Packer) Packer inspect/fix/validate Packer build (store build artifact)-> update TF to use this artifact/ami as a source TerraForm Plan Terraform validate > graph > plan Store plan output TerraForm Apply Run terraform apply (or terraform destroy) Commit .tfstate to VCS or remote backend.
  • 14. Design Env Maintain Packer and TerraForm Packer build image TerraForm Apply Store artifact TerraForm update Add resources Destroy resources Etc