SlideShare a Scribd company logo
Managing Microservices
using Terraform, Docker, and the Cloud
Given by Derek C. Ashmore
June 27, 2017
©2017 Derek C. Ashmore, All Rights Reserved 1
Who am I?
• Professional Geek
since 1987
• Java/J2EE/Java EE
since 1999
• AWS since 2010
• Specialties
• Refactoring
• Performance
Tuning
• Yes – I still code!
©2017 Derek C. Ashmore, All Rights Reserved 2
Lab Preparation
• This lab has set-up instructions on my github
– https://github.com/Derek-Ashmore/terraform-hands-on-lab
• Set up for the lab during the discussion!
– It is socially acceptable
– I will not wait for you to do the setup!
– Feel free to treat the lab as a demo
©2017 Derek C. Ashmore, All Rights Reserved 3
Discussion Resources
• This slide deck
– http://www.slideshare.net/derekashmore
• The hands-on-lab code and setup instructions
– https://github.com/Derek-Ashmore/terraform-hands-on-lab
• The Moneta microservice (written in Java)
– https://github.com/Derek-Ashmore/moneta
• Slide deck has hyper-links!
– Don’t bother writing down URLs
©2017 Derek C. Ashmore, All Rights Reserved 4
Agenda
Microservices,
Docker, and
the Cloud
Cloud with
Terraform
Terraform’s
Competitors
Summary /
Q&A
©2017 Derek C. Ashmore, All Rights Reserved 5
What are Microservices?
• No concrete definition
• Common microservice traits
– Single functional purpose
• Most/all changes only impact one service
• Not dependent on execution context
– “loosely coupled”
– Independent process/jvm
– Stateless
– Standard Interface (typically Web Service/REST)
– Analogy: Stereo system, Linux utilities
©2017 Derek C. Ashmore, All Rights Reserved 6
Microservices Application Architecture
• Separate Databases
• Eventual Consistency
• More network activity
©2017 Derek C. Ashmore, All Rights Reserved 7
Typical Microservice Library
©2017 Derek C. Ashmore, All Rights Reserved 8
Microservice Deployments
©2017 Derek C. Ashmore, All Rights Reserved 9
Docker
• Is a “mini VM”
• runs a linux kernal
• Compare to shipping
container
• Standard “connections” to
outside world
• Supported formally by
Oracle, Tomcat, Jboss, and
many more
10©2017 Derek C. Ashmore, All Rights Reserved
Package Once, Run Anywhere!
Why Docker?
• Docker is Win-Win
– Easier for OPS and system administrators
• All software looks the same
• Standard interface for disk and network resources
– Containers can be “linked”
• Inherently automated
– Easier for developers
• Fewer environment difference issues
• Less to communicate to OPS / system administrators
• Easy to leverage work of others (docker-hub)
– If you haven’t tried Docker yet – you should!
©2017 Derek C. Ashmore, All Rights Reserved 11
Docker Build File
• Docker file for Microservice Moneta
– Base Image
• FROM java:8-jre
– Expose Folder
• VOLUME /config
– Download Moneta Jar Release
• RUN curl -SL "$MONETA_URL" -o moneta-dropwizard.jar
– Expose Ports
• EXPOSE 8080 8081
– Run It
• ENTRYPOINT exec java -classpath $CLASSPATH -server $JAVA_OPTS
• -jar moneta-dropwizard.jar server /config/moneta-dropwizard.yaml
©2017 Derek C. Ashmore, All Rights Reserved 12
Running a Docker Image
• The Docker Run Command
– Exposes Ports
– Attaches Disk
– Passes/sets Environment Variables
– Allocates Memory
• Example from the Lab Portion
– export JAVA_OPTS="-Xmx768m”
– docker pull derekashmore/moneta-dropwizard:0.9.3-alpha
– docker run -d -p 80:8080 -m 800m -e JAVA_OPTS
– -v $PWD/moneta-config:/config derekashmore/moneta-dropwizard:0.9.3-alpha
©2017 Derek C. Ashmore, All Rights Reserved 13
Typical Microservice Install at AWS
©2017 Derek C. Ashmore, All Rights Reserved 14
• Horizontal scaling is supported
• Multiple copies of microservice / web application
running at the same time
• Elastic Load Balancer distributes load across
copies of your service
• Sticky sessions available
• ELB can use health checks
• Autoscaling Groups scale number of copies up
and down based on rules you give it
• CPU Utilization or other metrics
• Autoscaling Groups distribute across availability
zones for availability
Network Security
©2017 Derek C. Ashmore, All Rights Reserved 15
Network Security (con’t)
• Public vs. Private subnets
– Specified by Routes and Network ACLs
– Public subnets can be used from the internet
• Web Servers typically placed here
– Private subnets only used within your Virtual Network
• Access from the internet just not possible
– Even if a public IP is assigned
• Microservices
• Databases
• Messaging traffic
• It’s common to add SSO (for web applications) and OAUTH (for
microservices) above that
©2017 Derek C. Ashmore, All Rights Reserved 16
Security Groups
• Security Groups provide Inbound/Outbound rules for individual instances
– Think of as “an assignable firewall”
– Multiple rules per VM allowed.
– Easy additional layer of security
– No changes to applications or services needed.
• Examples
– Web Servers  Allow port 80 and 443 from anywhere
– Web Servers  Allow SSH/SFTP only from within the VPC
• Security Groups and be associated
– Financial Microservice Allow port 443 only from VMs belonging to security group
FINANCIAL_SERVICE_CLIENT_SG
– Oracle Database  Allow port 1521 only from VMs belonging to security group
ORACLE_CLIENT_SG
©2017 Derek C. Ashmore, All Rights Reserved 17
Managing Cloud Assets
• Objectives
– Managing Complexity
• Environment Consistency
• Environment Lifecycle Support
• Ease of change
• Reuse
– Manage risk of change
– Mitigate Cloud Lock-in
• Infrastructure as Code
– Reusable Infrastructure Components
• Leverage work/expertise of others
• Big problem  Smaller manageable problems
– Change Tracking – Source Control
©2017 Derek C. Ashmore, All Rights Reserved 18
Agenda
Microservices,
Docker, and
the Cloud
Cloud with
Terraform
Terraform’s
Competitors
Summary /
Q&A
©2017 Derek C. Ashmore, All Rights Reserved 19
Terraform
• Cloud Management
– Open Source
• Very active community
– Extensible to any cloud vendor
• AWS, Azure, GCP, AliCloud, Digital Ocean, OpenStack
– Supported for Cloud Support products
• Chef, Consul, Kubernetes, Datadog
• 62 Providers as of April, 2017 and growing
©2017 Derek C. Ashmore, All Rights Reserved 20
Terraform HCL
• Declarative Language
– Describe what the end product contains
• Terraform figures out how to get there
– Terraform Resources
• Describes deployed artifacts
– Network  Virtual Networks, Subnets, Network ACLs, Gateways, ELB/ALB
– Hosts  Virtual Machines, Databases
– Security  Security groups/policies/roles/groups/users
– Much more
©2017 Derek C. Ashmore, All Rights Reserved 21
Terraform Basics
• Declarative Programming
– All *.tf files loaded  Terraform decides execution order
– No GUI  All command line and text editor
• Top Commands
– Terraform plan  Describes planned changes
– Terraform apply  Makes planned changes
– Terraform taint  Forces re-creation of a resource
– Terraform destroy  deletes all resources
©2017 Derek C. Ashmore, All Rights Reserved 22
Terraform Resources
• AWS Subnet Resource
– Count = 3  Three subnets created
– Availability Zones come from a data source (lookup)
– CIDR blocks are input variables
• Sample source
©2017 Derek C. Ashmore, All Rights Reserved 23
Terraform Data Sources
• Example Data Sources (lookups)
• Sample source
©2017 Derek C. Ashmore, All Rights Reserved 24
Terraform Providers
• Example Provider
• Sample AWS source
• Azure Provider
©2017 Derek C. Ashmore, All Rights Reserved 25
Terraform Input Variables
• Example Provider
• Sample source
©2017 Derek C. Ashmore, All Rights Reserved 26
Reusing Terraform Templates
• Example Template Reuse
• Sample source
©2017 Derek C. Ashmore, All Rights Reserved 27
Typical Project Structure
©2017 Derek C. Ashmore, All Rights Reserved 28
Terraform State
• Terraform stores state
– Local file terraform.tfstate
• Teams need to manage state centrally
– Terraform Backends
• Locks so that only one person at a time can update
• Remote storage
– S3, Azure containers, Google cloud storage, etc.
©2017 Derek C. Ashmore, All Rights Reserved 29
Agenda
Microservices,
Docker, and
the Cloud
Cloud with
Terraform
Terraform’s
Competitors
Summary /
Q&A
©2017 Derek C. Ashmore, All Rights Reserved 30
Terraform vs. Ansible/Chef
• Terraform designed for infrastructure
– Not designed for configuration management
– Terraform deploys images
• Not good at maintaining what’s on those images
• If deployments update existing VMs
– You need Ansible, Chef, or Puppet
• If deployments are “new” VMs
– Terraform can handle deployments too
©2017 Derek C. Ashmore, All Rights Reserved 31
Paradigm Shift
• Deployment as new infrastructure
– New version  new VMs
• Software versions baked into images
– Advantages
• Facilitates Canary Deployments
– Route53 Routing Policies
• Go-live operation has less risk
– Deploy/Backout is just a load balancer switch
– Disadvantages
• More moving parts
• Impossible to do manually
©2017 Derek C. Ashmore, All Rights Reserved 32
Terraform vs CloudFormation
Terraform
• Scripting skills translate to Azure,
Google Cloud, etc.
• Less verbose (>50%)
• Data Lookups
• Custom Plug-ins possible
• Active Community Support
CloudFormation
• Quicker to follow AWS enhancements
• GUI support
• Automatic centralized state
• Vendor Support
©2017 Derek C. Ashmore, All Rights Reserved 33
Further Reading
• This slide deck
– http://www.slideshare.net/derekashmore
• The Gruntwork Blog
– https://blog.gruntwork.io/
©2017 Derek C. Ashmore, All Rights Reserved 34
Questions?
• Derek Ashmore:
– Blog: www.derekashmore.com
– LinkedIn: www.linkedin.com/in/derekashmore
• Connect Invites from attendees welcome
– Twitter: https://twitter.com/Derek_Ashmore
– GitHub: https://github.com/Derek-Ashmore
– Book: http://dvtpress.com/
©2017 Derek C. Ashmore, All Rights Reserved 35
HANDS-ON LAB
©2017 Derek C. Ashmore, All Rights Reserved 36
Lab Resources and Objectives
• This lab has set-up instructions on my github
– https://github.com/Derek-Ashmore/terraform-hands-on-lab
• You will experience
– Creating a network and deploying VMs at AWS using Terraform
– You will learn how to use Terraform Modules to leverage your code
across applications
– You will see the output of your work live on the internet.
• Java Microservice to be deployed
– https://github.com/Derek-Ashmore/moneta
©2017 Derek C. Ashmore, All Rights Reserved 37
Sample Java/EE Microservice
• Moneta – Greek goddess of ‘memory’
– Open source: https://github.com/Derek-Ashmore/moneta
• Objective:
– Provide a RESTful Web Service interface to a relational database
• Feature set:
– Provides generic ‘core’ services
– Returns Json-formatted data
– Supports startRow and maxRows query options
– Supports a security call-out
– Built-in Dropwizard, Spring Boot, and War-file deployments
• Sample contract spec – currently read-only (writes in progress)
– /moneta/topics – lists ‘topics’ of information
• E.g. – Topic Customer configured
– /moneta/topic/customers?startRow=5&maxRows=25
– /moneta/topic/customer/111-222-333
• Docker deployment
– https://hub.docker.com/r/derekashmore/moneta-dropwizard/
©2015 Derek C. Ashmore, All Rights Reserved 38
The Lab Network at AWS
©2017 Derek C. Ashmore, All Rights Reserved 39
Questions?
• Derek Ashmore:
– Blog: www.derekashmore.com
– LinkedIn: www.linkedin.com/in/derekashmore
• Connect Invites from attendees welcome
– Twitter: https://twitter.com/Derek_Ashmore
– GitHub: https://github.com/Derek-Ashmore
– Book: http://dvtpress.com/
©2017 Derek C. Ashmore, All Rights Reserved 40
terraform destroy

More Related Content

PDF
Microservices with Terraform, Docker and the Cloud. IJug Chicago 2017-06-06
PDF
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26
PDF
Containers, microservices and serverless for realists
PPTX
Docker Datacenter Overview and Production Setup Slides
PPTX
Containers vs. VMs: It's All About the Apps!
PDF
Bare-metal, Docker Containers, and Virtualization: The Growing Choices for Cl...
PDF
Docker and Containers overview - Docker Workshop
PPTX
7+1 myths of the new os
Microservices with Terraform, Docker and the Cloud. IJug Chicago 2017-06-06
Refactoring Into Microservices. Chicago Coders Conference 2017-06-26
Containers, microservices and serverless for realists
Docker Datacenter Overview and Production Setup Slides
Containers vs. VMs: It's All About the Apps!
Bare-metal, Docker Containers, and Virtualization: The Growing Choices for Cl...
Docker and Containers overview - Docker Workshop
7+1 myths of the new os

What's hot (20)

PDF
Docker, the Future of DevOps
PDF
DockerCon EU 2015: Day 1 General Session
PPTX
DockerCon EU 2015: Persistent, stateful services with docker cluster, namespa...
PPTX
Docker Practice in Alibaba Cloud by Li Yi (Mark) & Zuhe Li (Sogo)
PPTX
Virtualization Vs. Containers
PDF
Orchestrating Linux Containers while tolerating failures
PPTX
Intro Docker october 2013
PDF
Securing your Containers
PDF
Docker in pratice -chenyifei
PPTX
Weave User Group Talk - DockerCon 2017 Recap
PDF
Docker Introduction
PPTX
Oracle database on Docker Container
PDF
Docker in Production, Look No Hands! by Scott Coulton
PDF
The ABC of Docker: The Absolute Best Compendium of Docker
PDF
Docker Containers Deep Dive
PPTX
Docker Bday #5, SF Edition: Introduction to Docker
PPTX
DockerCon Keynote Ben Golub
ODP
Practical Container Security by Mrunal Patel and Thomas Cameron, Red Hat
PDF
Docker Online Meetup: Infrakit update and Q&A
PPTX
Docker Basic to Advance
Docker, the Future of DevOps
DockerCon EU 2015: Day 1 General Session
DockerCon EU 2015: Persistent, stateful services with docker cluster, namespa...
Docker Practice in Alibaba Cloud by Li Yi (Mark) & Zuhe Li (Sogo)
Virtualization Vs. Containers
Orchestrating Linux Containers while tolerating failures
Intro Docker october 2013
Securing your Containers
Docker in pratice -chenyifei
Weave User Group Talk - DockerCon 2017 Recap
Docker Introduction
Oracle database on Docker Container
Docker in Production, Look No Hands! by Scott Coulton
The ABC of Docker: The Absolute Best Compendium of Docker
Docker Containers Deep Dive
Docker Bday #5, SF Edition: Introduction to Docker
DockerCon Keynote Ben Golub
Practical Container Security by Mrunal Patel and Thomas Cameron, Red Hat
Docker Online Meetup: Infrakit update and Q&A
Docker Basic to Advance
Ad

Similar to Microservices with Terraform, Docker and the Cloud. Chicago Coders Conference 2017-06-27 (20)

PDF
Microservices with Terraform, Docker and the Cloud. JavaOne 2017 2017-10-02
PDF
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
PDF
Managing AWS Using Terraform AWS Chicago-Suburbs 2018-01-18
PDF
OpenStack Operations Guide 1st Edition Tom Fifield
PDF
Managing AWS Using Terraform AWS Atlanta 2018-07-18
PDF
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
PDF
Terraform-2.pdf
PPTX
Reusable, composable, battle-tested Terraform modules
PDF
Terraform in Depth (MEAP V01) Robert Hafner
PDF
Terraform in Depth (MEAP V01) Robert Hafner
PDF
Openstack Operations Guide 1st Edition Tom Fifield Diane Fleming
PDF
Managing GCP Projects with Terraform (devfest Pisa 2018)
PDF
Terraforming your Infrastructure on GCP
PDF
Platform Clouds, Containers, Immutable Infrastructure Oh My!
PDF
56k.cloud training
PDF
OSDC 2018 | Migrating to the cloud by Devdas Bhagat
PDF
AWS DevOps - Terraform, Docker, HashiCorp Vault
PDF
Oracle Cloud - Infrastruktura jako kód
PPTX
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
PDF
terraformforindusrtybestpracticesforaws.pdf
Microservices with Terraform, Docker and the Cloud. JavaOne 2017 2017-10-02
Microservices with Terraform, Docker and the Cloud. DevOps Wet 2018
Managing AWS Using Terraform AWS Chicago-Suburbs 2018-01-18
OpenStack Operations Guide 1st Edition Tom Fifield
Managing AWS Using Terraform AWS Atlanta 2018-07-18
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
Terraform-2.pdf
Reusable, composable, battle-tested Terraform modules
Terraform in Depth (MEAP V01) Robert Hafner
Terraform in Depth (MEAP V01) Robert Hafner
Openstack Operations Guide 1st Edition Tom Fifield Diane Fleming
Managing GCP Projects with Terraform (devfest Pisa 2018)
Terraforming your Infrastructure on GCP
Platform Clouds, Containers, Immutable Infrastructure Oh My!
56k.cloud training
OSDC 2018 | Migrating to the cloud by Devdas Bhagat
AWS DevOps - Terraform, Docker, HashiCorp Vault
Oracle Cloud - Infrastruktura jako kód
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
terraformforindusrtybestpracticesforaws.pdf
Ad

Recently uploaded (20)

PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
top salesforce developer skills in 2025.pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
medical staffing services at VALiNTRY
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
System and Network Administration Chapter 2
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
System and Network Administraation Chapter 3
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PPTX
Introduction to Artificial Intelligence
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Operating system designcfffgfgggggggvggggggggg
top salesforce developer skills in 2025.pdf
ai tools demonstartion for schools and inter college
Odoo Companies in India – Driving Business Transformation.pdf
Understanding Forklifts - TECH EHS Solution
medical staffing services at VALiNTRY
Design an Analysis of Algorithms I-SECS-1021-03
System and Network Administration Chapter 2
CHAPTER 2 - PM Management and IT Context
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Odoo POS Development Services by CandidRoot Solutions
System and Network Administraation Chapter 3
ManageIQ - Sprint 268 Review - Slide Deck
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
How to Choose the Right IT Partner for Your Business in Malaysia
Which alternative to Crystal Reports is best for small or large businesses.pdf
Introduction to Artificial Intelligence
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises

Microservices with Terraform, Docker and the Cloud. Chicago Coders Conference 2017-06-27

  • 1. Managing Microservices using Terraform, Docker, and the Cloud Given by Derek C. Ashmore June 27, 2017 ©2017 Derek C. Ashmore, All Rights Reserved 1
  • 2. Who am I? • Professional Geek since 1987 • Java/J2EE/Java EE since 1999 • AWS since 2010 • Specialties • Refactoring • Performance Tuning • Yes – I still code! ©2017 Derek C. Ashmore, All Rights Reserved 2
  • 3. Lab Preparation • This lab has set-up instructions on my github – https://github.com/Derek-Ashmore/terraform-hands-on-lab • Set up for the lab during the discussion! – It is socially acceptable – I will not wait for you to do the setup! – Feel free to treat the lab as a demo ©2017 Derek C. Ashmore, All Rights Reserved 3
  • 4. Discussion Resources • This slide deck – http://www.slideshare.net/derekashmore • The hands-on-lab code and setup instructions – https://github.com/Derek-Ashmore/terraform-hands-on-lab • The Moneta microservice (written in Java) – https://github.com/Derek-Ashmore/moneta • Slide deck has hyper-links! – Don’t bother writing down URLs ©2017 Derek C. Ashmore, All Rights Reserved 4
  • 5. Agenda Microservices, Docker, and the Cloud Cloud with Terraform Terraform’s Competitors Summary / Q&A ©2017 Derek C. Ashmore, All Rights Reserved 5
  • 6. What are Microservices? • No concrete definition • Common microservice traits – Single functional purpose • Most/all changes only impact one service • Not dependent on execution context – “loosely coupled” – Independent process/jvm – Stateless – Standard Interface (typically Web Service/REST) – Analogy: Stereo system, Linux utilities ©2017 Derek C. Ashmore, All Rights Reserved 6
  • 7. Microservices Application Architecture • Separate Databases • Eventual Consistency • More network activity ©2017 Derek C. Ashmore, All Rights Reserved 7
  • 8. Typical Microservice Library ©2017 Derek C. Ashmore, All Rights Reserved 8
  • 9. Microservice Deployments ©2017 Derek C. Ashmore, All Rights Reserved 9
  • 10. Docker • Is a “mini VM” • runs a linux kernal • Compare to shipping container • Standard “connections” to outside world • Supported formally by Oracle, Tomcat, Jboss, and many more 10©2017 Derek C. Ashmore, All Rights Reserved Package Once, Run Anywhere!
  • 11. Why Docker? • Docker is Win-Win – Easier for OPS and system administrators • All software looks the same • Standard interface for disk and network resources – Containers can be “linked” • Inherently automated – Easier for developers • Fewer environment difference issues • Less to communicate to OPS / system administrators • Easy to leverage work of others (docker-hub) – If you haven’t tried Docker yet – you should! ©2017 Derek C. Ashmore, All Rights Reserved 11
  • 12. Docker Build File • Docker file for Microservice Moneta – Base Image • FROM java:8-jre – Expose Folder • VOLUME /config – Download Moneta Jar Release • RUN curl -SL "$MONETA_URL" -o moneta-dropwizard.jar – Expose Ports • EXPOSE 8080 8081 – Run It • ENTRYPOINT exec java -classpath $CLASSPATH -server $JAVA_OPTS • -jar moneta-dropwizard.jar server /config/moneta-dropwizard.yaml ©2017 Derek C. Ashmore, All Rights Reserved 12
  • 13. Running a Docker Image • The Docker Run Command – Exposes Ports – Attaches Disk – Passes/sets Environment Variables – Allocates Memory • Example from the Lab Portion – export JAVA_OPTS="-Xmx768m” – docker pull derekashmore/moneta-dropwizard:0.9.3-alpha – docker run -d -p 80:8080 -m 800m -e JAVA_OPTS – -v $PWD/moneta-config:/config derekashmore/moneta-dropwizard:0.9.3-alpha ©2017 Derek C. Ashmore, All Rights Reserved 13
  • 14. Typical Microservice Install at AWS ©2017 Derek C. Ashmore, All Rights Reserved 14 • Horizontal scaling is supported • Multiple copies of microservice / web application running at the same time • Elastic Load Balancer distributes load across copies of your service • Sticky sessions available • ELB can use health checks • Autoscaling Groups scale number of copies up and down based on rules you give it • CPU Utilization or other metrics • Autoscaling Groups distribute across availability zones for availability
  • 15. Network Security ©2017 Derek C. Ashmore, All Rights Reserved 15
  • 16. Network Security (con’t) • Public vs. Private subnets – Specified by Routes and Network ACLs – Public subnets can be used from the internet • Web Servers typically placed here – Private subnets only used within your Virtual Network • Access from the internet just not possible – Even if a public IP is assigned • Microservices • Databases • Messaging traffic • It’s common to add SSO (for web applications) and OAUTH (for microservices) above that ©2017 Derek C. Ashmore, All Rights Reserved 16
  • 17. Security Groups • Security Groups provide Inbound/Outbound rules for individual instances – Think of as “an assignable firewall” – Multiple rules per VM allowed. – Easy additional layer of security – No changes to applications or services needed. • Examples – Web Servers  Allow port 80 and 443 from anywhere – Web Servers  Allow SSH/SFTP only from within the VPC • Security Groups and be associated – Financial Microservice Allow port 443 only from VMs belonging to security group FINANCIAL_SERVICE_CLIENT_SG – Oracle Database  Allow port 1521 only from VMs belonging to security group ORACLE_CLIENT_SG ©2017 Derek C. Ashmore, All Rights Reserved 17
  • 18. Managing Cloud Assets • Objectives – Managing Complexity • Environment Consistency • Environment Lifecycle Support • Ease of change • Reuse – Manage risk of change – Mitigate Cloud Lock-in • Infrastructure as Code – Reusable Infrastructure Components • Leverage work/expertise of others • Big problem  Smaller manageable problems – Change Tracking – Source Control ©2017 Derek C. Ashmore, All Rights Reserved 18
  • 19. Agenda Microservices, Docker, and the Cloud Cloud with Terraform Terraform’s Competitors Summary / Q&A ©2017 Derek C. Ashmore, All Rights Reserved 19
  • 20. Terraform • Cloud Management – Open Source • Very active community – Extensible to any cloud vendor • AWS, Azure, GCP, AliCloud, Digital Ocean, OpenStack – Supported for Cloud Support products • Chef, Consul, Kubernetes, Datadog • 62 Providers as of April, 2017 and growing ©2017 Derek C. Ashmore, All Rights Reserved 20
  • 21. Terraform HCL • Declarative Language – Describe what the end product contains • Terraform figures out how to get there – Terraform Resources • Describes deployed artifacts – Network  Virtual Networks, Subnets, Network ACLs, Gateways, ELB/ALB – Hosts  Virtual Machines, Databases – Security  Security groups/policies/roles/groups/users – Much more ©2017 Derek C. Ashmore, All Rights Reserved 21
  • 22. Terraform Basics • Declarative Programming – All *.tf files loaded  Terraform decides execution order – No GUI  All command line and text editor • Top Commands – Terraform plan  Describes planned changes – Terraform apply  Makes planned changes – Terraform taint  Forces re-creation of a resource – Terraform destroy  deletes all resources ©2017 Derek C. Ashmore, All Rights Reserved 22
  • 23. Terraform Resources • AWS Subnet Resource – Count = 3  Three subnets created – Availability Zones come from a data source (lookup) – CIDR blocks are input variables • Sample source ©2017 Derek C. Ashmore, All Rights Reserved 23
  • 24. Terraform Data Sources • Example Data Sources (lookups) • Sample source ©2017 Derek C. Ashmore, All Rights Reserved 24
  • 25. Terraform Providers • Example Provider • Sample AWS source • Azure Provider ©2017 Derek C. Ashmore, All Rights Reserved 25
  • 26. Terraform Input Variables • Example Provider • Sample source ©2017 Derek C. Ashmore, All Rights Reserved 26
  • 27. Reusing Terraform Templates • Example Template Reuse • Sample source ©2017 Derek C. Ashmore, All Rights Reserved 27
  • 28. Typical Project Structure ©2017 Derek C. Ashmore, All Rights Reserved 28
  • 29. Terraform State • Terraform stores state – Local file terraform.tfstate • Teams need to manage state centrally – Terraform Backends • Locks so that only one person at a time can update • Remote storage – S3, Azure containers, Google cloud storage, etc. ©2017 Derek C. Ashmore, All Rights Reserved 29
  • 30. Agenda Microservices, Docker, and the Cloud Cloud with Terraform Terraform’s Competitors Summary / Q&A ©2017 Derek C. Ashmore, All Rights Reserved 30
  • 31. Terraform vs. Ansible/Chef • Terraform designed for infrastructure – Not designed for configuration management – Terraform deploys images • Not good at maintaining what’s on those images • If deployments update existing VMs – You need Ansible, Chef, or Puppet • If deployments are “new” VMs – Terraform can handle deployments too ©2017 Derek C. Ashmore, All Rights Reserved 31
  • 32. Paradigm Shift • Deployment as new infrastructure – New version  new VMs • Software versions baked into images – Advantages • Facilitates Canary Deployments – Route53 Routing Policies • Go-live operation has less risk – Deploy/Backout is just a load balancer switch – Disadvantages • More moving parts • Impossible to do manually ©2017 Derek C. Ashmore, All Rights Reserved 32
  • 33. Terraform vs CloudFormation Terraform • Scripting skills translate to Azure, Google Cloud, etc. • Less verbose (>50%) • Data Lookups • Custom Plug-ins possible • Active Community Support CloudFormation • Quicker to follow AWS enhancements • GUI support • Automatic centralized state • Vendor Support ©2017 Derek C. Ashmore, All Rights Reserved 33
  • 34. Further Reading • This slide deck – http://www.slideshare.net/derekashmore • The Gruntwork Blog – https://blog.gruntwork.io/ ©2017 Derek C. Ashmore, All Rights Reserved 34
  • 35. Questions? • Derek Ashmore: – Blog: www.derekashmore.com – LinkedIn: www.linkedin.com/in/derekashmore • Connect Invites from attendees welcome – Twitter: https://twitter.com/Derek_Ashmore – GitHub: https://github.com/Derek-Ashmore – Book: http://dvtpress.com/ ©2017 Derek C. Ashmore, All Rights Reserved 35
  • 36. HANDS-ON LAB ©2017 Derek C. Ashmore, All Rights Reserved 36
  • 37. Lab Resources and Objectives • This lab has set-up instructions on my github – https://github.com/Derek-Ashmore/terraform-hands-on-lab • You will experience – Creating a network and deploying VMs at AWS using Terraform – You will learn how to use Terraform Modules to leverage your code across applications – You will see the output of your work live on the internet. • Java Microservice to be deployed – https://github.com/Derek-Ashmore/moneta ©2017 Derek C. Ashmore, All Rights Reserved 37
  • 38. Sample Java/EE Microservice • Moneta – Greek goddess of ‘memory’ – Open source: https://github.com/Derek-Ashmore/moneta • Objective: – Provide a RESTful Web Service interface to a relational database • Feature set: – Provides generic ‘core’ services – Returns Json-formatted data – Supports startRow and maxRows query options – Supports a security call-out – Built-in Dropwizard, Spring Boot, and War-file deployments • Sample contract spec – currently read-only (writes in progress) – /moneta/topics – lists ‘topics’ of information • E.g. – Topic Customer configured – /moneta/topic/customers?startRow=5&maxRows=25 – /moneta/topic/customer/111-222-333 • Docker deployment – https://hub.docker.com/r/derekashmore/moneta-dropwizard/ ©2015 Derek C. Ashmore, All Rights Reserved 38
  • 39. The Lab Network at AWS ©2017 Derek C. Ashmore, All Rights Reserved 39
  • 40. Questions? • Derek Ashmore: – Blog: www.derekashmore.com – LinkedIn: www.linkedin.com/in/derekashmore • Connect Invites from attendees welcome – Twitter: https://twitter.com/Derek_Ashmore – GitHub: https://github.com/Derek-Ashmore – Book: http://dvtpress.com/ ©2017 Derek C. Ashmore, All Rights Reserved 40 terraform destroy