SlideShare a Scribd company logo
Terraform modules and (some of)
best-practices
Anton Babenko
@antonbabenko
November 2018
Anton Babenko
Terraform AWS fanatic since 2015.
HUG, AWS, DevOps Norway, DevOpsDays Oslo…
I 💚 open-source:
terraform-community-modules + terraform-aws-modules
antonbabenko/pre-commit-terraform — auto-formatting code and documentation
antonbabenko/modules.tf-lambda — Terraform configurations from visual diagrams
www.terraform-best-practices.com
medium.com/@anton.babenko
@antonbabenko - Twitter, and many Slacks
Collection of open-source Terraform AWS modules supported by the community.
More than 1,5 million downloads.
(VPC, Autoscaling, RDS, Security Groups, ELB, ALB, Redshift, SNS, SQS, IAM, EKS, ECS…)
github.com/terraform-aws-modules
registry.terraform.io/modules/terraform-aws-modules
Write, plan and manage infrastructure as code
www.terraform.io
Google Cloud
Deployment Manager
Azure Resource
Manager
Terraform modules and (some of) best practices
Plus100+moreproviders
Terraform — is a universal tool to manage
anything that has an API
GSuite
Dropbox files and access
New Relic metrics
Datadog users and metrics
Bugs in Jira
All Terraform providers
VPC, please!
Terraform modules and (some of) best practices
Terraform modules and (some of) best practices
Terraform modules and (some of) best practices
Terraform modules and (some of) best practices
Terraform modules and (some of) best practices
Problems
Code size is growing
Complicated dependencies
Solution — Terraform modules
Terraform modules are self-contained
packages of Terraform configurations that are
managed as a group.
Resource modules
Only create resources in a very flexible way
Open-source
Resource modules
Terraform modules and (some of) best practices
Infrastructure modules
Consist of resource modules
Company standards and tags
Pre-processors, jsonnet, cookiecutter
Infrastructure modules
Terraform modules and (some of) best practices
Types of Terraform modules
Resource modules (terraform-aws-modules, for example)
Infrastructure modules
-	[	]	How	to	write	modules	
-	[	]	How	to	use	modules
Tip №0
Check Terraform Registry before writing new resource module.
Hide specifics
Terraform modules and (some of) best practices
Terraform modules and (some of) best practices
Size
Size
https://github.com/mbtproject/mbt
Things to avoid in Terraform modules
Exception: logical providers (template, random, local, http, external)
Providers in modules — bad
Terraform modules and (some of) best practices
Provisioner — bad
Avoid provisioners in all resources
Provisioner — bad
Avoid provisioners even inside EC2 resources
Provisioner — bad
Avoid provisioners even inside EC2 resources
Terraform modules and (some of) best practices
Terraform modules and (some of) best practices
null_resource provisioner — good
Traits of good Terraform modules
Documentation and examples
Feature-rich
Sane defaults
Clean code
Tests
Read more: http://bit.ly/common-traits-in-terraform-modules
-	[x]	How	to	write	modules	
		-	[x]	Do	not	write,	if	possible	
		-	[x]	Do	not	use:	providers	and	provisioners	
-	[	]	How	to	use	modules
How to use Terraform modules
Many resources, many modules
How to organize and use them?
How to orchestrate them?
All in one
Good:
Declare variables and outputs in
fewer places
Bad:
Large blast radius
Everything is blocked at once
Not possible to specify dependenies
between modules (depends_on)
1-in-1
Good:
Small blast radius
Possible to chain calls
Faster and easier to work with
Bad:
Declare variables and outputs
in several places
How is it in your project?
"All in one" or 1-in-1 ?
Correct
Most frequent answer:
"somewhere in between" + "it depends"
What about orchestration in your
project?
Orchestration in Terraform
Do not try this at home!
Orchestration = Terragrunt
https://github.com/gruntwork-io/terragrunt/
Orchestration = Terragrunt
Orchestration = Terragrunt
Orchestration = Terragrunt
Orchestration = Terragrunt
Edge cases
Different AWS regions (S3 signature, EC2 ClassicLink, IPv6)
Age of AWS accounts
Limits in AWS
Avoid in Terraform
Non-sensitive arguments in CLI. Put them in tfvars file.
• -target
• -parallelism
"Terraform workspaces" => separate directory
Dependency hell in modules
-	[x]	How	to	write	modules	
-	[x]	How	to	use	modules	
		-	[x]	1-in-1	much	better	over	time	
		-	[x]	Orchestration	=	Terragrunt	
-	[	]	What	is	next?
Terraform 0.12
HCL2 — simplified syntax
Loops ("for")
Dynamic blocks ("for_each")
Correct operations of comparison (… ? … : …)
Extended types in variables
Templates in string values
Links between all resources everywhere (depends_on)
Read more — https://www.hashicorp.com/blog/terraform-0-1-2-preview
Summary
Write less and simpler — Terraform 0.12 will not fix your code for you
Use existing modules and tools
BONUS
Terraform modules and (some of) best practices
Terraform modules and (some of) best practices
cloudcraft.co features
Manage AWS components in browser (EC2 instances, autoscaling groups, RDS,
etc)
Connect components
Import live AWS infrastructure
Calculate the budget
Share link to a blueprint
Export as image
Embed drawing to wiki, Confluence, etc
Terraform modules and (some of) best practices
Terraform modules and (some of) best practices
Infrastructure as code generator — from visual diagrams to Terraform
✓ cloudcraft.co — design, plan and visualize
✓ terraform-aws-modules — building blocks of AWS infrastructure
✓ Terraform — infrastructure as code
modules.tf notes
✓ Available for all users: https://cloudcraft.co/
✓ Generates potentially ready-to-use Terraform configurations
✓ Suits best for bootstrapping
✓ Enforces Terraform best practices
✓ Batteries included (terraform-aws-modules, terragrunt, pre-commit, …)
✓ 100% free for all & open-source (https://github.com/antonbabenko/
modules.tf-lambda )
✓ Want to sponsor, or a sticker? Contact me.
modules.tf demo
Thanks!
Questions?
In progress — www.terraform-best-practices.com
github.com/antonbabenko
twitter.com/antonbabenko
Thanks to my supporters!
Cloudcraft — the best way to draw AWS diagrams
cloudcraft.co
HIRING!
http://www.1plusx.com/about/careers/

More Related Content

What's hot (20)

PPTX
Infrastructure-as-Code (IaC) using Terraform
Adin Ermie
 
PDF
Terraform Introduction
soniasnowfrog
 
PDF
Building infrastructure as code using Terraform - DevOps Krakow
Anton Babenko
 
PPTX
Terraform on Azure
Mithun Shanbhag
 
PPTX
Comprehensive Terraform Training
Yevgeniy Brikman
 
PDF
Terraform in deployment pipeline
Anton Babenko
 
PPTX
Deploying Azure DevOps using Terraform
Adin Ermie
 
PPTX
Terraform modules restructured
Ami Mahloof
 
PDF
A Hands-on Introduction on Terraform Best Concepts and Best Practices
Nebulaworks
 
PPTX
Terraform
Adam Vincze
 
PDF
Terraform modules and best-practices - September 2018
Anton Babenko
 
PDF
Terraform
Diego Pacheco
 
PDF
Terraform introduction
Jason Vance
 
PPTX
Effective terraform
Calvin French-Owen
 
PPTX
Introduction To Terraform
Sasitha Iresh
 
PDF
Terraform
Marcelo Serpa
 
PDF
Datadog을 활용한 Elastic Kubernetes Service(EKS)에서의 마이크로서비스 통합 가시성 - 정영석 시니어 세일즈 ...
Amazon Web Services Korea
 
PPTX
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
Alex Cachia
 
PPTX
Terraform Basics
Mohammed Fazuluddin
 
PPTX
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Adin Ermie
 
Infrastructure-as-Code (IaC) using Terraform
Adin Ermie
 
Terraform Introduction
soniasnowfrog
 
Building infrastructure as code using Terraform - DevOps Krakow
Anton Babenko
 
Terraform on Azure
Mithun Shanbhag
 
Comprehensive Terraform Training
Yevgeniy Brikman
 
Terraform in deployment pipeline
Anton Babenko
 
Deploying Azure DevOps using Terraform
Adin Ermie
 
Terraform modules restructured
Ami Mahloof
 
A Hands-on Introduction on Terraform Best Concepts and Best Practices
Nebulaworks
 
Terraform
Adam Vincze
 
Terraform modules and best-practices - September 2018
Anton Babenko
 
Terraform
Diego Pacheco
 
Terraform introduction
Jason Vance
 
Effective terraform
Calvin French-Owen
 
Introduction To Terraform
Sasitha Iresh
 
Terraform
Marcelo Serpa
 
Datadog을 활용한 Elastic Kubernetes Service(EKS)에서의 마이크로서비스 통합 가시성 - 정영석 시니어 세일즈 ...
Amazon Web Services Korea
 
A brief introduction to IaC with Terraform by Kenton Robbins (codeHarbour May...
Alex Cachia
 
Terraform Basics
Mohammed Fazuluddin
 
Infrastructure-as-Code (IaC) Using Terraform (Advanced Edition)
Adin Ermie
 

Similar to Terraform modules and (some of) best practices (20)

PDF
Terraform modules and (some of) best practices
Anton Babenko
 
PDF
Terraform AWS modules and some best practices - September 2019
Anton Babenko
 
PDF
Terraform AWS modules and some best-practices - May 2019
Anton Babenko
 
PDF
OSDC 2019 | Terraform best practices with examples and arguments by Anton Bab...
NETWAYS
 
PDF
Terraform modules and some of best-practices - March 2019
Anton Babenko
 
PDF
OSDC 2018 | Lifecycle of a resource. Codifying infrastructure with Terraform ...
NETWAYS
 
PPTX
Terraform Modules Restructured
DoiT International
 
PDF
Terraform 0.12 + Terragrunt
Anton Babenko
 
PDF
Terraform + ansible talk
James Strong
 
PDF
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
ssuser705051
 
PDF
Terraform-2.pdf
rutiksankapal21
 
PDF
Manage any AWS resources with Terraform 0.12 - April 2020
Anton Babenko
 
PPTX
Terraform in production - experiences, best practices and deep dive- Piotr Ki...
PROIDEA
 
PDF
The hitchhiker's guide to terraform your infrastructure
Fernanda Martins
 
PDF
Introduction to IAC and Terraform
Venkat NaveenKashyap Devulapally
 
PPTX
Introduction to basics of Terraform.pptx
AKSHAYCHOUDHARY442172
 
PPTX
Terraform Modules and Continuous Deployment
Zane Williamson
 
PPTX
terraform cours intéressant et super fort
amar719595
 
PPTX
"Continuously delivering infrastructure using Terraform and Packer" training ...
Anton Babenko
 
PPTX
Terraform Abstractions for Safety and Power
Calvin French-Owen
 
Terraform modules and (some of) best practices
Anton Babenko
 
Terraform AWS modules and some best practices - September 2019
Anton Babenko
 
Terraform AWS modules and some best-practices - May 2019
Anton Babenko
 
OSDC 2019 | Terraform best practices with examples and arguments by Anton Bab...
NETWAYS
 
Terraform modules and some of best-practices - March 2019
Anton Babenko
 
OSDC 2018 | Lifecycle of a resource. Codifying infrastructure with Terraform ...
NETWAYS
 
Terraform Modules Restructured
DoiT International
 
Terraform 0.12 + Terragrunt
Anton Babenko
 
Terraform + ansible talk
James Strong
 
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
ssuser705051
 
Terraform-2.pdf
rutiksankapal21
 
Manage any AWS resources with Terraform 0.12 - April 2020
Anton Babenko
 
Terraform in production - experiences, best practices and deep dive- Piotr Ki...
PROIDEA
 
The hitchhiker's guide to terraform your infrastructure
Fernanda Martins
 
Introduction to IAC and Terraform
Venkat NaveenKashyap Devulapally
 
Introduction to basics of Terraform.pptx
AKSHAYCHOUDHARY442172
 
Terraform Modules and Continuous Deployment
Zane Williamson
 
terraform cours intéressant et super fort
amar719595
 
"Continuously delivering infrastructure using Terraform and Packer" training ...
Anton Babenko
 
Terraform Abstractions for Safety and Power
Calvin French-Owen
 
Ad

More from Anton Babenko (15)

PDF
What you see is what you get for AWS infrastructure
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 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
 
PDF
Build & deploy PHP application (intro level)
Anton Babenko
 
What you see is what you get for AWS infrastructure
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 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
 
Build & deploy PHP application (intro level)
Anton Babenko
 
Ad

Recently uploaded (20)

PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PDF
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
PDF
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
PDF
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
Why aren't you using FME Flow's CPU Time?
Safe Software
 
PPTX
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
PPTX
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
PPTX
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
''Taming Explosive Growth: Building Resilience in a Hyper-Scaled Financial Pl...
Fwdays
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Why aren't you using FME Flow's CPU Time?
Safe Software
 
2025 HackRedCon Cyber Career Paths.pptx Scott Stanton
Scott Stanton
 
CapCut Pro PC Crack Latest Version Free Free
josanj305
 
Mastering Authorization: Integrating Authentication and Authorization Data in...
Hitachi, Ltd. OSS Solution Center.
 
Kubernetes - Architecture & Components.pdf
geethak285
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Pipeline Industry IoT - Real Time Data Monitoring
Safe Software
 

Terraform modules and (some of) best practices