SlideShare a Scribd company logo
1 of 29
zz
Terraform Modules and
Continuous Deployments
San Francisco Infrastructure as Code Meetup
zz
Your speakers…
• Zane Williamson
• Trulia Sr. DevOps
• Twitter @zane_williamson
• Github @sepulworld
• Marius Ducea
• AWS Consultant
• Twitter @mariusducea
• Github @mdxp
zz
Overview
1. The Challenge
2. System overview
3. Why we chose Terraform and Packer for Continuous
Deployment
4. Terraform modules and how we are using them
5. Demo a continuous deployment with Terraform and Packer
zz
The Challenge
• Deploying an array of micro services
• Multiple teams
• Repeatable Cloud configuration
• Peer reviewed infrastructure changes
• Tooling flexibility
• As simple as possible for non experts
zz
System Overview
• Cloud Provider is AWS
• Micro-services APIs with ELB
endpoints
• Micro-services acting as worker
clusters without ELB endpoints
• A common shared backend
zz
System Overview
Terraform Managed
• Kafka cluster
• SQS
• s3
• RDS
• EMR (Hbase)
• VPC, subnets, routes, etc
zz
Why We Chose Packer to Build Images
1. Dev and ops personnel were already familiar with Packer
2. Allowed us to reuse Puppet modules
3. Multiple outputs (VirtualBox, Docker, AMI, etc)
4. Able to embed in the micro-service code base
5. Easy to call from Jenkins server
zz
Why we chose Terraform to Manage
Infrastructure
1. CloudFormation was limited to AWS services
2. Libraries like Boto and Fog required programming skills and don’t
manage state as well
3. Some developers and operations personnel were already familiar with
Terraform
4. Easy to integrate into Jenkins which is the preferred build and
deployment platform of most of our teams
5. Ability to put the Terraform directly into the code base for each micro-
service
6. Leverage Terraform Modules and the capability to use a Git repo as a
source
zz
Challenges we faced early on
Multiple teams working with terraform
• code duplication | code drift
• management & maintenance
• versioning
• testing
zz
Terraform modules
The solution to all our problems?
zz
Terraform modules basics
• Modules are used to create reusable components in
Terraform as well as for basic code organization.
• Modules are very easy to create and use.
• A module is technically just a folder with some
terraform templates.
zz
Terraform modules - example ELB module
elb
├── CHANGELOG.md
├── README.md
├── main.tf
├── outputs.tf
├── test
│ ├── aws.tf
│ └── test.tf
└── variables.tf
zz
variables.tf
variable "name" {
default = "dev-elb"
}
variable "subnet_ids" {
description = "comma separated list of subnet IDs"
}
variable "security_groups" {
description = "comma separated list of security group IDs"
}
variable "port" {
description = "Instance port"
default = 80
}
zz
main.tf
resource "aws_elb" "main" {
name = "${var.name}"
cross_zone_load_balancing = true
subnets = ["${split(",", var.subnet_ids)}"]
security_groups = ["${split(",",var.security_groups)}"]
listener {
lb_port = 80
lb_protocol = "http"
instance_port = "${var.port}"
instance_protocol = "http"
}
. . .
zz
outputs.tf
output "elb_name" {
value = "${aws_elb.main.name}"
}
output "elb_id" {
value = "${aws_elb.main.id}"
}
output "elb_dns_name" {
value = "${aws_elb.main.dns_name}"
}
output "elb_zone_id" {
value = "${aws_elb.main.zone_id}"
}
zz
Module usage
Using modules in Terraform is very similar to built-in
resources:
module "elb" {
source = “./tf_elb”
name = "myelb"
port = "80"
health_check_url = "HTTP:80/"
}
zz
Module usage - remote git source
The module can live in the same place with the code
using it (subfolder) or it can be in a separate repo
(recommended).
module "elb" {
source =
"github.com/sepulworld/tf_elb.git?ref=v0.0.1"
name = "myelb"
port = "80"
health_check_url = "HTTP:80/"
}
zz
Module usage - multiple instances
We can instantiate a module multiple times:
module "elb-frontend" {
source = “./tf_elb”
name = "frontend"
port = "80"
health_check_url = "HTTP:80/"
}
module "elb-internal" {
source = “./tf_elb”
name = "internal"
port = "8080"
health_check_url = "HTTP:8080/health"
}
zz
Module usage - get sources
Finally, before using the module we need to first
download it from the source, using terraform get:
terraform get -update
Get: git::https://github.com/sepulworld/tf_asg.git?ref=v0.0.3
(update)
Get: git::https://github.com/sepulworld/tf_elb.git?ref=v0.0.1
(update)
zz
So are modules helping solve our challenges?
Let’s see…
✓ code duplication | code drift
✓ management & maintenance
✓ versioning
✓ testing
zz
Lessons learned
• Use variables for everything; have sane defaults.
• Document your modules; we use a changelog to
have a history of all bug fixes and new features.
• Use separate git repositories for your modules and
use tags to release new versions of the module.
• Test your modules (ideally automatically); we use
terraform validate on all commits and a test run on
new releases.
• Be aware that different versions of terraform might
behave differently.
zz
Lessons learned
• Separate your terraform code to minimize the
impact of a failure; we use something like:
global (global resources like IAM, cloudtrail, s3, etc.)
└ users
development (dev environment)
└ core (base resources like vpc, sg, etc.)
└ db (persistent storage, rds, etc.)
└ microservice1 (resources for services like asg, elb, route53, etc.)
production (prod environment)
└ core (base resources like vpc, sg, etc.)
└ db (persistent storage, rds, etc.)
└ microservice2 (resources for services like asg, elb, route53, etc.)
zz
Lessons learned
• Use terraform_remote_state to share the state
between different terraform runs.
data "terraform_remote_state" "vcp" {
backend = "s3"
config {
bucket = “terraform-state-s3-bucket"
key = "dev-vpc-us-west-2"
}
}
resource "aws_instance" "foo" {
# ...
subnet_id = "${data.terraform_remote_state.vpc.subnet_id}"
}
zz
Lessons learned
• Terraform new features and improvements added
by a new version might break the run on an older
version. Always tag new releases of a module that
might break older version runs.
• If a new resource or a new argument to an existing
one was introduced that will be seen as an error on
older versions.
resource "aws_elasticsearch_domain" "es" {
elasticsearch_version = “${var.es_version}” # added in 0.7.1
domain_name = "${var.es_domain_name}"
zz
Terraform version manager
Use different versions of terraform (tfenv):
https://github.com/kamatama41/tfenv
tfenv install 0.7.7
install Terraform 0.7.7
get archive from
https://releases.hashicorp.com/terraform/0.7.7/terraform_0.7.7_darw
in_amd64.zip
% Total % Received % Xferd Average Speed Time Time
Time Current
Dload Upload Total Spent
Left Speed
100 16.8M 100 16.8M 0 0 7163k 0 0:00:02 0:00:02 --
:--:-- 7167k
Archive: /tmp/terraform_0.7.7_darwin_amd64.zip
inflating: /Users/marius/bin/tfenv/versions/0.7.7/terraform
the installation 0.7.7 was successful!!!
zz
Future improvements
• Conditionals, conditionals, conditionals…
• Terraform language is very limited and this prevents us
from writing ‘real’ reusable modules; at this time we are
using all sort of count related hacks to overcome
conditional limitations but hopefully we’ll have better
solutions in the future.
• Terraform state locking
• Better handling of multiple versions of Terraform
• Testing improvements
zz
Demo
Infrastructure Timeline
zz
Challenges and No Silver Bullets
1. Doesn’t work with systems that require code to be in
consistent state. For this a Blue/Green type of deployment is
required.
2. Clean up of old AMIs needs to be handled external to
Packer and Terraform
3. Requires application to be engineered for the Cloud
4. Autoscaling Group failure scenarios don’t automatically
cleanup
zz
https://github.com/sepulworld/tf_elb
https://github.com/sepulworld/tf_asg
https://github.com/sepulworld/terraform-examples
Demo links:
Questions!

More Related Content

What's hot

Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...Amazon Web Services
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform TrainingYevgeniy Brikman
 
Building infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps KrakowBuilding infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps KrakowAnton Babenko
 
Getting Started with Infrastructure as Code
Getting Started with Infrastructure as CodeGetting Started with Infrastructure as Code
Getting Started with Infrastructure as CodeWinWire Technologies Inc
 
Introduction To Terraform
Introduction To TerraformIntroduction To Terraform
Introduction To TerraformSasitha Iresh
 
Terraform modules restructured
Terraform modules restructuredTerraform modules restructured
Terraform modules restructuredAmi Mahloof
 
An introduction to terraform
An introduction to terraformAn introduction to terraform
An introduction to terraformJulien Pivotto
 
Reusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modulesReusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modulesYevgeniy Brikman
 
Terraform Introduction
Terraform IntroductionTerraform Introduction
Terraform Introductionsoniasnowfrog
 
Microsoft Azure IaaS and Terraform
Microsoft Azure IaaS and TerraformMicrosoft Azure IaaS and Terraform
Microsoft Azure IaaS and TerraformAlex Mags
 

What's hot (20)

Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
Using HashiCorp’s Terraform to build your infrastructure on AWS - Pop-up Loft...
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform Training
 
Building infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps KrakowBuilding infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps Krakow
 
Advanced Terraform
Advanced TerraformAdvanced Terraform
Advanced Terraform
 
Terraform
TerraformTerraform
Terraform
 
Final terraform
Final terraformFinal terraform
Final terraform
 
Getting Started with Infrastructure as Code
Getting Started with Infrastructure as CodeGetting Started with Infrastructure as Code
Getting Started with Infrastructure as Code
 
Terraform Basics
Terraform BasicsTerraform Basics
Terraform Basics
 
Terraform
TerraformTerraform
Terraform
 
Terraform
TerraformTerraform
Terraform
 
Introduction to IAC and Terraform
Introduction to IAC and Terraform Introduction to IAC and Terraform
Introduction to IAC and Terraform
 
Introduction To Terraform
Introduction To TerraformIntroduction To Terraform
Introduction To Terraform
 
Terraform modules restructured
Terraform modules restructuredTerraform modules restructured
Terraform modules restructured
 
An introduction to terraform
An introduction to terraformAn introduction to terraform
An introduction to terraform
 
Introduce to Terraform
Introduce to TerraformIntroduce to Terraform
Introduce to Terraform
 
Terraform
TerraformTerraform
Terraform
 
Terraform on Azure
Terraform on AzureTerraform on Azure
Terraform on Azure
 
Reusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modulesReusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modules
 
Terraform Introduction
Terraform IntroductionTerraform Introduction
Terraform Introduction
 
Microsoft Azure IaaS and Terraform
Microsoft Azure IaaS and TerraformMicrosoft Azure IaaS and Terraform
Microsoft Azure IaaS and Terraform
 

Viewers also liked

Infrastructure as code with Terraform
Infrastructure as code with TerraformInfrastructure as code with Terraform
Infrastructure as code with TerraformSam Bashton
 
Terraform: Configuration Management for Cloud Services
Terraform: Configuration Management for Cloud ServicesTerraform: Configuration Management for Cloud Services
Terraform: Configuration Management for Cloud ServicesMartin Schütte
 
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)Stephane Jourdan
 
Managing AWS infrastructure using CloudFormation
Managing AWS infrastructure using CloudFormationManaging AWS infrastructure using CloudFormation
Managing AWS infrastructure using CloudFormationAnton Babenko
 
Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)Radek Simko
 
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...Yevgeniy Brikman
 

Viewers also liked (6)

Infrastructure as code with Terraform
Infrastructure as code with TerraformInfrastructure as code with Terraform
Infrastructure as code with Terraform
 
Terraform: Configuration Management for Cloud Services
Terraform: Configuration Management for Cloud ServicesTerraform: Configuration Management for Cloud Services
Terraform: Configuration Management for Cloud Services
 
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
Using Terraform.io (Human Talks Montpellier, Epitech, 2014/09/09)
 
Managing AWS infrastructure using CloudFormation
Managing AWS infrastructure using CloudFormationManaging AWS infrastructure using CloudFormation
Managing AWS infrastructure using CloudFormation
 
Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)
 
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...Infrastructure as code: running microservices on AWS using Docker, Terraform,...
Infrastructure as code: running microservices on AWS using Docker, Terraform,...
 

Similar to Terraform Modules and Continuous Deployment

Terraform Modules Restructured
Terraform Modules RestructuredTerraform Modules Restructured
Terraform Modules RestructuredDoiT International
 
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)Adin Ermie
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Terraform for azure: the good, the bad and the ugly -
Terraform for azure: the good, the bad and the ugly - Terraform for azure: the good, the bad and the ugly -
Terraform for azure: the good, the bad and the ugly - Giulio Vian
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerCalvin French-Owen
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныTimur Safin
 
mjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profilingmjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profilingHaim Yadid
 
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoverageTesting NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoveragemlilley
 
Apache Submarine: Unified Machine Learning Platform
Apache Submarine: Unified Machine Learning PlatformApache Submarine: Unified Machine Learning Platform
Apache Submarine: Unified Machine Learning PlatformWangda Tan
 
DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your TeamGR8Conf
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...bobmcwhirter
 
Terraform - Taming Modern Clouds
Terraform  - Taming Modern CloudsTerraform  - Taming Modern Clouds
Terraform - Taming Modern CloudsNic Jackson
 
20100425 Configuration Management With Puppet Lfnw
20100425 Configuration Management With Puppet Lfnw20100425 Configuration Management With Puppet Lfnw
20100425 Configuration Management With Puppet Lfnwgarrett honeycutt
 
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...NETWAYS
 

Similar to Terraform Modules and Continuous Deployment (20)

Terraform Modules Restructured
Terraform Modules RestructuredTerraform Modules Restructured
Terraform Modules Restructured
 
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
 
DevOps for database
DevOps for databaseDevOps for database
DevOps for database
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
TIAD : Automating the modern datacenter
TIAD : Automating the modern datacenterTIAD : Automating the modern datacenter
TIAD : Automating the modern datacenter
 
Effective terraform
Effective terraformEffective terraform
Effective terraform
 
Terraform training 🎒 - Basic
Terraform training 🎒 - BasicTerraform training 🎒 - Basic
Terraform training 🎒 - Basic
 
Terraform for azure: the good, the bad and the ugly -
Terraform for azure: the good, the bad and the ugly - Terraform for azure: the good, the bad and the ugly -
Terraform for azure: the good, the bad and the ugly -
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and Power
 
Новый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоныНовый InterSystems: open-source, митапы, хакатоны
Новый InterSystems: open-source, митапы, хакатоны
 
mjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profilingmjprof: Monadic approach for JVM profiling
mjprof: Monadic approach for JVM profiling
 
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoverageTesting NodeJS with Mocha, Should, Sinon, and JSCoverage
Testing NodeJS with Mocha, Should, Sinon, and JSCoverage
 
Terraform 101
Terraform 101Terraform 101
Terraform 101
 
Apache Submarine: Unified Machine Learning Platform
Apache Submarine: Unified Machine Learning PlatformApache Submarine: Unified Machine Learning Platform
Apache Submarine: Unified Machine Learning Platform
 
DevOps Enabling Your Team
DevOps Enabling Your TeamDevOps Enabling Your Team
DevOps Enabling Your Team
 
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...TorqueBox: The beauty of Ruby with the power of JBoss.  Presented at Devnexus...
TorqueBox: The beauty of Ruby with the power of JBoss. Presented at Devnexus...
 
Terraform - Taming Modern Clouds
Terraform  - Taming Modern CloudsTerraform  - Taming Modern Clouds
Terraform - Taming Modern Clouds
 
20100425 Configuration Management With Puppet Lfnw
20100425 Configuration Management With Puppet Lfnw20100425 Configuration Management With Puppet Lfnw
20100425 Configuration Management With Puppet Lfnw
 
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
OSDC 2015: Mitchell Hashimoto | Automating the Modern Datacenter, Development...
 
De Java 8 ate Java 14
De Java 8 ate Java 14De Java 8 ate Java 14
De Java 8 ate Java 14
 

Recently uploaded

Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...tanu pandey
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 

Recently uploaded (20)

Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
NFPA 5000 2024 standard .
NFPA 5000 2024 standard                                  .NFPA 5000 2024 standard                                  .
NFPA 5000 2024 standard .
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Wakad Call Me 7737669865 Budget Friendly No Advance Booking
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 

Terraform Modules and Continuous Deployment

  • 1. zz Terraform Modules and Continuous Deployments San Francisco Infrastructure as Code Meetup
  • 2. zz Your speakers… • Zane Williamson • Trulia Sr. DevOps • Twitter @zane_williamson • Github @sepulworld • Marius Ducea • AWS Consultant • Twitter @mariusducea • Github @mdxp
  • 3. zz Overview 1. The Challenge 2. System overview 3. Why we chose Terraform and Packer for Continuous Deployment 4. Terraform modules and how we are using them 5. Demo a continuous deployment with Terraform and Packer
  • 4. zz The Challenge • Deploying an array of micro services • Multiple teams • Repeatable Cloud configuration • Peer reviewed infrastructure changes • Tooling flexibility • As simple as possible for non experts
  • 5. zz System Overview • Cloud Provider is AWS • Micro-services APIs with ELB endpoints • Micro-services acting as worker clusters without ELB endpoints • A common shared backend
  • 6. zz System Overview Terraform Managed • Kafka cluster • SQS • s3 • RDS • EMR (Hbase) • VPC, subnets, routes, etc
  • 7. zz Why We Chose Packer to Build Images 1. Dev and ops personnel were already familiar with Packer 2. Allowed us to reuse Puppet modules 3. Multiple outputs (VirtualBox, Docker, AMI, etc) 4. Able to embed in the micro-service code base 5. Easy to call from Jenkins server
  • 8. zz Why we chose Terraform to Manage Infrastructure 1. CloudFormation was limited to AWS services 2. Libraries like Boto and Fog required programming skills and don’t manage state as well 3. Some developers and operations personnel were already familiar with Terraform 4. Easy to integrate into Jenkins which is the preferred build and deployment platform of most of our teams 5. Ability to put the Terraform directly into the code base for each micro- service 6. Leverage Terraform Modules and the capability to use a Git repo as a source
  • 9. zz Challenges we faced early on Multiple teams working with terraform • code duplication | code drift • management & maintenance • versioning • testing
  • 10. zz Terraform modules The solution to all our problems?
  • 11. zz Terraform modules basics • Modules are used to create reusable components in Terraform as well as for basic code organization. • Modules are very easy to create and use. • A module is technically just a folder with some terraform templates.
  • 12. zz Terraform modules - example ELB module elb ├── CHANGELOG.md ├── README.md ├── main.tf ├── outputs.tf ├── test │ ├── aws.tf │ └── test.tf └── variables.tf
  • 13. zz variables.tf variable "name" { default = "dev-elb" } variable "subnet_ids" { description = "comma separated list of subnet IDs" } variable "security_groups" { description = "comma separated list of security group IDs" } variable "port" { description = "Instance port" default = 80 }
  • 14. zz main.tf resource "aws_elb" "main" { name = "${var.name}" cross_zone_load_balancing = true subnets = ["${split(",", var.subnet_ids)}"] security_groups = ["${split(",",var.security_groups)}"] listener { lb_port = 80 lb_protocol = "http" instance_port = "${var.port}" instance_protocol = "http" } . . .
  • 15. zz outputs.tf output "elb_name" { value = "${aws_elb.main.name}" } output "elb_id" { value = "${aws_elb.main.id}" } output "elb_dns_name" { value = "${aws_elb.main.dns_name}" } output "elb_zone_id" { value = "${aws_elb.main.zone_id}" }
  • 16. zz Module usage Using modules in Terraform is very similar to built-in resources: module "elb" { source = “./tf_elb” name = "myelb" port = "80" health_check_url = "HTTP:80/" }
  • 17. zz Module usage - remote git source The module can live in the same place with the code using it (subfolder) or it can be in a separate repo (recommended). module "elb" { source = "github.com/sepulworld/tf_elb.git?ref=v0.0.1" name = "myelb" port = "80" health_check_url = "HTTP:80/" }
  • 18. zz Module usage - multiple instances We can instantiate a module multiple times: module "elb-frontend" { source = “./tf_elb” name = "frontend" port = "80" health_check_url = "HTTP:80/" } module "elb-internal" { source = “./tf_elb” name = "internal" port = "8080" health_check_url = "HTTP:8080/health" }
  • 19. zz Module usage - get sources Finally, before using the module we need to first download it from the source, using terraform get: terraform get -update Get: git::https://github.com/sepulworld/tf_asg.git?ref=v0.0.3 (update) Get: git::https://github.com/sepulworld/tf_elb.git?ref=v0.0.1 (update)
  • 20. zz So are modules helping solve our challenges? Let’s see… ✓ code duplication | code drift ✓ management & maintenance ✓ versioning ✓ testing
  • 21. zz Lessons learned • Use variables for everything; have sane defaults. • Document your modules; we use a changelog to have a history of all bug fixes and new features. • Use separate git repositories for your modules and use tags to release new versions of the module. • Test your modules (ideally automatically); we use terraform validate on all commits and a test run on new releases. • Be aware that different versions of terraform might behave differently.
  • 22. zz Lessons learned • Separate your terraform code to minimize the impact of a failure; we use something like: global (global resources like IAM, cloudtrail, s3, etc.) └ users development (dev environment) └ core (base resources like vpc, sg, etc.) └ db (persistent storage, rds, etc.) └ microservice1 (resources for services like asg, elb, route53, etc.) production (prod environment) └ core (base resources like vpc, sg, etc.) └ db (persistent storage, rds, etc.) └ microservice2 (resources for services like asg, elb, route53, etc.)
  • 23. zz Lessons learned • Use terraform_remote_state to share the state between different terraform runs. data "terraform_remote_state" "vcp" { backend = "s3" config { bucket = “terraform-state-s3-bucket" key = "dev-vpc-us-west-2" } } resource "aws_instance" "foo" { # ... subnet_id = "${data.terraform_remote_state.vpc.subnet_id}" }
  • 24. zz Lessons learned • Terraform new features and improvements added by a new version might break the run on an older version. Always tag new releases of a module that might break older version runs. • If a new resource or a new argument to an existing one was introduced that will be seen as an error on older versions. resource "aws_elasticsearch_domain" "es" { elasticsearch_version = “${var.es_version}” # added in 0.7.1 domain_name = "${var.es_domain_name}"
  • 25. zz Terraform version manager Use different versions of terraform (tfenv): https://github.com/kamatama41/tfenv tfenv install 0.7.7 install Terraform 0.7.7 get archive from https://releases.hashicorp.com/terraform/0.7.7/terraform_0.7.7_darw in_amd64.zip % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 16.8M 100 16.8M 0 0 7163k 0 0:00:02 0:00:02 -- :--:-- 7167k Archive: /tmp/terraform_0.7.7_darwin_amd64.zip inflating: /Users/marius/bin/tfenv/versions/0.7.7/terraform the installation 0.7.7 was successful!!!
  • 26. zz Future improvements • Conditionals, conditionals, conditionals… • Terraform language is very limited and this prevents us from writing ‘real’ reusable modules; at this time we are using all sort of count related hacks to overcome conditional limitations but hopefully we’ll have better solutions in the future. • Terraform state locking • Better handling of multiple versions of Terraform • Testing improvements
  • 28. zz Challenges and No Silver Bullets 1. Doesn’t work with systems that require code to be in consistent state. For this a Blue/Green type of deployment is required. 2. Clean up of old AMIs needs to be handled external to Packer and Terraform 3. Requires application to be engineered for the Cloud 4. Autoscaling Group failure scenarios don’t automatically cleanup