SlideShare a Scribd company logo
CONTINUOUSLY
DELIVERING
INFRASTRUCTURE
USING TERRAFORM
AND PACKER
Hello!
I AM ANTON BABENKO
I enjoy AWS, DevOps, solutions architecture & web-development.
github.com/antonbabenko
linkedin.com/in/antonbabenko
0.
AGENDA
0.
AGENDA
1. State of things
2. Basics of Terraform and Packer
Getting started demo
3. More advanced concepts in Terraform
Practice
4. Working as a team
CI/CD pipeline with Terraform and Packer
Practice
5. Resources
1.
STATE OF THINGS
Tools for AWS & Infrastructure as code
AVAILABLE TOOLS
AWS CloudFormation, Google Deployment Manager
Puppet, Chef, Ansible, Salt…
AWS API, libraries (Boto, Fog)
Terraform & Packer by HashiCorp
www.packer.io
TERRAFORM
Terraform is a tool for building, changing, and versioning infrastructure safely and
efficiently.
www.terraform.io
Version: 0.6.8 (released 2.12.2015)
Open-source, written in Golang.
Very active development:
CHANGELOG.md (ca. 1 release per month)
GitHub Issues (ca. 5-15 issues resolving daily)
Growing community (IRC, Mailing list, Stack Overflow)
TERRAFORM FACTS (2015)
Latest version: 0.9.4 (released 26.4.2017)
Open-source, written in Golang.
Very active development:
CHANGELOG.md (ca. 3 releases per month)
GitHub Issues (10+ issues resolving daily)
Growing community (IRC, Mailing list, Stack Overflow, Slack channels, Gitter, etc)
TERRAFORM FACTS (2017)
TERRAFORM VS
CLOUDFORMATION
Year 2015 CloudFormation Terraform
Configuration format JSON HCL/JSON
State management No Yes
Execution control No Yes!
Logical comparisons Yes Limited
Supports iterations No Yes
Manage already
created resources
No Yes (hard)
Providers supported Only AWS
20+ (incl. AWS,
GCE, Azure)
Year 2017 CloudFormation Terraform
Configuration format YAML/JSON HCL/JSON
State management Kind of Yes
Execution control Yes Yes!
Logical comparisons Yes Yes
Supports iterations Yes Yes
Manage already
created resources
No Yes!
Providers supported Only AWS
60+ (incl. AWS,
GCE, Azure)
CloudFormation
(2015)
Terraform 0.6.8
(2015)
Terraform 0.9.4
(2017)
AWS resource
types
121 103 280
Resource
properties and
operations
completeness
90%
Work in
progress
Work in
progress :)
Handle failures
Optional
rollback
Fix it & retry
Exit faster. Fix
it & retry
Contribute? No Yes! Yes!
AWS SPECIFICS
2.
TERRAFORM
Commands
TERRAFORM COMMANDS
$ terraform
Usage: terraform [--version] [--help] <command> [args]
Common commands:
apply Builds or changes infrastructure
console Interactive console for Terraform interpolations
destroy Destroy Terraform-managed infrastructure
env Environment management
fmt Rewrites config files to canonical format
get Download and install modules for the configuration
graph Create a visual graph of Terraform resources
import Import existing infrastructure into Terraform
init Initialize a new or existing Terraform configuration
output Read an output from a state file
plan Generate and show an execution plan
push Upload this Terraform module to Atlas to run
refresh Update local state file against real resources
show Inspect Terraform state or plan
taint Manually mark a resource for recreation
untaint Manually unmark a resource as tainted
validate Validates the Terraform files
version Prints the Terraform version
All other commands:
debug Debug output management (experimental)
force-unlock Manually unlock the terraform state
state Advanced state management
TERRAFORM INIT
Initialize a new or existing Terraform environment by creating initial files, loading
any remote state, downloading modules, etc.
*.tf
Your
infrastructure
terraform.tfstate
S3,
Atlas, Consul,
etcd, HTTP
TERRAFORM PLAN
Generates an execution plan for Terraform
*.tf
Your
infrastructure
terraform.tfstate
TERRAFORM APPLY
Builds or changes infrastructure according to Terraform configuration files
*.tf
Your
infrastructure
terraform.tfstate
TERRAFORM etc
# Draw dependency graph (require “graphviz”)
terraform graph -draw-cycles | dot -Tpng -o graph.png
# Show help
terraform --help
TERRAFORM & PACKER DEMO1
Code inside {terraform,packer}/demo1:
https://github.com/antonbabenko/cd-terraform-demo
3.
TERRAFORM
More advanced...
TERRAFORM AHEAD
Variables
Modules
States
Backends
Data sources, providers, provisioners
Conditions
TERRAFORM - MODULES
Modules in Terraform are self-contained packages of Terraform configurations that are managed as a group.
Links:
https://github.com/terraform-community-modules/
Lots of github repositories (588)
module "network_security" {
source = "git::git@github.com:myself/tf_modules.git//modules/network/security?ref=v1.0.0"
vpc_cidr = "${var.vpc_cidr}"
}
TERRAFORM - VARIABLES
Terraform != programming language
Types: string, number, boolean, list, map
Interpolation functions: length, element, file …
Interpolation is not allowed everywhere
Links:
https://www.terraform.io/docs/configuration/syntax.html
variable "iam_users" {
description = "List of IAM users to create"
type = "list"
}
resource "aws_iam_user" "users" {
count = "${length(var.iam_users)}"
name = "${element(var.iam_users, count.index)}"
}
TERRAFORM - RESOURCES
Links:
https://www.terraform.io/docs/configuration/resources.html
resource "aws_autoscaling_group" "application" {
name = "${var.name}"
launch_configuration = "${aws_launch_configuration.application.name}"
vpc_zone_identifier = ["${module.public_subnet.subnet_ids}"]
depends_on = ["module.s3_artifacts"]
tag {
key = "Name"
value = "${var.name}"
propagate_at_launch = true
}
lifecycle {
create_before_destroy = true
ignore_changes = ["desired_capacity"]
}
}
TERRAFORM - DATA SOURCES
Links:
https://www.terraform.io/docs/configuration/data-sources.html
data "aws_ami" "ami" {
most_recent = true
filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
}
owners = ["099720109477"] // Canonical
}
resource "aws_launch_configuration" "application" {
image_id = "${data.aws_ami.ami.image_id}"
}
TERRAFORM - OUTPUTS
Links:
https://www.terraform.io/docs/configuration/outputs.html
output "application_name" {
value = "${var.name}"
}
output "vpc_id" {
value = "${module.vpc.vpc_id}"
}
TERRAFORM - STATES & BACKENDS
Terraform keeps state of managed infrastructure and configuration in “terraform.tfstate”.
Links:
https://www.terraform.io/docs/state/index.html
https://www.terraform.io/docs/backends/index.html
terraform {
backend "s3" {
bucket = "my-tf-states"
key = "staging/eu-west-1/shared"
region = "eu-west-1"
lock_table = "terraform_locks"
}
}
TERRAFORM - REMOTE STATES
Links:
https://www.terraform.io/docs/providers/terraform/d/remote_state.html
data "terraform_remote_state" "shared" {
backend = "s3"
config {
bucket = "my-tf-states"
region = "eu-west-1"
key = "staging/eu-west-1/shared"
encrypt = true
}
}
output "vpc_id" {
value = "${data.terraform_remote_state.shared.vpc_id}"
}
TERRAFORM - CONDITIONS
Links:
https://blog.gruntwork.io/terraform-tips-tricks-loops-if-statements-and-gotchas-f739bbae55f9
module "application" {
is_feature = "${replace(replace(terraform.env, "/^[^(feature)].*/", "false"), "/^feature.*/", "true")}"
}
# Example: If ... then
resource "foo" "bar" {
count = "${var.enable_ssl}" # true => 1, false => 0
}
# Example: If not ... then
resource "foo" "bar" {
count = "${1-var.enable_ssl}" # true => 1, false => 0
}
TERRAFORM DEMO2
Code inside terraform/demo2 :
https://github.com/antonbabenko/cd-terraform-demo
4.
TERRAFORM
Working as a team...
● How to structure your configs?
Reduce radius blast
Size matters a lot
Structure based on teams (infrastructure team-members = network; developers = modules owners)
Separate repositories for modules and infrastructure
Infrastructure can share same repository as application
● How to continuously test infrastructure using Terraform?
Validate, plan, env
Test modules independently, include working examples and README
Test Kitchen, Inspec, Serverspec…
Full run with smaller (yet, sane!) values
TERRAFORM HOW?
TERRAFORM WORK FLOW
Init, plan, apply, apply, plan, apply…
Executors:
Single developer
Multiple developers
Requires remote backend configuration (locks for lengthy operations)
CI system
Notes:
MFA?
Module versioning is important
Group code by both - region and environment (staging, prod)
TERRAFORM WORK FLOW
Init, plan, apply, apply, plan, apply…
Open a Pull request:
Validation (terraform validate)
Optionally: Create new ephemeral (short-lived) Terraform environment (“terraform env new feature-branch”), run automated tests
(kitchen-terraform, for example) and destroy it after
Run plan and display output for review (git comment)
Branch merged into master:
Terraform apply to staging
Optionally: terragrunt apply-all
Branch tagged (release):
Terraform apply to production
TERRAFORM - EXAMPLE 1 (pseudo)
● Developer commits application code
● CI system:
○ Run tests, builds artifact
○ Packer: Bake AMI
○ Terraform: Plan and apply with just created AMI id to create deployment
○ Run integration, performance tests
○ Deploy to staging
TERRAFORM - EXAMPLE 1 - feature
● Developer commits application code to a feature branch name feature-123
● CI system:
○ Run tests, builds artifact using Packer
○ Run Packer: Bake AMI and tag it with branch=feature-123
○ Run Terraform:
■ Plan the infrastructure for test environment, where AMI id lookup is using data source ami by
tag branch=feature-123
■ Optionally, save plan to a file, prompt git user in UI, post comment to github PR
■ Apply the plan
○ Run integration, performance tests
○ Deploy to staging
TERRAFORM DEPLOYMENTS
Rolling deployments
Using provider’s mechanisms:
ECS (or other scheduler)
CloudFormation
Using custom mechanisms:
DIY scripts combined with ‘-target’ arguments
Blue-green deployments
No provider’s mechanisms for this
DIY
5.
TERRAFORM
RESOURCES
TERRAFORM RESOURCES
Books and blog posts:
Getting Started with Terraform by Kirill Shirinkin
Terraform: Up and Running: Writing Infrastructure as Code by Yevgeniy Brikman
Infrastructure as Code: Managing Servers in the Cloud by Kief Morris
Using Pipelines to Manage Environments with Infrastructure as Code by Kief Morris
Tools:
https://github.com/gruntwork-io/terragrunt
https://github.com/dtan4/terraforming
https://github.com/coinbase/terraform-landscape
https://github.com/newcontext-oss/kitchen-terraform
https://github.com/kvz/json2hcl
Other relevant repositories:
THANK YOU!
All code from this talk:
https://github.com/antonbabenko/cd-terraform-demo
Ad

More Related Content

What's hot (20)

Terraform
TerraformTerraform
Terraform
Diego Pacheco
 
Terraform
TerraformTerraform
Terraform
Harish Kumar
 
Apache Airflow
Apache AirflowApache Airflow
Apache Airflow
Sumit Maheshwari
 
Scylla Summit 2022: Making Schema Changes Safe with Raft
Scylla Summit 2022: Making Schema Changes Safe with RaftScylla Summit 2022: Making Schema Changes Safe with Raft
Scylla Summit 2022: Making Schema Changes Safe with Raft
ScyllaDB
 
DevOps avec Ansible et Docker
DevOps avec Ansible et DockerDevOps avec Ansible et Docker
DevOps avec Ansible et Docker
Stephane Manciot
 
GitOps 101 Presentation.pdf
GitOps 101 Presentation.pdfGitOps 101 Presentation.pdf
GitOps 101 Presentation.pdf
ssuser31375f
 
Terraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeTerraform -- Infrastructure as Code
Terraform -- Infrastructure as Code
Martin Schütte
 
Terraform: An Overview & Introduction
Terraform: An Overview & IntroductionTerraform: An Overview & Introduction
Terraform: An Overview & Introduction
Lee Trout
 
Docker advance topic
Docker advance topicDocker advance topic
Docker advance topic
Kalkey
 
Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explained
confluent
 
Aggregated queries with Druid on terrabytes and petabytes of data
Aggregated queries with Druid on terrabytes and petabytes of dataAggregated queries with Druid on terrabytes and petabytes of data
Aggregated queries with Druid on terrabytes and petabytes of data
Rostislav Pashuto
 
Migrating your clusters and workloads from Hadoop 2 to Hadoop 3
Migrating your clusters and workloads from Hadoop 2 to Hadoop 3Migrating your clusters and workloads from Hadoop 2 to Hadoop 3
Migrating your clusters and workloads from Hadoop 2 to Hadoop 3
DataWorks Summit
 
Snowflake Automated Deployments / CI/CD Pipelines
Snowflake Automated Deployments / CI/CD PipelinesSnowflake Automated Deployments / CI/CD Pipelines
Snowflake Automated Deployments / CI/CD Pipelines
Drew Hansen
 
Gitops Hands On
Gitops Hands OnGitops Hands On
Gitops Hands On
Brice Fernandes
 
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Simplilearn
 
Getting Started: Intro to Telegraf - July 2021
Getting Started: Intro to Telegraf - July 2021Getting Started: Intro to Telegraf - July 2021
Getting Started: Intro to Telegraf - July 2021
InfluxData
 
Apache Kafka Best Practices
Apache Kafka Best PracticesApache Kafka Best Practices
Apache Kafka Best Practices
DataWorks Summit/Hadoop Summit
 
SRE Conference 2022 - How to Build a Healthy On-Call Culture
SRE Conference 2022 - How to Build a Healthy On-Call CultureSRE Conference 2022 - How to Build a Healthy On-Call Culture
SRE Conference 2022 - How to Build a Healthy On-Call Culture
smalltown
 
Terraform in deployment pipeline
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipeline
Anton Babenko
 
Exploring the power of OpenTelemetry on Kubernetes
Exploring the power of OpenTelemetry on KubernetesExploring the power of OpenTelemetry on Kubernetes
Exploring the power of OpenTelemetry on Kubernetes
Red Hat Developers
 
Scylla Summit 2022: Making Schema Changes Safe with Raft
Scylla Summit 2022: Making Schema Changes Safe with RaftScylla Summit 2022: Making Schema Changes Safe with Raft
Scylla Summit 2022: Making Schema Changes Safe with Raft
ScyllaDB
 
DevOps avec Ansible et Docker
DevOps avec Ansible et DockerDevOps avec Ansible et Docker
DevOps avec Ansible et Docker
Stephane Manciot
 
GitOps 101 Presentation.pdf
GitOps 101 Presentation.pdfGitOps 101 Presentation.pdf
GitOps 101 Presentation.pdf
ssuser31375f
 
Terraform -- Infrastructure as Code
Terraform -- Infrastructure as CodeTerraform -- Infrastructure as Code
Terraform -- Infrastructure as Code
Martin Schütte
 
Terraform: An Overview & Introduction
Terraform: An Overview & IntroductionTerraform: An Overview & Introduction
Terraform: An Overview & Introduction
Lee Trout
 
Docker advance topic
Docker advance topicDocker advance topic
Docker advance topic
Kalkey
 
Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explained
confluent
 
Aggregated queries with Druid on terrabytes and petabytes of data
Aggregated queries with Druid on terrabytes and petabytes of dataAggregated queries with Druid on terrabytes and petabytes of data
Aggregated queries with Druid on terrabytes and petabytes of data
Rostislav Pashuto
 
Migrating your clusters and workloads from Hadoop 2 to Hadoop 3
Migrating your clusters and workloads from Hadoop 2 to Hadoop 3Migrating your clusters and workloads from Hadoop 2 to Hadoop 3
Migrating your clusters and workloads from Hadoop 2 to Hadoop 3
DataWorks Summit
 
Snowflake Automated Deployments / CI/CD Pipelines
Snowflake Automated Deployments / CI/CD PipelinesSnowflake Automated Deployments / CI/CD Pipelines
Snowflake Automated Deployments / CI/CD Pipelines
Drew Hansen
 
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Chef vs Puppet vs Ansible vs Saltstack | Configuration Management Tools | Dev...
Simplilearn
 
Getting Started: Intro to Telegraf - July 2021
Getting Started: Intro to Telegraf - July 2021Getting Started: Intro to Telegraf - July 2021
Getting Started: Intro to Telegraf - July 2021
InfluxData
 
SRE Conference 2022 - How to Build a Healthy On-Call Culture
SRE Conference 2022 - How to Build a Healthy On-Call CultureSRE Conference 2022 - How to Build a Healthy On-Call Culture
SRE Conference 2022 - How to Build a Healthy On-Call Culture
smalltown
 
Terraform in deployment pipeline
Terraform in deployment pipelineTerraform in deployment pipeline
Terraform in deployment pipeline
Anton Babenko
 
Exploring the power of OpenTelemetry on Kubernetes
Exploring the power of OpenTelemetry on KubernetesExploring the power of OpenTelemetry on Kubernetes
Exploring the power of OpenTelemetry on Kubernetes
Red Hat Developers
 

Similar to "Continuously delivering infrastructure using Terraform and Packer" training material (20)

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
 
London HUG 12/4
London HUG 12/4London HUG 12/4
London HUG 12/4
London HashiCorp User Group
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform Training
Yevgeniy Brikman
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using Terraform
Adin Ermie
 
Terraform training 🎒 - Basic
Terraform training 🎒 - BasicTerraform training 🎒 - Basic
Terraform training 🎒 - Basic
StephaneBoghossian1
 
terraform cours intéressant et super fort
terraform cours intéressant et super fortterraform cours intéressant et super fort
terraform cours intéressant et super fort
amar719595
 
Terraform 101
Terraform 101Terraform 101
Terraform 101
Haggai Philip Zagury
 
Container Days Boston - Kubernetes in production
Container Days Boston - Kubernetes in productionContainer Days Boston - Kubernetes in production
Container Days Boston - Kubernetes in production
Mike Splain
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
Boulos Dib
 
Iniciando com Terraform
Iniciando com TerraformIniciando com Terraform
Iniciando com Terraform
Mateus Dubiela Oliveira
 
Terraform day 1
Terraform day 1Terraform day 1
Terraform day 1
Kalkey
 
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
Yevgeniy Brikman
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and Power
Calvin French-Owen
 
Terraform infraestructura como código
Terraform infraestructura como códigoTerraform infraestructura como código
Terraform infraestructura como código
Victor Adsuar
 
Provisioning Datadog with Terraform
Provisioning Datadog with TerraformProvisioning Datadog with Terraform
Provisioning Datadog with Terraform
Matt Spurlin
 
Debasihish da final.ppt
Debasihish da final.pptDebasihish da final.ppt
Debasihish da final.ppt
Kalkey
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
Ridwan Fadjar
 
Terraform day1
Terraform day1Terraform day1
Terraform day1
Gourav Varma
 
"Modern DevOps & Real Life Applications. 3.0.0-devops+20230318", Igor Fesenko
"Modern DevOps & Real Life Applications. 3.0.0-devops+20230318", Igor Fesenko "Modern DevOps & Real Life Applications. 3.0.0-devops+20230318", Igor Fesenko
"Modern DevOps & Real Life Applications. 3.0.0-devops+20230318", Igor Fesenko
Fwdays
 
Introductory Overview to Managing AWS with Terraform
Introductory Overview to Managing AWS with TerraformIntroductory Overview to Managing AWS with Terraform
Introductory Overview to Managing AWS with Terraform
Michael Heyns
 
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
 
Comprehensive Terraform Training
Comprehensive Terraform TrainingComprehensive Terraform Training
Comprehensive Terraform Training
Yevgeniy Brikman
 
Infrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using TerraformInfrastructure-as-Code (IaC) using Terraform
Infrastructure-as-Code (IaC) using Terraform
Adin Ermie
 
terraform cours intéressant et super fort
terraform cours intéressant et super fortterraform cours intéressant et super fort
terraform cours intéressant et super fort
amar719595
 
Container Days Boston - Kubernetes in production
Container Days Boston - Kubernetes in productionContainer Days Boston - Kubernetes in production
Container Days Boston - Kubernetes in production
Mike Splain
 
Introduction to PowerShell
Introduction to PowerShellIntroduction to PowerShell
Introduction to PowerShell
Boulos Dib
 
Terraform day 1
Terraform day 1Terraform day 1
Terraform day 1
Kalkey
 
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
Yevgeniy Brikman
 
Terraform Abstractions for Safety and Power
Terraform Abstractions for Safety and PowerTerraform Abstractions for Safety and Power
Terraform Abstractions for Safety and Power
Calvin French-Owen
 
Terraform infraestructura como código
Terraform infraestructura como códigoTerraform infraestructura como código
Terraform infraestructura como código
Victor Adsuar
 
Provisioning Datadog with Terraform
Provisioning Datadog with TerraformProvisioning Datadog with Terraform
Provisioning Datadog with Terraform
Matt Spurlin
 
Debasihish da final.ppt
Debasihish da final.pptDebasihish da final.ppt
Debasihish da final.ppt
Kalkey
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
Ridwan Fadjar
 
"Modern DevOps & Real Life Applications. 3.0.0-devops+20230318", Igor Fesenko
"Modern DevOps & Real Life Applications. 3.0.0-devops+20230318", Igor Fesenko "Modern DevOps & Real Life Applications. 3.0.0-devops+20230318", Igor Fesenko
"Modern DevOps & Real Life Applications. 3.0.0-devops+20230318", Igor Fesenko
Fwdays
 
Introductory Overview to Managing AWS with Terraform
Introductory Overview to Managing AWS with TerraformIntroductory Overview to Managing AWS with Terraform
Introductory Overview to Managing AWS with Terraform
Michael Heyns
 
Ad

More from Anton Babenko (20)

Manage any AWS resources with Terraform 0.12 - April 2020
Manage any AWS resources with Terraform 0.12 - April 2020Manage any AWS resources with Terraform 0.12 - April 2020
Manage any AWS resources with Terraform 0.12 - April 2020
Anton Babenko
 
Terraform 0.12 + Terragrunt
Terraform 0.12 + TerragruntTerraform 0.12 + Terragrunt
Terraform 0.12 + Terragrunt
Anton Babenko
 
Terraform Best Practices - DevOps Unicorns 2019
Terraform Best Practices - DevOps Unicorns 2019Terraform Best Practices - DevOps Unicorns 2019
Terraform Best Practices - DevOps Unicorns 2019
Anton Babenko
 
Terraform AWS modules and some best practices - September 2019
Terraform AWS modules and some best practices - September 2019Terraform AWS modules and some best practices - September 2019
Terraform AWS modules and some best practices - September 2019
Anton Babenko
 
What you see is what you get for AWS infrastructure
What you see is what you get for AWS infrastructureWhat you see is what you get for AWS infrastructure
What you see is what you get for AWS infrastructure
Anton Babenko
 
Terraform AWS modules and some best-practices - May 2019
Terraform AWS modules and some best-practices - May 2019Terraform AWS modules and some best-practices - May 2019
Terraform AWS modules and some best-practices - May 2019
Anton Babenko
 
Terraform modules and some of best-practices - March 2019
Terraform modules and some of best-practices - March 2019Terraform modules and some of best-practices - March 2019
Terraform modules and some of best-practices - March 2019
Anton Babenko
 
What you see is what you get for AWS infrastructure
What you see is what you get for AWS infrastructureWhat you see is what you get for AWS infrastructure
What you see is what you get for AWS infrastructure
Anton Babenko
 
Gotchas using Terraform in a secure delivery pipeline
Gotchas using Terraform in a secure delivery pipelineGotchas using Terraform in a secure delivery pipeline
Gotchas using Terraform in a secure delivery pipeline
Anton Babenko
 
Описание инфраструктуры с Terraform на будущее
Описание инфраструктуры с Terraform на будущееОписание инфраструктуры с Terraform на будущее
Описание инфраструктуры с Terraform на будущее
Anton Babenko
 
Preview of Terraform 0.12 + modules.tf - Kiev HUG meetup
Preview of Terraform 0.12 + modules.tf - Kiev HUG meetupPreview of Terraform 0.12 + modules.tf - Kiev HUG meetup
Preview of Terraform 0.12 + modules.tf - Kiev HUG meetup
Anton Babenko
 
Terraform modules and (some of) best practices
Terraform modules and (some of) best practicesTerraform modules and (some of) best practices
Terraform modules and (some of) best practices
Anton Babenko
 
Terraform modules and (some of) best practices
Terraform modules and (some of) best practicesTerraform modules and (some of) best practices
Terraform modules and (some of) best practices
Anton Babenko
 
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
Anton Babenko
 
Building infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps KrakowBuilding infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps Krakow
Anton Babenko
 
Terraform Q&A - HashiCorp User Group Oslo
Terraform Q&A - HashiCorp User Group OsloTerraform Q&A - HashiCorp User Group Oslo
Terraform Q&A - HashiCorp User Group Oslo
Anton Babenko
 
"I’ve heard you know infrastructure"
"I’ve heard you know infrastructure""I’ve heard you know infrastructure"
"I’ve heard you know infrastructure"
Anton Babenko
 
Continuous delivery in AWS
Continuous delivery in AWSContinuous delivery in AWS
Continuous delivery in AWS
Anton Babenko
 
Tools exist for a reason
Tools exist for a reasonTools exist for a reason
Tools exist for a reason
Anton Babenko
 
AWS CodeDeploy - basic intro
AWS CodeDeploy - basic introAWS CodeDeploy - basic intro
AWS CodeDeploy - basic intro
Anton Babenko
 
Manage any AWS resources with Terraform 0.12 - April 2020
Manage any AWS resources with Terraform 0.12 - April 2020Manage any AWS resources with Terraform 0.12 - April 2020
Manage any AWS resources with Terraform 0.12 - April 2020
Anton Babenko
 
Terraform 0.12 + Terragrunt
Terraform 0.12 + TerragruntTerraform 0.12 + Terragrunt
Terraform 0.12 + Terragrunt
Anton Babenko
 
Terraform Best Practices - DevOps Unicorns 2019
Terraform Best Practices - DevOps Unicorns 2019Terraform Best Practices - DevOps Unicorns 2019
Terraform Best Practices - DevOps Unicorns 2019
Anton Babenko
 
Terraform AWS modules and some best practices - September 2019
Terraform AWS modules and some best practices - September 2019Terraform AWS modules and some best practices - September 2019
Terraform AWS modules and some best practices - September 2019
Anton Babenko
 
What you see is what you get for AWS infrastructure
What you see is what you get for AWS infrastructureWhat you see is what you get for AWS infrastructure
What you see is what you get for AWS infrastructure
Anton Babenko
 
Terraform AWS modules and some best-practices - May 2019
Terraform AWS modules and some best-practices - May 2019Terraform AWS modules and some best-practices - May 2019
Terraform AWS modules and some best-practices - May 2019
Anton Babenko
 
Terraform modules and some of best-practices - March 2019
Terraform modules and some of best-practices - March 2019Terraform modules and some of best-practices - March 2019
Terraform modules and some of best-practices - March 2019
Anton Babenko
 
What you see is what you get for AWS infrastructure
What you see is what you get for AWS infrastructureWhat you see is what you get for AWS infrastructure
What you see is what you get for AWS infrastructure
Anton Babenko
 
Gotchas using Terraform in a secure delivery pipeline
Gotchas using Terraform in a secure delivery pipelineGotchas using Terraform in a secure delivery pipeline
Gotchas using Terraform in a secure delivery pipeline
Anton Babenko
 
Описание инфраструктуры с Terraform на будущее
Описание инфраструктуры с Terraform на будущееОписание инфраструктуры с Terraform на будущее
Описание инфраструктуры с Terraform на будущее
Anton Babenko
 
Preview of Terraform 0.12 + modules.tf - Kiev HUG meetup
Preview of Terraform 0.12 + modules.tf - Kiev HUG meetupPreview of Terraform 0.12 + modules.tf - Kiev HUG meetup
Preview of Terraform 0.12 + modules.tf - Kiev HUG meetup
Anton Babenko
 
Terraform modules and (some of) best practices
Terraform modules and (some of) best practicesTerraform modules and (some of) best practices
Terraform modules and (some of) best practices
Anton Babenko
 
Terraform modules and (some of) best practices
Terraform modules and (some of) best practicesTerraform modules and (some of) best practices
Terraform modules and (some of) best practices
Anton Babenko
 
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
Anton Babenko
 
Building infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps KrakowBuilding infrastructure as code using Terraform - DevOps Krakow
Building infrastructure as code using Terraform - DevOps Krakow
Anton Babenko
 
Terraform Q&A - HashiCorp User Group Oslo
Terraform Q&A - HashiCorp User Group OsloTerraform Q&A - HashiCorp User Group Oslo
Terraform Q&A - HashiCorp User Group Oslo
Anton Babenko
 
"I’ve heard you know infrastructure"
"I’ve heard you know infrastructure""I’ve heard you know infrastructure"
"I’ve heard you know infrastructure"
Anton Babenko
 
Continuous delivery in AWS
Continuous delivery in AWSContinuous delivery in AWS
Continuous delivery in AWS
Anton Babenko
 
Tools exist for a reason
Tools exist for a reasonTools exist for a reason
Tools exist for a reason
Anton Babenko
 
AWS CodeDeploy - basic intro
AWS CodeDeploy - basic introAWS CodeDeploy - basic intro
AWS CodeDeploy - basic intro
Anton Babenko
 
Ad

Recently uploaded (20)

Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Linux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdfLinux Professional Institute LPIC-1 Exam.pdf
Linux Professional Institute LPIC-1 Exam.pdf
RHCSA Guru
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-UmgebungenHCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
HCL Nomad Web – Best Practices und Verwaltung von Multiuser-Umgebungen
panagenda
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Cybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure ADCybersecurity Identity and Access Solutions using Azure AD
Cybersecurity Identity and Access Solutions using Azure AD
VICTOR MAESTRE RAMIREZ
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 

"Continuously delivering infrastructure using Terraform and Packer" training material

  • 2. Hello! I AM ANTON BABENKO I enjoy AWS, DevOps, solutions architecture & web-development. github.com/antonbabenko linkedin.com/in/antonbabenko
  • 4. 0. AGENDA 1. State of things 2. Basics of Terraform and Packer Getting started demo 3. More advanced concepts in Terraform Practice 4. Working as a team CI/CD pipeline with Terraform and Packer Practice 5. Resources
  • 5. 1. STATE OF THINGS Tools for AWS & Infrastructure as code
  • 6. AVAILABLE TOOLS AWS CloudFormation, Google Deployment Manager Puppet, Chef, Ansible, Salt… AWS API, libraries (Boto, Fog) Terraform & Packer by HashiCorp
  • 8. TERRAFORM Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. www.terraform.io
  • 9. Version: 0.6.8 (released 2.12.2015) Open-source, written in Golang. Very active development: CHANGELOG.md (ca. 1 release per month) GitHub Issues (ca. 5-15 issues resolving daily) Growing community (IRC, Mailing list, Stack Overflow) TERRAFORM FACTS (2015)
  • 10. Latest version: 0.9.4 (released 26.4.2017) Open-source, written in Golang. Very active development: CHANGELOG.md (ca. 3 releases per month) GitHub Issues (10+ issues resolving daily) Growing community (IRC, Mailing list, Stack Overflow, Slack channels, Gitter, etc) TERRAFORM FACTS (2017)
  • 12. Year 2015 CloudFormation Terraform Configuration format JSON HCL/JSON State management No Yes Execution control No Yes! Logical comparisons Yes Limited Supports iterations No Yes Manage already created resources No Yes (hard) Providers supported Only AWS 20+ (incl. AWS, GCE, Azure)
  • 13. Year 2017 CloudFormation Terraform Configuration format YAML/JSON HCL/JSON State management Kind of Yes Execution control Yes Yes! Logical comparisons Yes Yes Supports iterations Yes Yes Manage already created resources No Yes! Providers supported Only AWS 60+ (incl. AWS, GCE, Azure)
  • 14. CloudFormation (2015) Terraform 0.6.8 (2015) Terraform 0.9.4 (2017) AWS resource types 121 103 280 Resource properties and operations completeness 90% Work in progress Work in progress :) Handle failures Optional rollback Fix it & retry Exit faster. Fix it & retry Contribute? No Yes! Yes! AWS SPECIFICS
  • 16. TERRAFORM COMMANDS $ terraform Usage: terraform [--version] [--help] <command> [args] Common commands: apply Builds or changes infrastructure console Interactive console for Terraform interpolations destroy Destroy Terraform-managed infrastructure env Environment management fmt Rewrites config files to canonical format get Download and install modules for the configuration graph Create a visual graph of Terraform resources import Import existing infrastructure into Terraform init Initialize a new or existing Terraform configuration output Read an output from a state file plan Generate and show an execution plan push Upload this Terraform module to Atlas to run refresh Update local state file against real resources show Inspect Terraform state or plan taint Manually mark a resource for recreation untaint Manually unmark a resource as tainted validate Validates the Terraform files version Prints the Terraform version All other commands: debug Debug output management (experimental) force-unlock Manually unlock the terraform state state Advanced state management
  • 17. TERRAFORM INIT Initialize a new or existing Terraform environment by creating initial files, loading any remote state, downloading modules, etc. *.tf Your infrastructure terraform.tfstate S3, Atlas, Consul, etcd, HTTP
  • 18. TERRAFORM PLAN Generates an execution plan for Terraform *.tf Your infrastructure terraform.tfstate
  • 19. TERRAFORM APPLY Builds or changes infrastructure according to Terraform configuration files *.tf Your infrastructure terraform.tfstate
  • 20. TERRAFORM etc # Draw dependency graph (require “graphviz”) terraform graph -draw-cycles | dot -Tpng -o graph.png # Show help terraform --help
  • 21. TERRAFORM & PACKER DEMO1 Code inside {terraform,packer}/demo1: https://github.com/antonbabenko/cd-terraform-demo
  • 24. TERRAFORM - MODULES Modules in Terraform are self-contained packages of Terraform configurations that are managed as a group. Links: https://github.com/terraform-community-modules/ Lots of github repositories (588) module "network_security" { source = "git::[email protected]:myself/tf_modules.git//modules/network/security?ref=v1.0.0" vpc_cidr = "${var.vpc_cidr}" }
  • 25. TERRAFORM - VARIABLES Terraform != programming language Types: string, number, boolean, list, map Interpolation functions: length, element, file … Interpolation is not allowed everywhere Links: https://www.terraform.io/docs/configuration/syntax.html variable "iam_users" { description = "List of IAM users to create" type = "list" } resource "aws_iam_user" "users" { count = "${length(var.iam_users)}" name = "${element(var.iam_users, count.index)}" }
  • 26. TERRAFORM - RESOURCES Links: https://www.terraform.io/docs/configuration/resources.html resource "aws_autoscaling_group" "application" { name = "${var.name}" launch_configuration = "${aws_launch_configuration.application.name}" vpc_zone_identifier = ["${module.public_subnet.subnet_ids}"] depends_on = ["module.s3_artifacts"] tag { key = "Name" value = "${var.name}" propagate_at_launch = true } lifecycle { create_before_destroy = true ignore_changes = ["desired_capacity"] } }
  • 27. TERRAFORM - DATA SOURCES Links: https://www.terraform.io/docs/configuration/data-sources.html data "aws_ami" "ami" { most_recent = true filter { name = "name" values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"] } owners = ["099720109477"] // Canonical } resource "aws_launch_configuration" "application" { image_id = "${data.aws_ami.ami.image_id}" }
  • 28. TERRAFORM - OUTPUTS Links: https://www.terraform.io/docs/configuration/outputs.html output "application_name" { value = "${var.name}" } output "vpc_id" { value = "${module.vpc.vpc_id}" }
  • 29. TERRAFORM - STATES & BACKENDS Terraform keeps state of managed infrastructure and configuration in “terraform.tfstate”. Links: https://www.terraform.io/docs/state/index.html https://www.terraform.io/docs/backends/index.html terraform { backend "s3" { bucket = "my-tf-states" key = "staging/eu-west-1/shared" region = "eu-west-1" lock_table = "terraform_locks" } }
  • 30. TERRAFORM - REMOTE STATES Links: https://www.terraform.io/docs/providers/terraform/d/remote_state.html data "terraform_remote_state" "shared" { backend = "s3" config { bucket = "my-tf-states" region = "eu-west-1" key = "staging/eu-west-1/shared" encrypt = true } } output "vpc_id" { value = "${data.terraform_remote_state.shared.vpc_id}" }
  • 31. TERRAFORM - CONDITIONS Links: https://blog.gruntwork.io/terraform-tips-tricks-loops-if-statements-and-gotchas-f739bbae55f9 module "application" { is_feature = "${replace(replace(terraform.env, "/^[^(feature)].*/", "false"), "/^feature.*/", "true")}" } # Example: If ... then resource "foo" "bar" { count = "${var.enable_ssl}" # true => 1, false => 0 } # Example: If not ... then resource "foo" "bar" { count = "${1-var.enable_ssl}" # true => 1, false => 0 }
  • 32. TERRAFORM DEMO2 Code inside terraform/demo2 : https://github.com/antonbabenko/cd-terraform-demo
  • 34. ● How to structure your configs? Reduce radius blast Size matters a lot Structure based on teams (infrastructure team-members = network; developers = modules owners) Separate repositories for modules and infrastructure Infrastructure can share same repository as application ● How to continuously test infrastructure using Terraform? Validate, plan, env Test modules independently, include working examples and README Test Kitchen, Inspec, Serverspec… Full run with smaller (yet, sane!) values TERRAFORM HOW?
  • 35. TERRAFORM WORK FLOW Init, plan, apply, apply, plan, apply… Executors: Single developer Multiple developers Requires remote backend configuration (locks for lengthy operations) CI system Notes: MFA? Module versioning is important Group code by both - region and environment (staging, prod)
  • 36. TERRAFORM WORK FLOW Init, plan, apply, apply, plan, apply… Open a Pull request: Validation (terraform validate) Optionally: Create new ephemeral (short-lived) Terraform environment (“terraform env new feature-branch”), run automated tests (kitchen-terraform, for example) and destroy it after Run plan and display output for review (git comment) Branch merged into master: Terraform apply to staging Optionally: terragrunt apply-all Branch tagged (release): Terraform apply to production
  • 37. TERRAFORM - EXAMPLE 1 (pseudo) ● Developer commits application code ● CI system: ○ Run tests, builds artifact ○ Packer: Bake AMI ○ Terraform: Plan and apply with just created AMI id to create deployment ○ Run integration, performance tests ○ Deploy to staging
  • 38. TERRAFORM - EXAMPLE 1 - feature ● Developer commits application code to a feature branch name feature-123 ● CI system: ○ Run tests, builds artifact using Packer ○ Run Packer: Bake AMI and tag it with branch=feature-123 ○ Run Terraform: ■ Plan the infrastructure for test environment, where AMI id lookup is using data source ami by tag branch=feature-123 ■ Optionally, save plan to a file, prompt git user in UI, post comment to github PR ■ Apply the plan ○ Run integration, performance tests ○ Deploy to staging
  • 39. TERRAFORM DEPLOYMENTS Rolling deployments Using provider’s mechanisms: ECS (or other scheduler) CloudFormation Using custom mechanisms: DIY scripts combined with ‘-target’ arguments Blue-green deployments No provider’s mechanisms for this DIY
  • 41. TERRAFORM RESOURCES Books and blog posts: Getting Started with Terraform by Kirill Shirinkin Terraform: Up and Running: Writing Infrastructure as Code by Yevgeniy Brikman Infrastructure as Code: Managing Servers in the Cloud by Kief Morris Using Pipelines to Manage Environments with Infrastructure as Code by Kief Morris Tools: https://github.com/gruntwork-io/terragrunt https://github.com/dtan4/terraforming https://github.com/coinbase/terraform-landscape https://github.com/newcontext-oss/kitchen-terraform https://github.com/kvz/json2hcl Other relevant repositories:
  • 42. THANK YOU! All code from this talk: https://github.com/antonbabenko/cd-terraform-demo

Editor's Notes

  • #3: Organizer of AWS user group norway AWS certified solution architect and sysops Doing web-development, devops for the last 10+ years. Doing AWS for the last 5 years. open-source, team leadership windsurfing, sailing, paragliding
  • #7: Who is using AWS API directly or using libraries (like Troposphere written in Python) ?
  • #13: State management - TF has local tfstate file describing metadata of created resources Execution control = well controlled. Plan => output file or limit by targets => apply with confidence. CF can only validate syntax. Logical comparisons = more, less, equal value. In TF you can use “count=0” or “count=1” resource parameter instead of boolean true/false to control resource creation. Manage already created resources like EIP, S3 buckets, VPC is not possible without deleting them first.
  • #14: State management - TF has local tfstate file describing metadata of created resources Execution control = well controlled. Plan => output file or limit by targets => apply with confidence. CF can only validate syntax. Logical comparisons = more, less, equal value. In TF you can use “count=0” or “count=1” resource parameter instead of boolean true/false to control resource creation. Manage already created resources like EIP, S3 buckets, VPC is not possible without deleting them first.
  • #15: Some resource properties (for example, ec2 keypair) can be created using AWS API, but not available in CloudFormation. Terraform uses AWS API, so you can get/update missing properties in many cases. update_rollback_failed = contact customer service --- Handle failures => Partial State and Error Handling If an error happens at any stage in the lifecycle of a resource, Terraform stores a partial state of the resource. This behavior is critical for Terraform to ensure that you don't end up with any zombie resources: resources that were created by Terraform but no longer managed by Terraform due to a loss of state.
  • #18: Atlas, Consul, etcd, S3 or HTTP Terraform will automatically update remote state file once where are any changes in it. There are also ways to pull and push to remote state file.
  • #19: Refresh state locally and generate execution plan based on tf configs
  • #20: Apply the changes required to reach the desired state of the configuration. Or the pre-determined set of actions generated by a terraform plan execution plan.
  • #22: Atlas, Consul, etcd, S3 or HTTP Terraform will automatically update remote state file once where are any changes in it. There are also ways to pull and push to remote state file.
  • #33: Atlas, Consul, etcd, S3 or HTTP Terraform will automatically update remote state file once where are any changes in it. There are also ways to pull and push to remote state file.