SlideShare a Scribd company logo
Infrastructure as code with
Terraform and Packer
Alex Landa
Head of DevOps and BigData technologies at Trainologic
We will talk about
•Why infrastructure as code?
•How to build images with Packer?
•Managing cloud environments with
Terraform
Story time
• Once upon a time a cool Machine Learning startup raised seed
money - lets call them CyberTemp
• They wrote in Python and used AWS
The story part ||
• They wanted use Auto-Scaling so they created an AMI
• By hand
• Took a day to configure
And then they had to update..
• They wanted to use a different base AMI that support GPUs
So what went wrong?
• No automatic way to configure the server
• Error prone
• No connection to the CI process
• No way to track changes
Infrastructure as Code
• Writing code to manage configuration, provisioning and deployment
• Scripts
• Ansible
• Docker
• Terraform
• ..
• Using software development practices:
• Source control
• Testing
• Code reviews
• Design
• 3rd libraries
• Knowledge sharing
What if CyberTemp
• Has to deploy on several cloud providers?
• It wants to create an automatic deployment?
• Want to create a VM images for on premise deployment?
Packer
• “An open source tool for creating identical machine images
for multiple platforms from a single source configuration”
• Machine image contains pre-configures OS and installed
software which is used to create and run machines
• AMI for EC2
• VMDK/VMX for VMware
• OVF for VirtualBox
• Different cloud providers
Packer template
• A JSON file that contains the build configuration
• Composed of several parts:
• Builders – Create the machines and generates the images from them
in the configured platform
• Provisioners – Install and configure on the machine
• Post-processors – Take the result of a builder or another post-
processor
• Variables – key value strings to parametrize templates
Packer Example
Builders
• Responsible for creating the machine
• Provide a way to run the Provisioners there – communicator
• SSH
• WinRM for Windows machines
• Packages the machine into a deployable image
• Every build definition maps to a single build.
Provisioners
• Use built-in and existing module to install and configure the
machine after booting
• Installing packages
• Applying patches
• Creating users and folders
• Downloading or copying application code
• The Provisioners are executed in the order they are defined
Post Processors
• Optional section to run processing on the built image
• Compression, tagging, uploading files, etc..
• Every post processor will be ran on every build image (unless
configured otherwise)
Variables
• The way to pass environment variables to packer
• Templating the build
So we have an image..
• Cloud deployments are complex
• Contain
• Permissions
• Network definitions
• Machines
• Load balancers
• Databases
• Other managed services
Now lets deploy in Europe
If only we had our infrastructure in code..
Terraform
• An open-source tool for building, updating and managing
infrastructure
• Uses declarative approach – the state that I want to achieve
instead of set of instructions
• Configuration files are written in HCL, also support JSON
• Written in Go
The Terraform work flow
• Define – create or update your configuration file
• Init – initializes the terraform environment and provider binaries
• Plan – Terraform creates an execution plan from the configuration
files and the current state
• Apply – Applies the execution plan, modify the cloud infrastructure
• Destroy (optional  ) – removes all the resources specified in the
configuration
Simple example
resource "aws_instance" "web" {
ami = "ami-679d3f1e"
instace_type = "t2.micro
}
Resource
• Everything with life cycle – machine, load balancers, network …
• Has a type – different for every resource type and cloud provider
• Has a unique name – for internal reference
• Uses attributes – configuration for the type
• Uses Interpolation – a way to reference other resources and manipulate values
Terraform plan
• Terraform creates a resource graph
• It calculates the dependencies of every resource and the action that
should happen – the result is a plan
+ aws_instance.web
id: <computed>
ami: "ami-679d3f1e"
associate_public_ip_address: <computed>
...
get_password_data: "false"
instance_state: <computed>
instance_type: "t2.micro"
...
Reading the Terraform plan
•+ a resource will be created
• - resource will be destroyed
• ~ resource will be updated in place
• -/+ resource will be destroyed and recreated
Terraform apply
• Generates an execution plan if not given
• Asks for confirmation for the changes to come
• Executes the plan
• Updates the state
State of the “Art”
• Used by Terraform to map between the “actual” cloud resources
to the configured one
• Contains resource metadata - the real dependencies between
resources
• Refreshed before actions to validate the “State of the world”
• A JSON file created in the local directory with the name
terraform.tfstate
Remote state
• Local state is an issue when a team works together
• Remote state allows Terraform to synchronize state across different
machines
• Uses “backends” – determines how state is loaded and updated:
• S3
• Consul
• ETCD
• Terraform enterprise …
Templating Terraform
• Terraform allows to template configuration by using variables
• As convention defined in variables.tf
• Support lists and maps
• Can be set:
• In a file terraform.tfvars
• As a command line flags -var ‘region=us-west-2’
• UI
• Defaults
variable "region" {}
Output
• A way to organize data back to the user
• Tells Terraform what data is important
• Can be viewed as part of the ”apply” command result,
or by using terraform output web_ip
•
output "web_ip" {
value = "${aws_instance.web.public_ip}"
}
Terraform modules
• A way to structure Terraform to reusable pieces
• Self-contained packages that are managed as a group
• Terraform registry – a public repository for popular modules
• To use a module:
• Declare in config
• Run terraform init – downloads the module
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "my-vpc"
cidr = "10.0.0.0/16
…
Questions?
variable "questions" {
type = "list"
description = "???"
}

More Related Content

PPTX
AWS Elastic Container Service (ECS) with a CI Pipeline Overview
PPTX
Developer workflow with docker
PPTX
Introduction to Apache Mesos
PPTX
Containerization in microsoft azure
PPTX
Containerization with Microsoft Azure
PPTX
Tech4Africa 2014
PDF
Monitoring docker: from zero to Azure
PPTX
Cooking Akka.net and Azure Service Fabric together
AWS Elastic Container Service (ECS) with a CI Pipeline Overview
Developer workflow with docker
Introduction to Apache Mesos
Containerization in microsoft azure
Containerization with Microsoft Azure
Tech4Africa 2014
Monitoring docker: from zero to Azure
Cooking Akka.net and Azure Service Fabric together

What's hot (20)

PDF
Performance monitoring for Docker - Lucerne meetup
PDF
Neptune @ SoCal
PPTX
eCAP Developer Walkthru
PPTX
Introducing Puppet - The faster speed of Automation
PPTX
Spark 1.0
PPTX
Terraform - Shared Definitions and Variable Inheritance
PDF
Running an openstack instance
PDF
AppScale Talk at SBonRails
PDF
Appscale at CLOUDCOMP '09
PPTX
Apache Curator: Past, Present and Future
PDF
AppScale @ LA.rb
PPTX
Amazon Cloud Overview
PDF
AppScale + Neptune @ HPCDB
PDF
A Pluggable Autoscaling System @ UCC
PPT
Exploring Openstack Swift(Object Storage) and Swiftstack
PDF
Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015
PPT
Designing the Call of Cthulhu app with Google App Engine
PDF
Ph.D. Defense
PDF
Active Cloud DB at CloudComp '10
PDF
Virtual Machine Migration Techniques in Cloud Environment: A Survey
Performance monitoring for Docker - Lucerne meetup
Neptune @ SoCal
eCAP Developer Walkthru
Introducing Puppet - The faster speed of Automation
Spark 1.0
Terraform - Shared Definitions and Variable Inheritance
Running an openstack instance
AppScale Talk at SBonRails
Appscale at CLOUDCOMP '09
Apache Curator: Past, Present and Future
AppScale @ LA.rb
Amazon Cloud Overview
AppScale + Neptune @ HPCDB
A Pluggable Autoscaling System @ UCC
Exploring Openstack Swift(Object Storage) and Swiftstack
Building an Autoscaler for DigitalOcean - DevOps Days Denver 2015
Designing the Call of Cthulhu app with Google App Engine
Ph.D. Defense
Active Cloud DB at CloudComp '10
Virtual Machine Migration Techniques in Cloud Environment: A Survey
Ad

Similar to Infrastructure as code with terraform and packer (20)

PDF
Infrastructure as Code with Terraform
PDF
TechBeats #2
PPTX
Terraform
PPTX
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
PPTX
Cloudify workshop at CCCEU 2014
PPTX
Terraform day1
PDF
Infrastructure as Code for Azure: ARM or Terraform?
PDF
20170831 - Greg Palmier: Terraform & AWS at Tempus
PPTX
Effective terraform
PPTX
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
PDF
Introduction to IAC and Terraform
PPTX
Docker and kubernetes
PDF
Azure Day Rome 2019 Reloaded - Effettuare il provisioning su Azure utilizzand...
PDF
Provisioning with Terraform - AzureDay Reloaded
PDF
Infrastructure as Code
PPTX
Meteor presentation
PDF
Terraform: Infrastructure as Code
PPTX
Centralized Application Configuration with Spring and Apache Zookeeper
PDF
Ch1Ch2Sept10.pdf
PPT
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
Infrastructure as Code with Terraform
TechBeats #2
Terraform
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
Cloudify workshop at CCCEU 2014
Terraform day1
Infrastructure as Code for Azure: ARM or Terraform?
20170831 - Greg Palmier: Terraform & AWS at Tempus
Effective terraform
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Introduction to IAC and Terraform
Docker and kubernetes
Azure Day Rome 2019 Reloaded - Effettuare il provisioning su Azure utilizzand...
Provisioning with Terraform - AzureDay Reloaded
Infrastructure as Code
Meteor presentation
Terraform: Infrastructure as Code
Centralized Application Configuration with Spring and Apache Zookeeper
Ch1Ch2Sept10.pdf
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
Ad

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Cloud computing and distributed systems.
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Electronic commerce courselecture one. Pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Cloud computing and distributed systems.
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Empathic Computing: Creating Shared Understanding
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Diabetes mellitus diagnosis method based random forest with bat algorithm
MIND Revenue Release Quarter 2 2025 Press Release
Review of recent advances in non-invasive hemoglobin estimation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Electronic commerce courselecture one. Pdf

Infrastructure as code with terraform and packer

  • 1. Infrastructure as code with Terraform and Packer Alex Landa Head of DevOps and BigData technologies at Trainologic
  • 2. We will talk about •Why infrastructure as code? •How to build images with Packer? •Managing cloud environments with Terraform
  • 3. Story time • Once upon a time a cool Machine Learning startup raised seed money - lets call them CyberTemp • They wrote in Python and used AWS
  • 4. The story part || • They wanted use Auto-Scaling so they created an AMI • By hand • Took a day to configure
  • 5. And then they had to update.. • They wanted to use a different base AMI that support GPUs
  • 6. So what went wrong? • No automatic way to configure the server • Error prone • No connection to the CI process • No way to track changes
  • 7. Infrastructure as Code • Writing code to manage configuration, provisioning and deployment • Scripts • Ansible • Docker • Terraform • .. • Using software development practices: • Source control • Testing • Code reviews • Design • 3rd libraries • Knowledge sharing
  • 8. What if CyberTemp • Has to deploy on several cloud providers? • It wants to create an automatic deployment? • Want to create a VM images for on premise deployment?
  • 9. Packer • “An open source tool for creating identical machine images for multiple platforms from a single source configuration” • Machine image contains pre-configures OS and installed software which is used to create and run machines • AMI for EC2 • VMDK/VMX for VMware • OVF for VirtualBox • Different cloud providers
  • 10. Packer template • A JSON file that contains the build configuration • Composed of several parts: • Builders – Create the machines and generates the images from them in the configured platform • Provisioners – Install and configure on the machine • Post-processors – Take the result of a builder or another post- processor • Variables – key value strings to parametrize templates
  • 12. Builders • Responsible for creating the machine • Provide a way to run the Provisioners there – communicator • SSH • WinRM for Windows machines • Packages the machine into a deployable image • Every build definition maps to a single build.
  • 13. Provisioners • Use built-in and existing module to install and configure the machine after booting • Installing packages • Applying patches • Creating users and folders • Downloading or copying application code • The Provisioners are executed in the order they are defined
  • 14. Post Processors • Optional section to run processing on the built image • Compression, tagging, uploading files, etc.. • Every post processor will be ran on every build image (unless configured otherwise)
  • 15. Variables • The way to pass environment variables to packer • Templating the build
  • 16. So we have an image.. • Cloud deployments are complex • Contain • Permissions • Network definitions • Machines • Load balancers • Databases • Other managed services
  • 17. Now lets deploy in Europe If only we had our infrastructure in code..
  • 18. Terraform • An open-source tool for building, updating and managing infrastructure • Uses declarative approach – the state that I want to achieve instead of set of instructions • Configuration files are written in HCL, also support JSON • Written in Go
  • 19. The Terraform work flow • Define – create or update your configuration file • Init – initializes the terraform environment and provider binaries • Plan – Terraform creates an execution plan from the configuration files and the current state • Apply – Applies the execution plan, modify the cloud infrastructure • Destroy (optional  ) – removes all the resources specified in the configuration
  • 20. Simple example resource "aws_instance" "web" { ami = "ami-679d3f1e" instace_type = "t2.micro }
  • 21. Resource • Everything with life cycle – machine, load balancers, network … • Has a type – different for every resource type and cloud provider • Has a unique name – for internal reference • Uses attributes – configuration for the type • Uses Interpolation – a way to reference other resources and manipulate values
  • 22. Terraform plan • Terraform creates a resource graph • It calculates the dependencies of every resource and the action that should happen – the result is a plan + aws_instance.web id: <computed> ami: "ami-679d3f1e" associate_public_ip_address: <computed> ... get_password_data: "false" instance_state: <computed> instance_type: "t2.micro" ...
  • 23. Reading the Terraform plan •+ a resource will be created • - resource will be destroyed • ~ resource will be updated in place • -/+ resource will be destroyed and recreated
  • 24. Terraform apply • Generates an execution plan if not given • Asks for confirmation for the changes to come • Executes the plan • Updates the state
  • 25. State of the “Art” • Used by Terraform to map between the “actual” cloud resources to the configured one • Contains resource metadata - the real dependencies between resources • Refreshed before actions to validate the “State of the world” • A JSON file created in the local directory with the name terraform.tfstate
  • 26. Remote state • Local state is an issue when a team works together • Remote state allows Terraform to synchronize state across different machines • Uses “backends” – determines how state is loaded and updated: • S3 • Consul • ETCD • Terraform enterprise …
  • 27. Templating Terraform • Terraform allows to template configuration by using variables • As convention defined in variables.tf • Support lists and maps • Can be set: • In a file terraform.tfvars • As a command line flags -var ‘region=us-west-2’ • UI • Defaults variable "region" {}
  • 28. Output • A way to organize data back to the user • Tells Terraform what data is important • Can be viewed as part of the ”apply” command result, or by using terraform output web_ip • output "web_ip" { value = "${aws_instance.web.public_ip}" }
  • 29. Terraform modules • A way to structure Terraform to reusable pieces • Self-contained packages that are managed as a group • Terraform registry – a public repository for popular modules • To use a module: • Declare in config • Run terraform init – downloads the module module "vpc" { source = "terraform-aws-modules/vpc/aws" name = "my-vpc" cidr = "10.0.0.0/16 …
  • 30. Questions? variable "questions" { type = "list" description = "???" }

Editor's Notes

  • #28: https://www.terraform.io/intro/getting-started/variables.html
  • #29: https://www.terraform.io/intro/getting-started/variables.html
  • #30: https://www.terraform.io/intro/getting-started/modules.html