KEMBAR78
Introduction to IAC and Terraform | PDF
INFRASTRUCTURE AS CODE
TERRAFORM
Venkat Naveen
CloudDevOpsEngineer
Agenda
▸ Infrastructure as
Code
▸ Introduction to
Terraform
▸ Demo -
Infrastructure as
Code with Terraform
▸ Questions
INFRASTRUCTURE AS CODE - WHAT?
The practice of using code to describe, create and manage
infrastructure.
▸ IaC for short
▸ Often referred to as programmable infrastructure
▸ NOT a "new" thing
▸ Infrastructure?
INFRASTRUCTURE AS CODE - WHAT?
High level goals of IaC
▸ Ability to rebuild any part of the infrastructure at any time
▸ Ensure consistency
▸ Repeatable process
▸ Assume everything will change
INFRASTRUCTURE AS CODE -
WHAT?
Key practices
▸ Create definition files
▸ Put everything in source control
▸ Prove production readiness
INFRASTRUCTURE AS CODE - WHY?
On prem datacenter’s and Hosting services
▸ Time consuming ordering process
▸ Long lead times
▸ Manual setup
▸ Incorrect configuration
INFRASTRUCTURE AS CODE -
WHY?
On prem datacenter’s and Hosting services continued…
▸ Poor documentation
▸ Configuration drift
▸ Downtime for patching and updating
INFRASTRUCTURE AS CODE - WHY?
Reasons for change
▸ Time to market
▸ High availability
▸ Scale
▸ Agility
INFRASTRUCTURE AS CODE - SUMMARY
A modern approach to Ops
▸ Use existing tools and practices
▸ Version history and change log
▸ Enables collaboration
▸ Executable
▸ Repeatable
INFRASTRUCTURE AS CODE -
SUMMARY
A modern approach to Ops
▸ Documentation (a source of knowledge)
▸ Risk management
▸ Agility
▸ Security
▸ Immutability
INTRODUCING TERRAFORM
“TERRAFORMIS ATOOLFORBUILDING,CHANGING,AND
VERSIONINGINFRASTRUCTURESAFELYANDEFFICIENTLY.
TERRAFORMCANMANAGEEXISTINGANDPOPULARSERVICE
PROVIDERSASWELLASCUSTOMIN-HOUSESOLUTIONS.”
io
INTRODUCING TERRAFORM
• Created by HashiCorp in 2014
• Open Source
• Runs on linux, mac & windows
• Version 0.11.10
• Uses HCL to describe infrastructure
Provisioning Workflow
• Write - create your Infrastructure as code
• Plan - creates a plan - review the changes
• Apply - instruct Terraform to carry out the
changes
Write
Create your infrastructure (as code):
Plan
Terraform has a "planning" step where it
generates an execution plan. The execution
plan shows what Terraform will do when you
call apply. This lets you avoid any
surprises when Terraform manipulates
infrastructure.
Apply
Apply the changes required to reach the
desired state of the configuration, or the
pre-determined set of actions generated by a
execution plan.
Terraform Providers
A provider is responsible for understanding
API interactions and exposing resources.
Providers generally are an IaaS (e.g. AWS,
GCP, Microsoft Azure, VMware, OpenStack),
PaaS (e.g. Heroku), or SaaS services (e.g.
Terraform Enterprise, DNSimple,
CloudFlare).
IaaS Providers
• AWS (32.3%, +46.3%)*
• Azure (16.5%, +75.9%)*
• Google Cloud (9.5%, +81.7%)*
• Alibaba Cloud (4.2%, +73.8%)*
• VMware (33.8%, +26.7%)*
• Open Stack
* https://www.canalys.com/newsroom/cloud-market-share-q4-2018-and-full-year-2018
PaaS Providers
• AWS
• Google App Engine
• Kubernetes
• Docker
• VMWare, Vsphere
• AZURE
SaaS Providers
• Jira
• Bitbucket
• GitHub
Centralised Management
of IaaS, PaaS and SaaS
Terraform State
• Terraform must store state about your
managed infrastructure and configuration.
This state is used by Terraform to map real
world resources to your configuration, keep
track of metadata, and to improve
performance for large infrastructures.
• The state is in JSON format and Terraform
will promise backwards compatibility with
the state file.
Terraform Variables
• Input Variables - Input variables serve as parameters for a
Terraform module, allowing aspects of the module to be customised without
altering the module's own source code, and allowing modules to be shared
between different configurations.
• Output Variables - Output values are like the return values of a
Terraform module, and have several uses.
• 1. A child module can use outputs to expose a subset of its resource
attributes to a parent module.
• 2. A root module can use outputs to print certain values in the CLI output
after running terraform apply.
• 3. When using remote state, root module outputs can be accessed by other
configurations via a terraform_remote_state data source.
Terraform Modules
• A module is a container for multiple
resources that are used together. Modules can
be used to create lightweight abstractions,
so that you can describe your infrastructure
in terms of its architecture, rather than
directly in terms of physical objects.
• Re-usable modules are defined using all of
the same configuration language concepts we
use in root modules
Best Practices
• Make use of Terraform variables
• Make user of Terraform modules
• Keep connection details out of source
control!
• .gitignore
• Have a human operator to review the plan
Why Terraform?
• Operates at a higher level, enabling it to
work alongside of on in place of the other
tools
• Light weight
• Cloud agnostic
• Open Source (You can contribute)
• Well documented
Questions?

Introduction to IAC and Terraform

  • 1.
    INFRASTRUCTURE AS CODE TERRAFORM VenkatNaveen CloudDevOpsEngineer
  • 2.
    Agenda ▸ Infrastructure as Code ▸Introduction to Terraform ▸ Demo - Infrastructure as Code with Terraform ▸ Questions
  • 3.
    INFRASTRUCTURE AS CODE- WHAT? The practice of using code to describe, create and manage infrastructure. ▸ IaC for short ▸ Often referred to as programmable infrastructure ▸ NOT a "new" thing ▸ Infrastructure?
  • 4.
    INFRASTRUCTURE AS CODE- WHAT? High level goals of IaC ▸ Ability to rebuild any part of the infrastructure at any time ▸ Ensure consistency ▸ Repeatable process ▸ Assume everything will change
  • 5.
    INFRASTRUCTURE AS CODE- WHAT? Key practices ▸ Create definition files ▸ Put everything in source control ▸ Prove production readiness
  • 6.
    INFRASTRUCTURE AS CODE- WHY? On prem datacenter’s and Hosting services ▸ Time consuming ordering process ▸ Long lead times ▸ Manual setup ▸ Incorrect configuration
  • 7.
    INFRASTRUCTURE AS CODE- WHY? On prem datacenter’s and Hosting services continued… ▸ Poor documentation ▸ Configuration drift ▸ Downtime for patching and updating
  • 8.
    INFRASTRUCTURE AS CODE- WHY? Reasons for change ▸ Time to market ▸ High availability ▸ Scale ▸ Agility
  • 9.
    INFRASTRUCTURE AS CODE- SUMMARY A modern approach to Ops ▸ Use existing tools and practices ▸ Version history and change log ▸ Enables collaboration ▸ Executable ▸ Repeatable
  • 10.
    INFRASTRUCTURE AS CODE- SUMMARY A modern approach to Ops ▸ Documentation (a source of knowledge) ▸ Risk management ▸ Agility ▸ Security ▸ Immutability
  • 11.
  • 12.
    INTRODUCING TERRAFORM • Createdby HashiCorp in 2014 • Open Source • Runs on linux, mac & windows • Version 0.11.10 • Uses HCL to describe infrastructure
  • 13.
    Provisioning Workflow • Write- create your Infrastructure as code • Plan - creates a plan - review the changes • Apply - instruct Terraform to carry out the changes
  • 14.
  • 15.
    Plan Terraform has a"planning" step where it generates an execution plan. The execution plan shows what Terraform will do when you call apply. This lets you avoid any surprises when Terraform manipulates infrastructure.
  • 16.
    Apply Apply the changesrequired to reach the desired state of the configuration, or the pre-determined set of actions generated by a execution plan.
  • 17.
    Terraform Providers A provideris responsible for understanding API interactions and exposing resources. Providers generally are an IaaS (e.g. AWS, GCP, Microsoft Azure, VMware, OpenStack), PaaS (e.g. Heroku), or SaaS services (e.g. Terraform Enterprise, DNSimple, CloudFlare).
  • 18.
    IaaS Providers • AWS(32.3%, +46.3%)* • Azure (16.5%, +75.9%)* • Google Cloud (9.5%, +81.7%)* • Alibaba Cloud (4.2%, +73.8%)* • VMware (33.8%, +26.7%)* • Open Stack * https://www.canalys.com/newsroom/cloud-market-share-q4-2018-and-full-year-2018
  • 19.
    PaaS Providers • AWS •Google App Engine • Kubernetes • Docker • VMWare, Vsphere • AZURE
  • 20.
    SaaS Providers • Jira •Bitbucket • GitHub
  • 21.
  • 22.
    Terraform State • Terraformmust store state about your managed infrastructure and configuration. This state is used by Terraform to map real world resources to your configuration, keep track of metadata, and to improve performance for large infrastructures. • The state is in JSON format and Terraform will promise backwards compatibility with the state file.
  • 23.
    Terraform Variables • InputVariables - Input variables serve as parameters for a Terraform module, allowing aspects of the module to be customised without altering the module's own source code, and allowing modules to be shared between different configurations. • Output Variables - Output values are like the return values of a Terraform module, and have several uses. • 1. A child module can use outputs to expose a subset of its resource attributes to a parent module. • 2. A root module can use outputs to print certain values in the CLI output after running terraform apply. • 3. When using remote state, root module outputs can be accessed by other configurations via a terraform_remote_state data source.
  • 24.
    Terraform Modules • Amodule is a container for multiple resources that are used together. Modules can be used to create lightweight abstractions, so that you can describe your infrastructure in terms of its architecture, rather than directly in terms of physical objects. • Re-usable modules are defined using all of the same configuration language concepts we use in root modules
  • 25.
    Best Practices • Makeuse of Terraform variables • Make user of Terraform modules • Keep connection details out of source control! • .gitignore • Have a human operator to review the plan
  • 26.
    Why Terraform? • Operatesat a higher level, enabling it to work alongside of on in place of the other tools • Light weight • Cloud agnostic • Open Source (You can contribute) • Well documented
  • 27.