2 Terraform-Overview
2 Terraform-Overview
2 Terraform-Overview
Provisioning infrastructure
through software to achieve
consistent and predictable
environments.
Core Concepts
Idempotent and
Push or pull
consistent
Infrastructure as Code Benefits
Automated deployment
Consistent environments
Repeatable process
Reusable components
Documented architecture
Automating Infrastructure Deployment
It’s not a magic wand that gives you power over all clouds and systems.
It embraces all major Cloud Providers and provides common language to orchestrate your infrastructure resources.
Architecture
Architecture
Architecture
Architecture
Architecture
Terraform Components
● OpenFaaS ● Docker
● GitLab ● OpenAPI ● Kubernetes
● GitHub ● Generic Rest API ● Nomad
● BitBucket ● Stateful ● Consul
● DNS ● Vault
● Palo Alto Networks ● Terraform :)
● F5 BIG-IP
● Template
● Random
● NewRelic ● Digital Ocean
● Null
● Datadog ● Fastly
● External
● PagerDuty ● OpenStack
(escape hatch)
● Heroku
● Archive
Provider Example
provider “azurerm” {
subscription_id = “subscription-id”
client_id = “principal-used-for-access”
client_secret = “password-of-principal”
tenant_id = “tenant-id”
alias = “arm-1”
}
Terraform Code
Terraform Syntax
Type Name
Terraform: Example (Simple local resource)
variable "aws_access_key" {} Variables
variable "aws_secret_key" {}
provider "aws" {
Provider
access_key = "access_key“
secret_key = “secret_key”
region = “us-east-1”
}
resource "aws_instance" "ex"{
Resource
ami = "ami-c58c1dd3"
instance_type = "t2.micro"
}
output "aws_public_ip" {
Output
value =
"${aws_instance.ex.public_dns}"
}
Code Example
provider “azurerm” {
subscription_id = “subscription-id”
client_id = “principal-used-for-access”
client_secret = “password-of-principal”
tenant_id = “tenant-id”
alias = “arm-1”
}
resource “azurerm_resource_group”{
name = “resource-group-name”
location = “East US”
provider = “azurerm.arm-1”
}
Terraform Syntax
#Create a variable
variable var_name {
key = value #type, default, description
}
#Use a variable
${var.name} #get string
${var.map[“key”]} #get map element
${var.list[idx]} #get list element
Terraform Syntax
#Create provider
provider provider_name {
key = value #depends on resource, use alias as needed
}
#Create data object
data data_type data_name {}
#Use data object
${data_type.data_name.attribute(args)}
Terraform Syntax
#Create resource
resource resource_type resource_name {
key = value #depends on resource
}
#Reference resource
${resource_type.resource_name.attribute(args)}
Terraform Workflow
Workflow: Adoption stages
Single
contributor
Terraform Core: Init
The terraform state can be saved remote, using the backend functionality in
terraform.
Play along!
- AWS account
- Demo files
Examine the Terraform file
Deploy theconfiguration
Play along!
- AWS account
- Terraform software (terraform.io)
- Demo files
Examine the Terraform file
Demo Deploy the configuration
Review the results
Play along!
- AWS account
- Terraform software (terraform.io)
- Demo files