SlideShare a Scribd company logo
Terraform in deployment pipeline
by Anton Babenko
Hi!
I am Anton Babenko, and I enjoy:
● AWS & DevOps
● AWS User Group Norway and DevOpsDays Oslo organizer
● Solve problems
“Getting Started with Terraform”,
terraform-community-modules, Terraform modules generator
(Terrapin), and more…
https://github.com/antonbabenko https://www.linkedin.com/in/antonbabenko
1. Become more familiar with managing infrastructure using CD pipeline
2. See scenarios of integrating Terraform and Packer
3. How to structure infrastructure code?
4. How to version your infrastructure between environments and make it DRY?
Goals of this talk
Do you know?
What is:
● Infrastructure as code?
● Deployment pipeline?
● Pipeline as code?
Featuring...
Write, plan, and create infrastructure as code Build automated machine images
Terraform in deployment pipeline
Typical CI/CD pipeline
source: https://dzone.com/articles/what-is-continuous-delivery-pipeline
Where are infrastructure changes here?
CI/CD pipeline (CircleCI 2.0)
Structure - all-in-one vs split
~/all-in-one-repo/
├── packer # Packer configs
│ └── app.json
├── terraform # Terraform configs
│ ├── main.tf
│ └── terraform.tfvars
└── web # Application code
└── index.html
~/infra-repo/
├── packer # Packer configs
│ └── app.json
└── terraform # Terraform configs
├── main.tf
└── terraform.tfvars
~/app-repo/
└── web # Application code
└── index.html
Structure - evolving infrastructure repository
~/infra-repo/
├── packer # Packer configs
│ └── app.json
└── terraform # Terraform configs
├── modules # Terraform modules
│ ├── network
│ │ └── main.tf
│ └── service1
│ └── main.tf
├── main.tf
└── terraform.tfvars
~/infra-repo/
├── packer # Packer configs
│ └── app.json
└── terraform # Terraform configs
├── modules # Terraform modules
│ ├── network
│ │ └── main.tf
│ └── service1
│ └── main.tf
└── environments
├── non-prod
│ └── us-east-1
│ ├── main.tf
│ └── terraform.tfvars
└── prod
├── eu-west-1
│ ├── main.tf
│ └── terraform.tfvars
└── us-east-1
├── main.tf
└── terraform.tfvars
example1/main.tf
resource "random_pet" "bucket" {}
resource "aws_s3_bucket" "app" {
bucket = "fullstackfest-${ random_pet .bucket. id}"
acl = "public-read"
website {
index_document = "index.html"
}
}
data "template_file" "index" {
template = "${file("../../web/index.html")}"
vars {
BUILD_DETAILS = "${aws_s3_bucket .app.website_endpoint }"
}
}
resource "aws_s3_bucket_object" "object" {
bucket = "${aws_s3_bucket .app.id}"
key = "index.html"
content = "${data. template_file .index.rendered }"
etag = "${md5(data. template_file .index.rendered )}"
content_type = "text/html"
acl = "public-read"
}
output "app_website_endpoint" {
value = "${aws_s3_bucket .app.website_endpoint }"
}
FullStackFest!
${BUILD_DETAILS}
$ terraform init
...
$ terraform plan
...
$ terraform apply
...
Apply complete! Resources: 3 added, 0 changed, 0 destroyed.
Outputs:
app_website_endpoint =
fullstackfest-feasible-basilisk.s3-website-eu-west-1.amazonaws.c
om
example2/main.tf
variable "subnet_id" {
description = "ID of subnet where resources will be created"
}
variable "security_groups" {
description = "ID of security group EC2 instance will use"
}
variable "instance_type" {
description = "Type of EC2 instance to launch"
}
data "aws_ami" "app" {
most_recent = true
filter {
name = "name"
values = ["fullstackfest-demo-*" ]
}
}
resource "aws_instance" "app" {
ami = "${data. aws_ami.app.id}"
instance_type = "${var.instance_type }"
subnet_id = "${var.subnet_id }"
vpc_security_group_ids = ["${var.security_groups }"]
}
output "app_public_ip" {
description = "Public IP of EC2 instance running an
application"
value = "${aws_instance .app.public_ip }"
}
packer/app.json
{
"builders" : [
{
"ami_name" : "fullstackfest-demo-{{uuid | clean_ami_name}}" ,
"ami_description" : "FullStackFest demo AMI based on Amazon
Linux",
"instance_type" : "t2.micro" ,
"region" : "eu-west-1" ,
"type": "amazon-ebs" ,
"ssh_username" : "ec2-user" ,
"source_ami_filter" : {
"filters" : {
"virtualization-type" : "hvm",
"name": "amzn-ami-hvm-*-x86_64-gp2" ,
"root-device-type" : "ebs"
},
"owners" : [
"137112412989"
],
"most_recent" : true
}
}
],
"provisioners" : [
{
"type": "shell",
"inline" : [
"# Install nginx, copy index.html into web-root"
]
}
]
}
# Avoid hard-coded values in *.tf files, use data sources or
*.tfvars
data "aws_ami" "app" {
most_recent = true
filter {
name = "name"
values = ["fullstackfest-demo-*" ]
}
}
# Tag and name resources consistently
resource "aws_instance" "app" {
ami = "${data. aws_ami.app.id}"
instance_type = "${var.instance_type }"
subnet_id = "${var.subnet_id }"
vpc_security_group_ids = ["${var.security_groups }"]
tags {
Name = "fullstackfest-demo-${var. environment }"
}
}
variable "environment" {
description = "Name of environment to create infrastructure (eg,
staging, production)"
}
# terraform.tfvars
environment = "non-prod"
FTP (Frequent Terraform Problems)
● Avoid hard-coded values => use data
sources
● Tag and name resources consistently
Next: Terraform modules = reusability
module "sg_web" {
source = "git@github.com:terraform-community-modules/tf_aws_sg.git//sg_web?ref=v0.2.3"
security_group_name = "fullstackfest-demo-web"
vpc_id = "vpc-12345678"
source_cidr_block = ["0.0.0.0/0" ]
}
resource "aws_instance" "app" {
# ...
vpc_security_group_ids = ["${module. sg_web.security_group_id_web }"]
# ...
}
Terraform modules
● Versioning
● Public/private access
● Local dir or hosted
● Allows:
○ code reuse
○ encapsulate groups of resources
○ testing
Demo - infrastructure as code and deployment pipeline
https://github.com/antonbabenko/terraform-deployment-pipeline-talk
Further thoughts…
● Use linters (tflint), coding styles (fmt), pre-commit hooks
● Automate (no excuses)
● Terraform workspaces, Terragrunt, Atlantis by Hootsuite (super!)
● Version & release infrastructure as the app code
● Using pipelines to manage environments with infrastructure as code by Kief
Morris
Thank you!

More Related Content

What's hot (20)

PDF
Best Practices of Infrastructure as Code with Terraform
DevOps.com
 
PDF
Terraform: Infrastructure as Code
Pradeep Bhadani
 
PPTX
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
Alex Cachia
 
PDF
Terraform introduction
Jason Vance
 
PPTX
Terraform Modules and Continuous Deployment
Zane Williamson
 
PDF
Introduction to IAC and Terraform
Venkat NaveenKashyap Devulapally
 
PPTX
Terraform
Pathum Fernando ☁
 
PPTX
Intro to Helm for Kubernetes
Carlos E. Salazar
 
PDF
Terraform modules and best-practices - September 2018
Anton Babenko
 
PDF
Introduction to Kubernetes Workshop
Bob Killen
 
PDF
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Edureka!
 
PDF
Why we chose Argo Workflow to scale DevOps at InVision
Nebulaworks
 
PDF
Terraform: An Overview & Introduction
Lee Trout
 
PDF
Building infrastructure as code using Terraform - DevOps Krakow
Anton Babenko
 
PDF
CI:CD in Lightspeed with kubernetes and argo cd
Billy Yuen
 
PDF
Terraform -- Infrastructure as Code
Martin Schütte
 
PPTX
MeetUp Monitoring with Prometheus and Grafana (September 2018)
Lucas Jellema
 
PDF
Kubernetes Basics
Eueung Mulyana
 
PPTX
Prometheus (Prometheus London, 2016)
Brian Brazil
 
PDF
Kubernetes
erialc_w
 
Best Practices of Infrastructure as Code with Terraform
DevOps.com
 
Terraform: Infrastructure as Code
Pradeep Bhadani
 
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
Alex Cachia
 
Terraform introduction
Jason Vance
 
Terraform Modules and Continuous Deployment
Zane Williamson
 
Introduction to IAC and Terraform
Venkat NaveenKashyap Devulapally
 
Intro to Helm for Kubernetes
Carlos E. Salazar
 
Terraform modules and best-practices - September 2018
Anton Babenko
 
Introduction to Kubernetes Workshop
Bob Killen
 
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Edureka!
 
Why we chose Argo Workflow to scale DevOps at InVision
Nebulaworks
 
Terraform: An Overview & Introduction
Lee Trout
 
Building infrastructure as code using Terraform - DevOps Krakow
Anton Babenko
 
CI:CD in Lightspeed with kubernetes and argo cd
Billy Yuen
 
Terraform -- Infrastructure as Code
Martin Schütte
 
MeetUp Monitoring with Prometheus and Grafana (September 2018)
Lucas Jellema
 
Kubernetes Basics
Eueung Mulyana
 
Prometheus (Prometheus London, 2016)
Brian Brazil
 
Kubernetes
erialc_w
 

Similar to Terraform in deployment pipeline (20)

PDF
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
OpenCredo
 
PDF
Workshop Infrastructure as Code - Suestra
Mario IC
 
PPTX
terraform cours intéressant et super fort
amar719595
 
PPTX
"Continuously delivering infrastructure using Terraform and Packer" training ...
Anton Babenko
 
PDF
Terraform in action
Damien Pacaud
 
PDF
Terraform at Scale - All Day DevOps 2017
Jonathon Brouse
 
PDF
Infrastructure as Code - Terraform - Devfest 2018
Mathieu Herbert
 
PDF
Declarative & workflow based infrastructure with Terraform
Radek Simko
 
PDF
Agiles Peru 2019 - Infrastructure As Code
Mario IC
 
PDF
Infrastructure as Code with Terraform
Mathieu Herbert
 
PPTX
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
Plain Concepts
 
PDF
Terraform 0.9 + good practices
Radek Simko
 
PDF
Infrastructure as Code with Terraform
Pedro J. Molina
 
PDF
Infrastructure-as-code: bridging the gap between Devs and Ops
Mykyta Protsenko
 
PPTX
Infrastructure as code with terraform and packer
Alex Landa
 
PDF
DevOps Enabling Your Team
GR8Conf
 
PDF
Infrastructure as Code with Terraform
Mario IC
 
PPTX
Terraform at Scale
Calvin French-Owen
 
PDF
Atmosphere 2018: Wojciech Krysmann- INFRA AS CODE - TERRAFORM DEEP DIVE AND B...
PROIDEA
 
PDF
Case Study: Using Terraform and Packer to deploy go applications to AWS
Patrick Bolduan
 
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
OpenCredo
 
Workshop Infrastructure as Code - Suestra
Mario IC
 
terraform cours intéressant et super fort
amar719595
 
"Continuously delivering infrastructure using Terraform and Packer" training ...
Anton Babenko
 
Terraform in action
Damien Pacaud
 
Terraform at Scale - All Day DevOps 2017
Jonathon Brouse
 
Infrastructure as Code - Terraform - Devfest 2018
Mathieu Herbert
 
Declarative & workflow based infrastructure with Terraform
Radek Simko
 
Agiles Peru 2019 - Infrastructure As Code
Mario IC
 
Infrastructure as Code with Terraform
Mathieu Herbert
 
Aprovisionamiento multi-proveedor con Terraform - Plain Concepts DevOps day
Plain Concepts
 
Terraform 0.9 + good practices
Radek Simko
 
Infrastructure as Code with Terraform
Pedro J. Molina
 
Infrastructure-as-code: bridging the gap between Devs and Ops
Mykyta Protsenko
 
Infrastructure as code with terraform and packer
Alex Landa
 
DevOps Enabling Your Team
GR8Conf
 
Infrastructure as Code with Terraform
Mario IC
 
Terraform at Scale
Calvin French-Owen
 
Atmosphere 2018: Wojciech Krysmann- INFRA AS CODE - TERRAFORM DEEP DIVE AND B...
PROIDEA
 
Case Study: Using Terraform and Packer to deploy go applications to AWS
Patrick Bolduan
 
Ad

More from Anton Babenko (20)

PDF
Manage any AWS resources with Terraform 0.12 - April 2020
Anton Babenko
 
PDF
Terraform AWS modules and some best practices - September 2019
Anton Babenko
 
PDF
What you see is what you get for AWS infrastructure
Anton Babenko
 
PDF
Terraform AWS modules and some best-practices - May 2019
Anton Babenko
 
PDF
Terraform modules and some of best-practices - March 2019
Anton Babenko
 
PDF
What you see is what you get for AWS infrastructure
Anton Babenko
 
PDF
Gotchas using Terraform in a secure delivery pipeline
Anton Babenko
 
PDF
Описание инфраструктуры с Terraform на будущее
Anton Babenko
 
PDF
Preview of Terraform 0.12 + modules.tf - Kiev HUG meetup
Anton Babenko
 
PDF
Terraform modules and (some of) best practices
Anton Babenko
 
PDF
Terraform modules and (some of) best practices
Anton Babenko
 
PDF
Terraform Q&A - HashiCorp User Group Oslo
Anton Babenko
 
PDF
"I’ve heard you know infrastructure"
Anton Babenko
 
PDF
Continuous delivery in AWS
Anton Babenko
 
PDF
Tools exist for a reason
Anton Babenko
 
PPTX
AWS CodeDeploy - basic intro
Anton Babenko
 
PPTX
Managing AWS infrastructure using CloudFormation
Anton Babenko
 
PPTX
Designing for elasticity on AWS - 9.11.2015
Anton Babenko
 
PPTX
Recap of AWS re:invent 2015
Anton Babenko
 
PPTX
Designing for elasticity on AWS
Anton Babenko
 
Manage any AWS resources with Terraform 0.12 - April 2020
Anton Babenko
 
Terraform AWS modules and some best practices - September 2019
Anton Babenko
 
What you see is what you get for AWS infrastructure
Anton Babenko
 
Terraform AWS modules and some best-practices - May 2019
Anton Babenko
 
Terraform modules and some of best-practices - March 2019
Anton Babenko
 
What you see is what you get for AWS infrastructure
Anton Babenko
 
Gotchas using Terraform in a secure delivery pipeline
Anton Babenko
 
Описание инфраструктуры с Terraform на будущее
Anton Babenko
 
Preview of Terraform 0.12 + modules.tf - Kiev HUG meetup
Anton Babenko
 
Terraform modules and (some of) best practices
Anton Babenko
 
Terraform modules and (some of) best practices
Anton Babenko
 
Terraform Q&A - HashiCorp User Group Oslo
Anton Babenko
 
"I’ve heard you know infrastructure"
Anton Babenko
 
Continuous delivery in AWS
Anton Babenko
 
Tools exist for a reason
Anton Babenko
 
AWS CodeDeploy - basic intro
Anton Babenko
 
Managing AWS infrastructure using CloudFormation
Anton Babenko
 
Designing for elasticity on AWS - 9.11.2015
Anton Babenko
 
Recap of AWS re:invent 2015
Anton Babenko
 
Designing for elasticity on AWS
Anton Babenko
 
Ad

Recently uploaded (20)

PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
July Patch Tuesday
Ivanti
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 

Terraform in deployment pipeline

  • 1. Terraform in deployment pipeline by Anton Babenko
  • 2. Hi! I am Anton Babenko, and I enjoy: ● AWS & DevOps ● AWS User Group Norway and DevOpsDays Oslo organizer ● Solve problems “Getting Started with Terraform”, terraform-community-modules, Terraform modules generator (Terrapin), and more… https://github.com/antonbabenko https://www.linkedin.com/in/antonbabenko
  • 3. 1. Become more familiar with managing infrastructure using CD pipeline 2. See scenarios of integrating Terraform and Packer 3. How to structure infrastructure code? 4. How to version your infrastructure between environments and make it DRY? Goals of this talk
  • 4. Do you know? What is: ● Infrastructure as code? ● Deployment pipeline? ● Pipeline as code?
  • 5. Featuring... Write, plan, and create infrastructure as code Build automated machine images
  • 7. Typical CI/CD pipeline source: https://dzone.com/articles/what-is-continuous-delivery-pipeline
  • 8. Where are infrastructure changes here?
  • 10. Structure - all-in-one vs split ~/all-in-one-repo/ ├── packer # Packer configs │ └── app.json ├── terraform # Terraform configs │ ├── main.tf │ └── terraform.tfvars └── web # Application code └── index.html ~/infra-repo/ ├── packer # Packer configs │ └── app.json └── terraform # Terraform configs ├── main.tf └── terraform.tfvars ~/app-repo/ └── web # Application code └── index.html
  • 11. Structure - evolving infrastructure repository ~/infra-repo/ ├── packer # Packer configs │ └── app.json └── terraform # Terraform configs ├── modules # Terraform modules │ ├── network │ │ └── main.tf │ └── service1 │ └── main.tf ├── main.tf └── terraform.tfvars ~/infra-repo/ ├── packer # Packer configs │ └── app.json └── terraform # Terraform configs ├── modules # Terraform modules │ ├── network │ │ └── main.tf │ └── service1 │ └── main.tf └── environments ├── non-prod │ └── us-east-1 │ ├── main.tf │ └── terraform.tfvars └── prod ├── eu-west-1 │ ├── main.tf │ └── terraform.tfvars └── us-east-1 ├── main.tf └── terraform.tfvars
  • 12. example1/main.tf resource "random_pet" "bucket" {} resource "aws_s3_bucket" "app" { bucket = "fullstackfest-${ random_pet .bucket. id}" acl = "public-read" website { index_document = "index.html" } } data "template_file" "index" { template = "${file("../../web/index.html")}" vars { BUILD_DETAILS = "${aws_s3_bucket .app.website_endpoint }" } } resource "aws_s3_bucket_object" "object" { bucket = "${aws_s3_bucket .app.id}" key = "index.html" content = "${data. template_file .index.rendered }" etag = "${md5(data. template_file .index.rendered )}" content_type = "text/html" acl = "public-read" } output "app_website_endpoint" { value = "${aws_s3_bucket .app.website_endpoint }" } FullStackFest! ${BUILD_DETAILS} $ terraform init ... $ terraform plan ... $ terraform apply ... Apply complete! Resources: 3 added, 0 changed, 0 destroyed. Outputs: app_website_endpoint = fullstackfest-feasible-basilisk.s3-website-eu-west-1.amazonaws.c om
  • 13. example2/main.tf variable "subnet_id" { description = "ID of subnet where resources will be created" } variable "security_groups" { description = "ID of security group EC2 instance will use" } variable "instance_type" { description = "Type of EC2 instance to launch" } data "aws_ami" "app" { most_recent = true filter { name = "name" values = ["fullstackfest-demo-*" ] } } resource "aws_instance" "app" { ami = "${data. aws_ami.app.id}" instance_type = "${var.instance_type }" subnet_id = "${var.subnet_id }" vpc_security_group_ids = ["${var.security_groups }"] } output "app_public_ip" { description = "Public IP of EC2 instance running an application" value = "${aws_instance .app.public_ip }" } packer/app.json { "builders" : [ { "ami_name" : "fullstackfest-demo-{{uuid | clean_ami_name}}" , "ami_description" : "FullStackFest demo AMI based on Amazon Linux", "instance_type" : "t2.micro" , "region" : "eu-west-1" , "type": "amazon-ebs" , "ssh_username" : "ec2-user" , "source_ami_filter" : { "filters" : { "virtualization-type" : "hvm", "name": "amzn-ami-hvm-*-x86_64-gp2" , "root-device-type" : "ebs" }, "owners" : [ "137112412989" ], "most_recent" : true } } ], "provisioners" : [ { "type": "shell", "inline" : [ "# Install nginx, copy index.html into web-root" ] } ] }
  • 14. # Avoid hard-coded values in *.tf files, use data sources or *.tfvars data "aws_ami" "app" { most_recent = true filter { name = "name" values = ["fullstackfest-demo-*" ] } } # Tag and name resources consistently resource "aws_instance" "app" { ami = "${data. aws_ami.app.id}" instance_type = "${var.instance_type }" subnet_id = "${var.subnet_id }" vpc_security_group_ids = ["${var.security_groups }"] tags { Name = "fullstackfest-demo-${var. environment }" } } variable "environment" { description = "Name of environment to create infrastructure (eg, staging, production)" } # terraform.tfvars environment = "non-prod" FTP (Frequent Terraform Problems) ● Avoid hard-coded values => use data sources ● Tag and name resources consistently Next: Terraform modules = reusability
  • 15. module "sg_web" { source = "[email protected]:terraform-community-modules/tf_aws_sg.git//sg_web?ref=v0.2.3" security_group_name = "fullstackfest-demo-web" vpc_id = "vpc-12345678" source_cidr_block = ["0.0.0.0/0" ] } resource "aws_instance" "app" { # ... vpc_security_group_ids = ["${module. sg_web.security_group_id_web }"] # ... } Terraform modules ● Versioning ● Public/private access ● Local dir or hosted ● Allows: ○ code reuse ○ encapsulate groups of resources ○ testing
  • 16. Demo - infrastructure as code and deployment pipeline https://github.com/antonbabenko/terraform-deployment-pipeline-talk
  • 17. Further thoughts… ● Use linters (tflint), coding styles (fmt), pre-commit hooks ● Automate (no excuses) ● Terraform workspaces, Terragrunt, Atlantis by Hootsuite (super!) ● Version & release infrastructure as the app code ● Using pipelines to manage environments with infrastructure as code by Kief Morris