SlideShare a Scribd company logo
1 of 34
Download to read offline
Terraform
Sonia Hamilton
1 / 34
Provisioning
instances
storage
dns
2 / 34
In Relation To...
Puppet, Salt
Boto, Fog
CloudFormation
Vagrant?
3 / 34
Features
execution plans
dependencies
state
4 / 34
Example Providers
AWS
Heroku
Google Cloud
DNSimple
no VCloud, yet...
5 / 34
Terraform and Go
Terraform is written in Go (golang)
dev version
http://blog.snowfrog.net/2014/12/04/building-the-development-
version-of-terraform/
http://bit.ly/1vNjuIU
docs -- grep
6 / 34
Using a Provider
provider "aws" {
access_key = "ACCESS_KEY_HERE"
secret_key = "SECRET_KEY_HERE"
region = "us-east-1"
}
resource "aws_instance" "example" {
ami = "ami-408c7f28"
instance_type = "t1.micro"
}
7 / 34
Terraform Plan
$ terraform plan
...
+ aws_instance.example
ami: "" => "ami-408c7f28"
availability_zone: "" => "<computed>"
instance_type: "" => "t1.micro"
key_name: "" => "<computed>"
private_dns: "" => "<computed>"
private_ip: "" => "<computed>"
public_dns: "" => "<computed>"
public_ip: "" => "<computed>"
security_groups: "" => "<computed>"
subnet_id: "" => "<computed>"
8 / 34
Terraform Apply
$ terraform apply
aws_instance.example: Creating...
ami: "" => "ami-408c7f28"
instance_type: "" => "t1.micro"
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
...
9 / 34
terraform.tfstate
JSON file
TerraformShow
$ terraform show
aws_instance.example:
id = i-e60900cd
ami = ami-408c7f28
availability_zone = us-east-1c
instance_type = t1.micro
key_name =
private_dns = domU-12-31-39-12-38-AB.compute-1.internal
private_ip = 10.200.59.89
public_dns = ec2-54-81-21-192.compute-1.amazonaws.com
public_ip = 54.81.21.192
security_groups.# = 1
security_groups.0 = default
subnet_id =
10 / 34
Plan/Apply - Video
provider "aws" {
access_key = "AKIA................"
secret_key = "puOt...................................."
region = "ap-southeast-2"
}
resource "aws_instance" "example" {
key_name = "sonia" # AWS keypair name
ami = "ami-9b0b62a1" # Ubuntu 14.04
instance_type = "t1.micro"
}
demo01
11 / 34
Changing Infrastructure
Edit
resource "aws_instance" "example" {
ami = "ami-aa7ab6c2" # NEW AMI
instance_type = "t1.micro"
}
12 / 34
Changing Infrastructure
Plan
$ terraform plan
...
-/+ aws_instance.example
ami: "ami-408c7f28" => "ami-aa7ab6c2" (forces new resource)
availability_zone: "us-east-1c" => "<computed>"
...
13 / 34
Changing Infrastructure
Apply
$ terraform apply
aws_instance.example: Destroying...
aws_instance.example: Modifying...
ami: "ami-408c7f28" => "ami-aa7ab6c2"
Apply complete! Resources: 0 added, 1 changed, 1 destroyed.
...
14 / 34
Destroy Infrastructure
Plan
$ terraform plan -destroy
...
- aws_instance.example
15 / 34
Destroy
$ terraform destroy
aws_instance.example: Destroying...
Apply complete! Resources: 0 added, 0 changed, 1 destroyed.
...
16 / 34
Changing Infrastructure - Video
provider "aws" {
access_key = "AKIA................"
secret_key = "puOt...................................."
region = "ap-southeast-2"
}
resource "aws_instance" "example" {
key_name = "sonia" # AWS keypair name
ami = "ami-950b62af" # Ubuntu 14.04
instance_type = "t2.small" # CHANGED
}
demo02
17 / 34
Resource Dependencies
multiple providers
multiple resource types
do x before y, and y needs x's ip address
18 / 34
Resource Dependencies
resource "aws_eip" "ip" {
instance = "${aws_instance.example.id}" # IMPLICIT
}
Plan
$ terraform plan
...
+ aws_eip.ip
instance: "" => "${aws_instance.example.id}"
private_ip: "" => "<computed>"
public_ip: "" => "<computed>"
+ aws_instance.example
ami: "" => "ami-aa7ab6c2"
...
19 / 34
Resource Dependencies
Apply
aws_instance.example: Creating...
ami: "" => "ami-aa7ab6c2"
instance_type: "" => "t1.micro"
aws_eip.ip: Creating...
instance: "" => "i-0e737b25"
Apply complete! Resources: 2 added, 0 changed, 0 destroyed.
Run order is different from output order.
20 / 34
Explicit Dependencies
resource "aws_eip" "ip" {
instance = "${aws_instance.example.id}"
depends_on = ["aws_instance.example"]
}
terraformgraph
21 / 34
Dependencies - Video
provider "aws" {
access_key = "AKIA................"
secret_key = "puOt...................................."
region = "ap-southeast-2"
}
resource "aws_instance" "example" {
key_name = "sonia" # AWS keypair name
ami = "ami-9b0b62a1" # Ubuntu 14.04
instance_type = "t1.micro"
}
resource "aws_eip" "example_eip" {
instance = "${aws_instance.example.id}"
}
demo03
22 / 34
Provisioners
connection
file
local-exec
remote-exec
23 / 34
Connection/File Provisioner - Video
provider "aws" {
access_key = "AKIA................"
secret_key = "puOt...................................."
region = "ap-southeast-2"
}
resource "aws_instance" "example" {
key_name = "sonia" # AWS keypair name
ami = "ami-9b0b62a1" # Ubuntu 14.04
instance_type = "t1.micro"
connection {
user = "ubuntu"
host = "${aws_instance.example.public_ip}"
key_file = "../include/sonia.pem"
}
provisioner "file" {
source = "bootstrap"
destination = "/var/tmp"
}
}
demo04
24 / 34
Exec Provisioners - Video
provider "aws" {
access_key = "AKIA................"
secret_key = "puOt...................................."
region = "ap-southeast-2"
}
resource "aws_instance" "example" {
key_name = "sonia" # AWS keypair name
ami = "ami-9b0b62a1" # Ubuntu 14.04
instance_type = "t1.micro"
connection {
user = "ubuntu"
host = "${aws_instance.example.public_ip}"
key_file = "../include/sonia.pem"
}
provisioner "local-exec" {
command = "echo ${aws_instance.example.public_ip} > ip.txt"
}
provisioner "remote-exec" {
inline = [ "sudo locale-gen en_AU.UTF-8" ]
}
provisioner "remote-exec" {
script = "script1.sh"
}
}
demo05
25 / 34
'Advanced'
input, output variables
modules
26 / 34
Input Variables
Commonly named variables.tf, uses all *.tf files.
variable "access_key" {}
variable "secret_key" {}
variable "region" {
default = "us-east-1"
}
27 / 34
Using Variables
provider "aws" {
access_key = "${var.access_key}"
secret_key = "${var.secret_key}"
region = "${var.region}"
}
28 / 34
Assigning Variables
CommandLine
$ terraform apply 
-var 'access_key=foo' 
-var 'secret_key=bar'
File
terraform.tfvars or use -var-file
access_key = "foo"
secret_key = "bar"
29 / 34
Outputs Variables
Defining
output "ip" {
value = "${aws_eip.ip.public_ip}"
}
Viewing
$ terraform apply
...
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
ip = 50.17.232.209
30 / 34
Modules
Create
$ mkdir child
$ touch child/main.tf
Use
module "child" {
source = "./child"
}
31 / 34
Module Parameters - Input
Caller
module "child" {
source = "./child"
memory = "1G"
}
Child
variable "memory" {}
resource "aws_db_instance" "default" {
...
allocated_storage = "${var.memory}"
...
}
32 / 34
Module Parameters - Output
Child
output "result" {
value = "${foo.region}-${bar.city}"
}
Caller
module "child" { ... }
resource "aws_instance" "web" {
...
tags { Location = "${module.child.result}" }
...
}
33 / 34
Questions
Sonia Hamilton
sonia@snowfrog.net
34 / 34

More Related Content

What's hot

Best Practices of Infrastructure as Code with Terraform
Best Practices of Infrastructure as Code with TerraformBest Practices of Infrastructure as Code with Terraform
Best Practices of Infrastructure as Code with TerraformDevOps.com
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform TrainingYevgeniy Brikman
 
Terraform introduction
Terraform introductionTerraform introduction
Terraform introductionJason Vance
 
Introduction To Terraform
Introduction To TerraformIntroduction To Terraform
Introduction To TerraformSasitha Iresh
 
An introduction to terraform
An introduction to terraformAn introduction to terraform
An introduction to terraformJulien Pivotto
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformAdin Ermie
 
Everything as Code with Terraform
Everything as Code with TerraformEverything as Code with Terraform
Everything as Code with TerraformAll Things Open
 
Terraform modules restructured
Terraform modules restructuredTerraform modules restructured
Terraform modules restructuredAmi Mahloof
 
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
 
Creating AWS infrastructure using Terraform
Creating AWS infrastructure using TerraformCreating AWS infrastructure using Terraform
Creating AWS infrastructure using TerraformKnoldus Inc.
 
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
 

What's hot (20)

Terraform
TerraformTerraform
Terraform
 
Effective terraform
Effective terraformEffective terraform
Effective terraform
 
Best Practices of Infrastructure as Code with Terraform
Best Practices of Infrastructure as Code with TerraformBest Practices of Infrastructure as Code with Terraform
Best Practices of Infrastructure as Code with Terraform
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform Training
 
Terraform
TerraformTerraform
Terraform
 
Final terraform
Final terraformFinal terraform
Final terraform
 
Terraform Basics
Terraform BasicsTerraform Basics
Terraform Basics
 
Terraform introduction
Terraform introductionTerraform introduction
Terraform introduction
 
02 terraform core concepts
02 terraform core concepts02 terraform core concepts
02 terraform core concepts
 
Introduction To Terraform
Introduction To TerraformIntroduction To Terraform
Introduction To Terraform
 
An introduction to terraform
An introduction to terraformAn introduction to terraform
An introduction to terraform
 
infrastructure as code
infrastructure as codeinfrastructure as code
infrastructure as code
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using Terraform
 
Terraform on Azure
Terraform on AzureTerraform on Azure
Terraform on Azure
 
Everything as Code with Terraform
Everything as Code with TerraformEverything as Code with Terraform
Everything as Code with Terraform
 
Terraform modules restructured
Terraform modules restructuredTerraform modules restructured
Terraform modules restructured
 
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
 
Creating AWS infrastructure using Terraform
Creating AWS infrastructure using TerraformCreating AWS infrastructure using Terraform
Creating AWS infrastructure using Terraform
 
Introduction to IAC and Terraform
Introduction to IAC and Terraform Introduction to IAC and Terraform
Introduction to IAC and Terraform
 
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)
 

Viewers also liked

Terraform: Cloud Configuration Management (WTC/IPC'16)
Terraform: Cloud Configuration Management (WTC/IPC'16)Terraform: Cloud Configuration Management (WTC/IPC'16)
Terraform: Cloud Configuration Management (WTC/IPC'16)Martin Schütte
 
Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)Radek Simko
 
Terraform and cloud.ca
Terraform and cloud.caTerraform and cloud.ca
Terraform and cloud.caCloudOps2005
 
Rapid Infrastructure Provisioning
Rapid Infrastructure ProvisioningRapid Infrastructure Provisioning
Rapid Infrastructure ProvisioningUchit Vyas ☁
 
Infrastructure as Code: Introduction to Terraform
Infrastructure as Code: Introduction to TerraformInfrastructure as Code: Introduction to Terraform
Infrastructure as Code: Introduction to TerraformAlexander Popov
 
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
DevOps - Infrastructure as Code by Andre Marcelo-TannerDevOps - Infrastructure as Code by Andre Marcelo-Tanner
DevOps - Infrastructure as Code by Andre Marcelo-TannerDEVCON
 
2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...
2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...
2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...devopsdaysaustin
 
AWS Webcast - How to Migrate On-premise NAS Storage to Cloud NAS Storage
AWS Webcast - How to Migrate On-premise NAS Storage to Cloud NAS StorageAWS Webcast - How to Migrate On-premise NAS Storage to Cloud NAS Storage
AWS Webcast - How to Migrate On-premise NAS Storage to Cloud NAS StorageAmazon Web Services
 
Rediscovering Developer Opportunities in the Philippines by Fred Tshidimba
Rediscovering Developer Opportunities in the Philippines by Fred TshidimbaRediscovering Developer Opportunities in the Philippines by Fred Tshidimba
Rediscovering Developer Opportunities in the Philippines by Fred TshidimbaDEVCON
 
TerraformでECS+ECRする話
TerraformでECS+ECRする話TerraformでECS+ECRする話
TerraformでECS+ECRする話Satoshi Hirayama
 
Jsonnet, terraform & packer
Jsonnet, terraform & packerJsonnet, terraform & packer
Jsonnet, terraform & packerDavid Cunningham
 
Infrastructure as code with Terraform
Infrastructure as code with TerraformInfrastructure as code with Terraform
Infrastructure as code with TerraformSam Bashton
 
Automation with Packer and TerraForm
Automation with Packer and TerraFormAutomation with Packer and TerraForm
Automation with Packer and TerraFormWesley Charles Blake
 
Delivering Go.CD with Terraform and Docker
Delivering Go.CD with Terraform and DockerDelivering Go.CD with Terraform and Docker
Delivering Go.CD with Terraform and DockerJorrit Salverda
 
AWS re:Invent 2016| GAM401 | Riot Games: Standardizing Application Deployment...
AWS re:Invent 2016| GAM401 | Riot Games: Standardizing Application Deployment...AWS re:Invent 2016| GAM401 | Riot Games: Standardizing Application Deployment...
AWS re:Invent 2016| GAM401 | Riot Games: Standardizing Application Deployment...Amazon Web Services
 

Viewers also liked (20)

Terraform: Cloud Configuration Management (WTC/IPC'16)
Terraform: Cloud Configuration Management (WTC/IPC'16)Terraform: Cloud Configuration Management (WTC/IPC'16)
Terraform: Cloud Configuration Management (WTC/IPC'16)
 
Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)Building infrastructure with Terraform (Google)
Building infrastructure with Terraform (Google)
 
Terraform
TerraformTerraform
Terraform
 
Terraform and cloud.ca
Terraform and cloud.caTerraform and cloud.ca
Terraform and cloud.ca
 
Rapid Infrastructure Provisioning
Rapid Infrastructure ProvisioningRapid Infrastructure Provisioning
Rapid Infrastructure Provisioning
 
Infrastructure as Code: Introduction to Terraform
Infrastructure as Code: Introduction to TerraformInfrastructure as Code: Introduction to Terraform
Infrastructure as Code: Introduction to Terraform
 
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
DevOps - Infrastructure as Code by Andre Marcelo-TannerDevOps - Infrastructure as Code by Andre Marcelo-Tanner
DevOps - Infrastructure as Code by Andre Marcelo-Tanner
 
Terraform at Scale
Terraform at ScaleTerraform at Scale
Terraform at Scale
 
Etcd terraform by Alex Somesan
Etcd terraform by Alex SomesanEtcd terraform by Alex Somesan
Etcd terraform by Alex Somesan
 
2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...
2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...
2016 - IGNITE - Terraform to go from Zero to Prod in less than 1 month and TH...
 
Refactoring terraform
Refactoring terraformRefactoring terraform
Refactoring terraform
 
AWS Webcast - How to Migrate On-premise NAS Storage to Cloud NAS Storage
AWS Webcast - How to Migrate On-premise NAS Storage to Cloud NAS StorageAWS Webcast - How to Migrate On-premise NAS Storage to Cloud NAS Storage
AWS Webcast - How to Migrate On-premise NAS Storage to Cloud NAS Storage
 
Rediscovering Developer Opportunities in the Philippines by Fred Tshidimba
Rediscovering Developer Opportunities in the Philippines by Fred TshidimbaRediscovering Developer Opportunities in the Philippines by Fred Tshidimba
Rediscovering Developer Opportunities in the Philippines by Fred Tshidimba
 
TerraformでECS+ECRする話
TerraformでECS+ECRする話TerraformでECS+ECRする話
TerraformでECS+ECRする話
 
Jsonnet, terraform & packer
Jsonnet, terraform & packerJsonnet, terraform & packer
Jsonnet, terraform & packer
 
Infrastructure as code with Terraform
Infrastructure as code with TerraformInfrastructure as code with Terraform
Infrastructure as code with Terraform
 
London Hug 19/5 - Terraform in Production
London Hug 19/5 - Terraform in ProductionLondon Hug 19/5 - Terraform in Production
London Hug 19/5 - Terraform in Production
 
Automation with Packer and TerraForm
Automation with Packer and TerraFormAutomation with Packer and TerraForm
Automation with Packer and TerraForm
 
Delivering Go.CD with Terraform and Docker
Delivering Go.CD with Terraform and DockerDelivering Go.CD with Terraform and Docker
Delivering Go.CD with Terraform and Docker
 
AWS re:Invent 2016| GAM401 | Riot Games: Standardizing Application Deployment...
AWS re:Invent 2016| GAM401 | Riot Games: Standardizing Application Deployment...AWS re:Invent 2016| GAM401 | Riot Games: Standardizing Application Deployment...
AWS re:Invent 2016| GAM401 | Riot Games: Standardizing Application Deployment...
 

Similar to Terraform Introduction

Terraform in deployment pipeline
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipelineAnton Babenko
 
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
Aprovisionamiento multi-proveedor con Terraform  - Plain Concepts DevOps dayAprovisionamiento multi-proveedor con Terraform  - Plain Concepts DevOps day
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps dayPlain Concepts
 
Terraform 0.9 + good practices
Terraform 0.9 + good practicesTerraform 0.9 + good practices
Terraform 0.9 + good practicesRadek Simko
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsMykyta Protsenko
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesLindsay Holmwood
 
Terraform day 3
Terraform day 3Terraform day 3
Terraform day 3Kalkey
 
Meetup bangalore aug31st2019
Meetup bangalore aug31st2019Meetup bangalore aug31st2019
Meetup bangalore aug31st2019D.Rajesh Kumar
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013grim_radical
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slidesDocker, Inc.
 
Declarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with TerraformDeclarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with TerraformRadek Simko
 
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
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStackBram Vogelaar
 
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
 
Infrastructure as code terraformujeme cloud
Infrastructure as code   terraformujeme cloudInfrastructure as code   terraformujeme cloud
Infrastructure as code terraformujeme cloudViliamPucik
 
Unlocked Nov 2013: Main Slide Pack
Unlocked Nov 2013: Main Slide PackUnlocked Nov 2013: Main Slide Pack
Unlocked Nov 2013: Main Slide PackRackspace Academy
 
Introduction to Apache Mesos
Introduction to Apache MesosIntroduction to Apache Mesos
Introduction to Apache MesosJoe Stein
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteBram Vogelaar
 

Similar to Terraform Introduction (20)

Terraform in deployment pipeline
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipeline
 
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
Aprovisionamiento multi-proveedor con Terraform  - Plain Concepts DevOps dayAprovisionamiento multi-proveedor con Terraform  - Plain Concepts DevOps day
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
 
London HUG 12/4
London HUG 12/4London HUG 12/4
London HUG 12/4
 
Terraform 0.9 + good practices
Terraform 0.9 + good practicesTerraform 0.9 + good practices
Terraform 0.9 + good practices
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and OpsInfrastructure-as-code: bridging the gap between Devs and Ops
Infrastructure-as-code: bridging the gap between Devs and Ops
 
Burn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websitesBurn down the silos! Helping dev and ops gel on high availability websites
Burn down the silos! Helping dev and ops gel on high availability websites
 
Terraform day 3
Terraform day 3Terraform day 3
Terraform day 3
 
Meetup bangalore aug31st2019
Meetup bangalore aug31st2019Meetup bangalore aug31st2019
Meetup bangalore aug31st2019
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013
 
Docker Security workshop slides
Docker Security workshop slidesDocker Security workshop slides
Docker Security workshop slides
 
Declarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with TerraformDeclarative & workflow based infrastructure with Terraform
Declarative & workflow based infrastructure with Terraform
 
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 -
 
TIAD : Automating the modern datacenter
TIAD : Automating the modern datacenterTIAD : Automating the modern datacenter
TIAD : Automating the modern datacenter
 
Puppet and the HashiStack
Puppet and the HashiStackPuppet and the HashiStack
Puppet and the HashiStack
 
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...
 
Infrastructure as code terraformujeme cloud
Infrastructure as code   terraformujeme cloudInfrastructure as code   terraformujeme cloud
Infrastructure as code terraformujeme cloud
 
Puppet
PuppetPuppet
Puppet
 
Unlocked Nov 2013: Main Slide Pack
Unlocked Nov 2013: Main Slide PackUnlocked Nov 2013: Main Slide Pack
Unlocked Nov 2013: Main Slide Pack
 
Introduction to Apache Mesos
Introduction to Apache MesosIntroduction to Apache Mesos
Introduction to Apache Mesos
 
Integrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suiteIntegrating icinga2 and the HashiCorp suite
Integrating icinga2 and the HashiCorp suite
 

Recently uploaded

Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 

Recently uploaded (20)

Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 

Terraform Introduction

  • 3. In Relation To... Puppet, Salt Boto, Fog CloudFormation Vagrant? 3 / 34
  • 6. Terraform and Go Terraform is written in Go (golang) dev version http://blog.snowfrog.net/2014/12/04/building-the-development- version-of-terraform/ http://bit.ly/1vNjuIU docs -- grep 6 / 34
  • 7. Using a Provider provider "aws" { access_key = "ACCESS_KEY_HERE" secret_key = "SECRET_KEY_HERE" region = "us-east-1" } resource "aws_instance" "example" { ami = "ami-408c7f28" instance_type = "t1.micro" } 7 / 34
  • 8. Terraform Plan $ terraform plan ... + aws_instance.example ami: "" => "ami-408c7f28" availability_zone: "" => "<computed>" instance_type: "" => "t1.micro" key_name: "" => "<computed>" private_dns: "" => "<computed>" private_ip: "" => "<computed>" public_dns: "" => "<computed>" public_ip: "" => "<computed>" security_groups: "" => "<computed>" subnet_id: "" => "<computed>" 8 / 34
  • 9. Terraform Apply $ terraform apply aws_instance.example: Creating... ami: "" => "ami-408c7f28" instance_type: "" => "t1.micro" Apply complete! Resources: 1 added, 0 changed, 0 destroyed. ... 9 / 34
  • 10. terraform.tfstate JSON file TerraformShow $ terraform show aws_instance.example: id = i-e60900cd ami = ami-408c7f28 availability_zone = us-east-1c instance_type = t1.micro key_name = private_dns = domU-12-31-39-12-38-AB.compute-1.internal private_ip = 10.200.59.89 public_dns = ec2-54-81-21-192.compute-1.amazonaws.com public_ip = 54.81.21.192 security_groups.# = 1 security_groups.0 = default subnet_id = 10 / 34
  • 11. Plan/Apply - Video provider "aws" { access_key = "AKIA................" secret_key = "puOt...................................." region = "ap-southeast-2" } resource "aws_instance" "example" { key_name = "sonia" # AWS keypair name ami = "ami-9b0b62a1" # Ubuntu 14.04 instance_type = "t1.micro" } demo01 11 / 34
  • 12. Changing Infrastructure Edit resource "aws_instance" "example" { ami = "ami-aa7ab6c2" # NEW AMI instance_type = "t1.micro" } 12 / 34
  • 13. Changing Infrastructure Plan $ terraform plan ... -/+ aws_instance.example ami: "ami-408c7f28" => "ami-aa7ab6c2" (forces new resource) availability_zone: "us-east-1c" => "<computed>" ... 13 / 34
  • 14. Changing Infrastructure Apply $ terraform apply aws_instance.example: Destroying... aws_instance.example: Modifying... ami: "ami-408c7f28" => "ami-aa7ab6c2" Apply complete! Resources: 0 added, 1 changed, 1 destroyed. ... 14 / 34
  • 15. Destroy Infrastructure Plan $ terraform plan -destroy ... - aws_instance.example 15 / 34
  • 16. Destroy $ terraform destroy aws_instance.example: Destroying... Apply complete! Resources: 0 added, 0 changed, 1 destroyed. ... 16 / 34
  • 17. Changing Infrastructure - Video provider "aws" { access_key = "AKIA................" secret_key = "puOt...................................." region = "ap-southeast-2" } resource "aws_instance" "example" { key_name = "sonia" # AWS keypair name ami = "ami-950b62af" # Ubuntu 14.04 instance_type = "t2.small" # CHANGED } demo02 17 / 34
  • 18. Resource Dependencies multiple providers multiple resource types do x before y, and y needs x's ip address 18 / 34
  • 19. Resource Dependencies resource "aws_eip" "ip" { instance = "${aws_instance.example.id}" # IMPLICIT } Plan $ terraform plan ... + aws_eip.ip instance: "" => "${aws_instance.example.id}" private_ip: "" => "<computed>" public_ip: "" => "<computed>" + aws_instance.example ami: "" => "ami-aa7ab6c2" ... 19 / 34
  • 20. Resource Dependencies Apply aws_instance.example: Creating... ami: "" => "ami-aa7ab6c2" instance_type: "" => "t1.micro" aws_eip.ip: Creating... instance: "" => "i-0e737b25" Apply complete! Resources: 2 added, 0 changed, 0 destroyed. Run order is different from output order. 20 / 34
  • 21. Explicit Dependencies resource "aws_eip" "ip" { instance = "${aws_instance.example.id}" depends_on = ["aws_instance.example"] } terraformgraph 21 / 34
  • 22. Dependencies - Video provider "aws" { access_key = "AKIA................" secret_key = "puOt...................................." region = "ap-southeast-2" } resource "aws_instance" "example" { key_name = "sonia" # AWS keypair name ami = "ami-9b0b62a1" # Ubuntu 14.04 instance_type = "t1.micro" } resource "aws_eip" "example_eip" { instance = "${aws_instance.example.id}" } demo03 22 / 34
  • 24. Connection/File Provisioner - Video provider "aws" { access_key = "AKIA................" secret_key = "puOt...................................." region = "ap-southeast-2" } resource "aws_instance" "example" { key_name = "sonia" # AWS keypair name ami = "ami-9b0b62a1" # Ubuntu 14.04 instance_type = "t1.micro" connection { user = "ubuntu" host = "${aws_instance.example.public_ip}" key_file = "../include/sonia.pem" } provisioner "file" { source = "bootstrap" destination = "/var/tmp" } } demo04 24 / 34
  • 25. Exec Provisioners - Video provider "aws" { access_key = "AKIA................" secret_key = "puOt...................................." region = "ap-southeast-2" } resource "aws_instance" "example" { key_name = "sonia" # AWS keypair name ami = "ami-9b0b62a1" # Ubuntu 14.04 instance_type = "t1.micro" connection { user = "ubuntu" host = "${aws_instance.example.public_ip}" key_file = "../include/sonia.pem" } provisioner "local-exec" { command = "echo ${aws_instance.example.public_ip} > ip.txt" } provisioner "remote-exec" { inline = [ "sudo locale-gen en_AU.UTF-8" ] } provisioner "remote-exec" { script = "script1.sh" } } demo05 25 / 34
  • 27. Input Variables Commonly named variables.tf, uses all *.tf files. variable "access_key" {} variable "secret_key" {} variable "region" { default = "us-east-1" } 27 / 34
  • 28. Using Variables provider "aws" { access_key = "${var.access_key}" secret_key = "${var.secret_key}" region = "${var.region}" } 28 / 34
  • 29. Assigning Variables CommandLine $ terraform apply -var 'access_key=foo' -var 'secret_key=bar' File terraform.tfvars or use -var-file access_key = "foo" secret_key = "bar" 29 / 34
  • 30. Outputs Variables Defining output "ip" { value = "${aws_eip.ip.public_ip}" } Viewing $ terraform apply ... Apply complete! Resources: 0 added, 0 changed, 0 destroyed. Outputs: ip = 50.17.232.209 30 / 34
  • 31. Modules Create $ mkdir child $ touch child/main.tf Use module "child" { source = "./child" } 31 / 34
  • 32. Module Parameters - Input Caller module "child" { source = "./child" memory = "1G" } Child variable "memory" {} resource "aws_db_instance" "default" { ... allocated_storage = "${var.memory}" ... } 32 / 34
  • 33. Module Parameters - Output Child output "result" { value = "${foo.region}-${bar.city}" } Caller module "child" { ... } resource "aws_instance" "web" { ... tags { Location = "${module.child.result}" } ... } 33 / 34