2014-07-25 06:11:33 +02:00
---
layout: "intro"
page_title: "Use Cases"
sidebar_current: "use-cases"
2014-10-22 05:21:56 +02:00
description: |-
Before understanding use cases, it's useful to know what Terraform is. This page lists some concrete use cases for Terraform, but the possible use cases are much broader than what we cover. Due to its extensible nature, providers and provisioners can be added to further extend Terraform's ability to manipulate resources.
2014-07-25 06:11:33 +02:00
---
# Use Cases
Before understanding use cases, it's useful to know [what Terraform is ](/intro/index.html ).
This page lists some concrete use cases for Terraform, but the possible use cases are
2014-07-28 22:09:32 +02:00
much broader than what we cover. Due to its extensible nature, providers and provisioners
2014-07-25 06:11:33 +02:00
can be added to further extend Terraform's ability to manipulate resources.
2017-04-06 20:02:56 +02:00
## Heroku App Setup
2014-07-25 06:11:33 +02:00
Heroku is a popular PaaS for hosting web apps. Developers create an app, and then
2014-07-29 02:09:25 +02:00
attach add-ons, such as a database, or email provider. One of the best features is
2014-07-25 06:11:33 +02:00
the ability to elastically scale the number of dynos or workers. However, most
non-trivial applications quickly need many add-ons and external services.
Terraform can be used to codify the setup required for a Heroku application, ensuring
2014-09-02 19:38:30 +02:00
that all the required add-ons are available, but it can go even further: configuring
2017-03-18 13:34:07 +01:00
DNSimple to set a CNAME, or setting up Cloudflare as a CDN for the
2014-09-02 19:38:30 +02:00
app. Best of all, Terraform can do all of this in under 30 seconds without
using a web interface.
2014-07-25 06:11:33 +02:00
2017-04-06 20:02:56 +02:00
## Multi-Tier Applications
2014-07-25 06:11:33 +02:00
A very common pattern is the N-tier architecture. The most common 2-tier architecture is
2014-07-27 20:51:45 +02:00
a pool of web servers that use a database tier. Additional tiers get added for API servers,
caching servers, routing meshes, etc. This pattern is used because the tiers can be scaled
2014-07-29 01:12:18 +02:00
independently and provide a separation of concerns.
2014-07-25 06:11:33 +02:00
Terraform is an ideal tool for building and managing these infrastructures. Each tier can
2014-09-02 19:38:30 +02:00
be described as a collection of resources, and the dependencies between each tier are handled
2014-07-25 06:11:33 +02:00
automatically; Terraform will ensure the database tier is available before the web servers
are started and that the load balancers are aware of the web nodes. Each tier can then be
scaled easily using Terraform by modifying a single `count` configuration value. Because
2014-07-27 20:51:45 +02:00
the creation and provisioning of a resource is codified and automated, elastically scaling
with load becomes trivial.
2014-07-25 06:11:33 +02:00
2017-04-06 20:02:56 +02:00
## Self-Service Clusters
2014-07-25 06:11:33 +02:00
At a certain organizational size, it becomes very challenging for a centralized
operations team to manage a large and growing infrastructure. Instead it becomes
more attractive to make "self-serve" infrastructure, allowing product teams to
manage their own infrastructure using tooling provided by the central operations team.
Using Terraform, the knowledge of how to build and scale a service can be codified
in a configuration. Terraform configurations can be shared within an organization
enabling customer teams to use the configuration as a black box and use Terraform as
a tool to manage their services.
2017-04-06 20:02:56 +02:00
## Software Demos
2014-07-25 06:11:33 +02:00
2014-09-02 19:38:30 +02:00
Modern software is increasingly networked and distributed. Although tools like
2015-01-03 19:31:53 +01:00
[Vagrant ](https://www.vagrantup.com/ ) exist to build virtualized environments
2014-07-27 20:51:45 +02:00
for demos, it is still very challenging to demo software on real infrastructure
2014-09-02 19:38:30 +02:00
which more closely matches production environments.
2014-07-25 06:11:33 +02:00
2014-07-29 03:17:02 +02:00
Software writers can provide a Terraform configuration to create, provision and
2014-07-25 06:11:33 +02:00
bootstrap a demo on cloud providers like AWS. This allows end users to easily demo
the software on their own infrastructure, and even enables tweaking parameters like
cluster size to more rigorously test tools at any scale.
2017-04-06 20:02:56 +02:00
## Disposable Environments
2014-07-25 06:11:33 +02:00
It is common practice to have both a production and staging or QA environment.
These environments are smaller clones of their production counterpart, but are
used to test new applications before releasing in production. As the production
environment grows larger and more complex, it becomes increasingly onerous to
maintain an up-to-date staging environment.
2014-07-30 08:10:30 +02:00
Using Terraform, the production environment can be codified and then shared with
2014-07-25 06:11:33 +02:00
staging, QA or dev. These configurations can be used to rapidly spin up new
2014-09-02 19:38:30 +02:00
environments to test in, and then be easily disposed of. Terraform can help tame
2014-07-25 06:11:33 +02:00
the difficulty of maintaining parallel environments, and makes it practical
to elastically create and destroy them.
2017-04-06 20:02:56 +02:00
## Software Defined Networking
2014-07-25 06:11:33 +02:00
Software Defined Networking (SDN) is becoming increasingly prevalent in the
datacenter, as it provides more control to operators and developers and
allows the network to better support the applications running on top. Most SDN
implementations have a control layer and infrastructure layer.
Terraform can be used to codify the configuration for software defined networks.
2014-07-29 11:47:53 +02:00
This configuration can then be used by Terraform to automatically setup and modify
2014-07-25 06:11:33 +02:00
settings by interfacing with the control layer. This allows configuration to be
2016-01-14 21:55:39 +01:00
versioned and changes to be automated. As an example, [AWS VPC ](https://aws.amazon.com/vpc/ )
2014-07-27 20:51:45 +02:00
is one of the most commonly used SDN implementations, and [can be configured by
2020-12-17 00:17:27 +01:00
Terraform](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/vpc).
2014-07-25 06:11:33 +02:00
2017-04-06 20:02:56 +02:00
## Resource Schedulers
2014-07-25 06:11:33 +02:00
2014-09-02 19:38:30 +02:00
In large-scale infrastructures, static assignment of applications to machines
2014-07-25 06:11:33 +02:00
becomes increasingly challenging. To solve that problem, there are a number
of schedulers like Borg, Mesos, YARN, and Kubernetes. These can be used to
dynamically schedule Docker containers, Hadoop, Spark, and many other software
tools.
Terraform is not limited to physical providers like AWS. Resource schedulers
2014-09-02 19:38:30 +02:00
can be treated as a provider, enabling Terraform to request resources from them.
2014-07-25 06:11:33 +02:00
This allows Terraform to be used in layers: to setup the physical infrastructure
2014-09-02 19:38:30 +02:00
running the schedulers as well as provisioning onto the scheduled grid.
2014-07-25 06:11:33 +02:00
2017-04-06 20:02:56 +02:00
## Multi-Cloud Deployment
2014-07-25 16:45:56 +02:00
It's often attractive to spread infrastructure across multiple clouds to increase
fault-tolerance. By using only a single region or cloud provider, fault tolerance
is limited by the availability of that provider. Having a multi-cloud deployment
allows for more graceful recovery of the loss of a region or entire provider.
Realizing multi-cloud deployments can be very challenging as many existing tools
2014-09-02 19:38:30 +02:00
for infrastructure management are cloud-specific. Terraform is cloud-agnostic
2014-07-25 16:45:56 +02:00
and allows a single configuration to be used to manage multiple providers, and
2014-07-29 07:27:41 +02:00
to even handle cross-cloud dependencies. This simplifies management and orchestration,
2014-09-02 19:38:30 +02:00
helping operators build large-scale multi-cloud infrastructures.