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

Terraform modules and best-practices - September 2018
Terraform modules and best-practices - September 2018Terraform modules and best-practices - September 2018
Terraform modules and best-practices - September 2018Anton Babenko
 
Terraform introduction
Terraform introductionTerraform introduction
Terraform introductionJason Vance
 
Terraform: An Overview & Introduction
Terraform: An Overview & IntroductionTerraform: An Overview & Introduction
Terraform: An Overview & IntroductionLee Trout
 
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 Terraform
Introduction To TerraformIntroduction To Terraform
Introduction To TerraformSasitha Iresh
 
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
 
Terraform 0.9 + good practices
Terraform 0.9 + good practicesTerraform 0.9 + good practices
Terraform 0.9 + good practicesRadek Simko
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformAdin Ermie
 
Terraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeTerraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeMartin Schütte
 
Terraform modules and (some of) best practices
Terraform modules and (some of) best practicesTerraform modules and (some of) best practices
Terraform modules and (some of) best practicesAnton Babenko
 

What's hot (20)

Terraform modules and best-practices - September 2018
Terraform modules and best-practices - September 2018Terraform modules and best-practices - September 2018
Terraform modules and best-practices - September 2018
 
Terraform
TerraformTerraform
Terraform
 
Terraform
TerraformTerraform
Terraform
 
Terraform introduction
Terraform introductionTerraform introduction
Terraform introduction
 
Terraform: An Overview & Introduction
Terraform: An Overview & IntroductionTerraform: An Overview & Introduction
Terraform: An Overview & Introduction
 
Effective terraform
Effective terraformEffective terraform
Effective terraform
 
Terraform Basics
Terraform BasicsTerraform Basics
Terraform Basics
 
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)
 
Introduction To Terraform
Introduction To TerraformIntroduction To Terraform
Introduction To Terraform
 
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...
 
Terraform
TerraformTerraform
Terraform
 
Code quality for Terraform
Code quality for TerraformCode quality for Terraform
Code quality for Terraform
 
Terraform
TerraformTerraform
Terraform
 
Terraform
TerraformTerraform
Terraform
 
Terraform 0.9 + good practices
Terraform 0.9 + good practicesTerraform 0.9 + good practices
Terraform 0.9 + good practices
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using Terraform
 
Terraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeTerraform -- Infrastructure as Code
Terraform -- Infrastructure as Code
 
Final terraform
Final terraformFinal terraform
Final terraform
 
Terraform modules and (some of) best practices
Terraform modules and (some of) best practicesTerraform modules and (some of) best practices
Terraform modules and (some of) best practices
 
Terraform
TerraformTerraform
Terraform
 

Viewers also liked

Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform TrainingYevgeniy Brikman
 
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 (7)

Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform Training
 
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

Reusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modulesReusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modulesYevgeniy Brikman
 
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
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy Systemadrian_nye
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Viral Solani
 

Similar to Terraform Modules and Continuous Deployment (20)

Reusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modulesReusable, composable, battle-tested Terraform modules
Reusable, composable, battle-tested Terraform modules
 
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
 
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
 
A Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy SystemA Fabric/Puppet Build/Deploy System
A Fabric/Puppet Build/Deploy System
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 

Recently uploaded

(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 

Recently uploaded (20)

(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 

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