SlideShare a Scribd company logo
4
Most read
11
Most read
14
Most read
TERRAFORM
3rd October 2018
Introduction to Terraform
By Sasitha Rajapaksha
Overview
● Terraform
● What is Terraform
● Why we use Terraform
● Terraform use cases
● Compare with Cloudformation
● Workflow of provisioning
● Hands on with Terraform
○ S3
○ Cloudfront
○ EC2
Terraform
● Open source
● Mozilla public licence 2.0
● Created by Hashicorp
● Started in 2014
● Written in GO
● Pluggable
Terraform is a tool to BUILD, CHANGE and VERSION
CONTROL your infrastructure.
Terraform can work with multiple cloud infrastructure at the
same time and ensure creation and consistency.
Terraform Remote State
● There is default local state
Which making sure that developer doesn’t do any changes to the same infrastructure at the
same time
● Remote state
○ Work same as the local state but it is useful when working with a team. This remote state will share with each
other and block the concurrent changes to the same infrastructure.
Terraform use cases
● Apply incremental changes
● Destroy infrastructure at any time we want
● Preview changes
● Scale easily
● Version control
Terraform vs. Cloudformation
resource "aws_s3_bucket" "bucket" {
bucket = "my-tf-test-bucket"
acl = "private"
}
{
"Resources": {
"my-cf-test-bucket":{
"Type": "AWS::S3::Bucket",
"Properties":{
"AccessControl":"Private",
},
},
}
}
Terraform Cloudformation
How Terraform works
● Terraform takes variables as a inputs
○ JSON
○ HCL
○ CLI
● Output ip address, texts and etc..
○ JSON
○ CLI
Let's start
AWS Provider
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "us-east-1"
}
Azure Provider
provider "azurerm" {
subscription_id = "${var.subscription_id }"
client_id = "${var.client_id }"
client_secret = "${var.client_secret }"
tenant_id = "${var.tenant_id }"
}
Workflow of provisioning
1. First start with “terraform init” to setup initial aws or azure providers
2. Then “terraform plan” command to see than plan of what will provision
3. Finally “terraform apply” command to provision all the infrastructure
4. Okay, then you can use “terraform apply” at any time to do any changes to the
provisioned infrastructure.
S3 Bucket to store static website
resource "aws_s3_bucket" "b" {
bucket = "mybucket"
acl = "private"
tags {
Name = "My bucket"
}
}
locals {
s3_origin_id = "myS3Origin"
}
EC2 instance
provider "aws" {
region = "us-west-2"
}
data "aws_ami" "ubuntu" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-
trusty-14.04-amd64-server-*"]
}
filter {
name = "virtualization-type"
values = ["hvm"]
}
owners = ["099720109477"] # Canonical
}
resource "aws_instance" "web" {
ami = "${data.aws_ami.ubuntu.id}"
instance_type = "t2.micro"
tags {
Name = "HelloWorld"
}
}
Creating Cloudfront
resource "aws_cloudfront_distribution" "s3_distribution" {
origin {
domain_name = "${aws_s3_bucket.b.bucket_regional_domain_name}"
origin_id = "${local.s3_origin_id}"
s3_origin_config {
origin_access_identity = "origin-access-identity/cloudfront/ABCDEFG1234567"
}
}
}

More Related Content

PDF
Terraform -- Infrastructure as Code
PPTX
PDF
Best Practices of Infrastructure as Code with Terraform
PPTX
Terraform
PPTX
Terraform
PDF
Getting Started with Infrastructure as Code
PDF
Terraform
PPTX
Infrastructure-as-Code (IaC) using Terraform
Terraform -- Infrastructure as Code
Best Practices of Infrastructure as Code with Terraform
Terraform
Terraform
Getting Started with Infrastructure as Code
Terraform
Infrastructure-as-Code (IaC) using Terraform

What's hot (20)

PDF
Terraform introduction
PPTX
Comprehensive Terraform Training
PPTX
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
PPTX
Terraform Basics
PDF
Introduction to IAC and Terraform
PDF
Terraform: An Overview & Introduction
PDF
PDF
Terraform Introduction
PDF
Terraform modules and best-practices - September 2018
PDF
Terraform Best Practices - DevOps Unicorns 2019
PPTX
Final terraform
PPTX
Terraform modules restructured
PDF
Introduce to Terraform
PDF
Terraform
PPTX
Terraform training 🎒 - Basic
PPTX
Terraform on Azure
PDF
Infrastructure as Code
PPTX
Building Repeatable Infrastructure using Terraform
PDF
A Hands-on Introduction on Terraform Best Concepts and Best Practices
PDF
Terraform modules and (some of) best practices
Terraform introduction
Comprehensive Terraform Training
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Terraform Basics
Introduction to IAC and Terraform
Terraform: An Overview & Introduction
Terraform Introduction
Terraform modules and best-practices - September 2018
Terraform Best Practices - DevOps Unicorns 2019
Final terraform
Terraform modules restructured
Introduce to Terraform
Terraform
Terraform training 🎒 - Basic
Terraform on Azure
Infrastructure as Code
Building Repeatable Infrastructure using Terraform
A Hands-on Introduction on Terraform Best Concepts and Best Practices
Terraform modules and (some of) best practices
Ad

Similar to Introduction To Terraform (20)

PDF
PPTX
Meetup bangalore aug31st2019
PDF
DevOps Braga #9: Introdução ao Terraform
PDF
Terraforming your Infrastructure on GCP
PDF
Terraform - Taming Modern Clouds
PPTX
Terraform Immutablish Infrastructure with Consul-Template
PDF
Oracle Cloud deployment with Terraform
DOCX
Terraform Multi-Cloud Infrastructure_ Building a Unified, Portable Cloud Foun...
PDF
Configuration management II - Terraform
PPTX
Hashicorp-Terraform_Packer_Vault-by Sushil
PDF
AWS DevOps - Terraform, Docker, HashiCorp Vault
PDF
Provisioning infrastructure to AWS using Terraform – Exove
PPTX
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
PPTX
Debasihish da final.ppt
PDF
Declarative Infrastructure Tools
PPTX
Introduction to Kubernetes
PDF
Collaborative Terraform with Atlantis
KEY
Jclouds Intro
PDF
CDK Meetup: Rule the World through IaC
PPTX
Effective terraform
Meetup bangalore aug31st2019
DevOps Braga #9: Introdução ao Terraform
Terraforming your Infrastructure on GCP
Terraform - Taming Modern Clouds
Terraform Immutablish Infrastructure with Consul-Template
Oracle Cloud deployment with Terraform
Terraform Multi-Cloud Infrastructure_ Building a Unified, Portable Cloud Foun...
Configuration management II - Terraform
Hashicorp-Terraform_Packer_Vault-by Sushil
AWS DevOps - Terraform, Docker, HashiCorp Vault
Provisioning infrastructure to AWS using Terraform – Exove
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
Debasihish da final.ppt
Declarative Infrastructure Tools
Introduction to Kubernetes
Collaborative Terraform with Atlantis
Jclouds Intro
CDK Meetup: Rule the World through IaC
Effective terraform
Ad

Recently uploaded (20)

PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Business Ethics Teaching Materials for college
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
Insiders guide to clinical Medicine.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Final Presentation General Medicine 03-08-2024.pptx
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Microbial disease of the cardiovascular and lymphatic systems
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Supply Chain Operations Speaking Notes -ICLT Program
O5-L3 Freight Transport Ops (International) V1.pdf
Business Ethics Teaching Materials for college
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Abdominal Access Techniques with Prof. Dr. R K Mishra
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPH.pptx obstetrics and gynecology in nursing
human mycosis Human fungal infections are called human mycosis..pptx
Anesthesia in Laparoscopic Surgery in India
Week 4 Term 3 Study Techniques revisited.pptx
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Insiders guide to clinical Medicine.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf

Introduction To Terraform

  • 1. TERRAFORM 3rd October 2018 Introduction to Terraform By Sasitha Rajapaksha
  • 2. Overview ● Terraform ● What is Terraform ● Why we use Terraform ● Terraform use cases ● Compare with Cloudformation ● Workflow of provisioning ● Hands on with Terraform ○ S3 ○ Cloudfront ○ EC2
  • 3. Terraform ● Open source ● Mozilla public licence 2.0 ● Created by Hashicorp ● Started in 2014 ● Written in GO ● Pluggable
  • 4. Terraform is a tool to BUILD, CHANGE and VERSION CONTROL your infrastructure. Terraform can work with multiple cloud infrastructure at the same time and ensure creation and consistency.
  • 5. Terraform Remote State ● There is default local state Which making sure that developer doesn’t do any changes to the same infrastructure at the same time ● Remote state ○ Work same as the local state but it is useful when working with a team. This remote state will share with each other and block the concurrent changes to the same infrastructure.
  • 6. Terraform use cases ● Apply incremental changes ● Destroy infrastructure at any time we want ● Preview changes ● Scale easily ● Version control
  • 7. Terraform vs. Cloudformation resource "aws_s3_bucket" "bucket" { bucket = "my-tf-test-bucket" acl = "private" } { "Resources": { "my-cf-test-bucket":{ "Type": "AWS::S3::Bucket", "Properties":{ "AccessControl":"Private", }, }, } } Terraform Cloudformation
  • 8. How Terraform works ● Terraform takes variables as a inputs ○ JSON ○ HCL ○ CLI ● Output ip address, texts and etc.. ○ JSON ○ CLI
  • 10. AWS Provider provider "aws" { access_key = "${var.aws_access_key}" secret_key = "${var.aws_secret_key}" region = "us-east-1" } Azure Provider provider "azurerm" { subscription_id = "${var.subscription_id }" client_id = "${var.client_id }" client_secret = "${var.client_secret }" tenant_id = "${var.tenant_id }" }
  • 11. Workflow of provisioning 1. First start with “terraform init” to setup initial aws or azure providers 2. Then “terraform plan” command to see than plan of what will provision 3. Finally “terraform apply” command to provision all the infrastructure 4. Okay, then you can use “terraform apply” at any time to do any changes to the provisioned infrastructure.
  • 12. S3 Bucket to store static website resource "aws_s3_bucket" "b" { bucket = "mybucket" acl = "private" tags { Name = "My bucket" } } locals { s3_origin_id = "myS3Origin" }
  • 13. EC2 instance provider "aws" { region = "us-west-2" } data "aws_ami" "ubuntu" { most_recent = true filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu- trusty-14.04-amd64-server-*"] } filter { name = "virtualization-type" values = ["hvm"] } owners = ["099720109477"] # Canonical } resource "aws_instance" "web" { ami = "${data.aws_ami.ubuntu.id}" instance_type = "t2.micro" tags { Name = "HelloWorld" } }
  • 14. Creating Cloudfront resource "aws_cloudfront_distribution" "s3_distribution" { origin { domain_name = "${aws_s3_bucket.b.bucket_regional_domain_name}" origin_id = "${local.s3_origin_id}" s3_origin_config { origin_access_identity = "origin-access-identity/cloudfront/ABCDEFG1234567" } } }