SlideShare a Scribd company logo
Terraform modules and (some of)
best-practices
Anton Babenko
@antonbabenko
December 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 2 millions 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
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?
-target
Makefile
…
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
Orchestration = Terragrunt
tfvars can’t contain dynamic values :(
Orchestration = Terragrunt
tfvars can’t contain dynamic values,
so I fixed it :)
before_hook + shell-script
See this: https://github.com/antonbabenko/modules.tf-lambda/blob/master/
templates/terragrunt-common-layer/template/common/scripts/
update_dynamic_values_in_tfvars.sh
Or try it yourself by using cloudcraft.co
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	
		-	[x]	Dynamic	values	in	tfvars	
-	[	]	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 to my supporters!
Cloudcraft — the best way to draw AWS diagrams
cloudcraft.co
Thanks!
Questions?
In progress — www.terraform-best-practices.com
github.com/antonbabenko
twitter.com/antonbabenko

More Related Content

What's hot (20)

PDF
Terraform modules and best-practices - September 2018
Anton Babenko
 
PDF
Building infrastructure as code using Terraform - DevOps Krakow
Anton Babenko
 
PPTX
Terraform
Pathum Fernando ☁
 
PPTX
Terraform
Harish Kumar
 
PPTX
Terraform
Adam Vincze
 
PDF
Terraform Q&A - HashiCorp User Group Oslo
Anton Babenko
 
PPTX
Terraform on Azure
Mithun Shanbhag
 
PDF
Terraform @Base
Miroslaw Nagas
 
PPTX
Comprehensive Terraform Training
Yevgeniy Brikman
 
PPTX
Terraform
Phil Wilkins
 
PDF
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
Yevgeniy Brikman
 
PDF
Scaling terraform
Paolo Tonin
 
PPTX
Terraform Concepts
Saiyam Pathak
 
PPTX
Final terraform
Gourav Varma
 
PPTX
Infrastructure as Code: Introduction to Terraform
Alexander Popov
 
PPTX
Terraform
An Nguyen
 
PDF
[Alibaba Cloud Singapore Community Meetup Webinar, 3 Sep 2020] Automate Your ...
Vinod Narayanankutty
 
PDF
Case Study: Using Terraform and Packer to deploy go applications to AWS
Patrick Bolduan
 
PPTX
Hybrid Clouds: Dancing with "Automated" Virtual Machines
CSUC - Consorci de Serveis Universitaris de Catalunya
 
PDF
Terraform in deployment pipeline
Anton Babenko
 
Terraform modules and best-practices - September 2018
Anton Babenko
 
Building infrastructure as code using Terraform - DevOps Krakow
Anton Babenko
 
Terraform
Harish Kumar
 
Terraform
Adam Vincze
 
Terraform Q&A - HashiCorp User Group Oslo
Anton Babenko
 
Terraform on Azure
Mithun Shanbhag
 
Terraform @Base
Miroslaw Nagas
 
Comprehensive Terraform Training
Yevgeniy Brikman
 
Terraform
Phil Wilkins
 
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
Yevgeniy Brikman
 
Scaling terraform
Paolo Tonin
 
Terraform Concepts
Saiyam Pathak
 
Final terraform
Gourav Varma
 
Infrastructure as Code: Introduction to Terraform
Alexander Popov
 
Terraform
An Nguyen
 
[Alibaba Cloud Singapore Community Meetup Webinar, 3 Sep 2020] Automate Your ...
Vinod Narayanankutty
 
Case Study: Using Terraform and Packer to deploy go applications to AWS
Patrick Bolduan
 
Hybrid Clouds: Dancing with "Automated" Virtual Machines
CSUC - Consorci de Serveis Universitaris de Catalunya
 
Terraform in deployment pipeline
Anton Babenko
 

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

PDF
Terraform AWS modules and some best practices - September 2019
Anton Babenko
 
PDF
OSDC 2019 | Terraform best practices with examples and arguments by Anton Bab...
NETWAYS
 
PDF
OSDC 2018 | Lifecycle of a resource. Codifying infrastructure with Terraform ...
NETWAYS
 
PPTX
Terraform Modules Restructured
DoiT International
 
PPTX
Terraform modules restructured
Ami Mahloof
 
PDF
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
ssuser705051
 
PDF
Terraform-2.pdf
rutiksankapal21
 
PPTX
Terraform in production - experiences, best practices and deep dive- Piotr Ki...
PROIDEA
 
PDF
Terraform + ansible talk
James Strong
 
PDF
Manage any AWS resources with Terraform 0.12 - April 2020
Anton Babenko
 
PPTX
Introduction to basics of Terraform.pptx
AKSHAYCHOUDHARY442172
 
PPTX
Terraform - The Road to Self-Service
Ryan Boyce
 
PPTX
"Continuously delivering infrastructure using Terraform and Packer" training ...
Anton Babenko
 
PPTX
terraform cours intéressant et super fort
amar719595
 
PPTX
DelEx Conference: Jenkins+Terragrunt+Terraform eco-system
Alexander Dobrodey
 
PDF
DevOps Braga #9: Introdução ao Terraform
DevOps Braga
 
PPTX
Terraform Modules and Continuous Deployment
Zane Williamson
 
PPTX
Terraform Abstractions for Safety and Power
Calvin French-Owen
 
PDF
The hitchhiker's guide to terraform your infrastructure
Fernanda Martins
 
PDF
Introductory Overview to Managing AWS with Terraform
Michael Heyns
 
Terraform AWS modules and some best practices - September 2019
Anton Babenko
 
OSDC 2019 | Terraform best practices with examples and arguments by Anton Bab...
NETWAYS
 
OSDC 2018 | Lifecycle of a resource. Codifying infrastructure with Terraform ...
NETWAYS
 
Terraform Modules Restructured
DoiT International
 
Terraform modules restructured
Ami Mahloof
 
Hashicorp-Terraform-Deep-Dive-with-no-Fear-Victor-Turbinsky-Texuna.pdf
ssuser705051
 
Terraform-2.pdf
rutiksankapal21
 
Terraform in production - experiences, best practices and deep dive- Piotr Ki...
PROIDEA
 
Terraform + ansible talk
James Strong
 
Manage any AWS resources with Terraform 0.12 - April 2020
Anton Babenko
 
Introduction to basics of Terraform.pptx
AKSHAYCHOUDHARY442172
 
Terraform - The Road to Self-Service
Ryan Boyce
 
"Continuously delivering infrastructure using Terraform and Packer" training ...
Anton Babenko
 
terraform cours intéressant et super fort
amar719595
 
DelEx Conference: Jenkins+Terragrunt+Terraform eco-system
Alexander Dobrodey
 
DevOps Braga #9: Introdução ao Terraform
DevOps Braga
 
Terraform Modules and Continuous Deployment
Zane Williamson
 
Terraform Abstractions for Safety and Power
Calvin French-Owen
 
The hitchhiker's guide to terraform your infrastructure
Fernanda Martins
 
Introductory Overview to Managing AWS with Terraform
Michael Heyns
 
Ad

More from Anton Babenko (11)

PDF
What you see is what you get for AWS infrastructure
Anton Babenko
 
PDF
Описание инфраструктуры с Terraform на будущее
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
 
Описание инфраструктуры с Terraform на будущее
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
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
Complete Network Protection with Real-Time Security
L4RGINDIA
 
PDF
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Why Orbit Edge Tech is a Top Next JS Development Company in 2025
mahendraalaska08
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Complete Network Protection with Real-Time Security
L4RGINDIA
 
Human-centred design in online workplace learning and relationship to engagem...
Tracy Tang
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 

Terraform modules and (some of) best practices