|
| 1 | +--- |
| 2 | +layout: "intro" |
| 3 | +page_title: "Use Cases" |
| 4 | +sidebar_current: "use-cases" |
| 5 | +--- |
| 6 | + |
| 7 | +# Use Cases |
| 8 | + |
| 9 | +Before understanding use cases, it's useful to know [what Terraform is](/intro/index.html). |
| 10 | +This page lists some concrete use cases for Terraform, but the possible use cases are |
| 11 | +much broader than what we cover. Due to it's extensible nature, providers and provisioners |
| 12 | +can be added to further extend Terraform's ability to manipulate resources. |
| 13 | + |
| 14 | +#### Heroku App Setup |
| 15 | + |
| 16 | +Heroku is a popular PaaS for hosting web apps. Developers create an app, and then |
| 17 | +attach add-ons, such as a database, or email provider. One of the best features it |
| 18 | +the ability to elastically scale the number of dynos or workers. However, most |
| 19 | +non-trivial applications quickly need many add-ons and external services. |
| 20 | + |
| 21 | +Terraform can be used to codify the setup required for a Heroku application, ensuring |
| 22 | +that all the required add-ons are available but it can go even further, configuring |
| 23 | +DNSimple to use an update CNAME, or setting up CloudFlare to act as a CDN for the |
| 24 | +app. Best of all, Terraform can do all of this without using a web interface in |
| 25 | +under 30 seconds. |
| 26 | + |
| 27 | +#### Multi-Tier Applications |
| 28 | + |
| 29 | +A very common pattern is the N-tier architecture. The most common 2-tier architecture is |
| 30 | +a pool of web servers that interface with a database tier. Extending this, additional |
| 31 | +tiers get added for API servers, caching servers, routing meshes, etc. This pattern is used |
| 32 | +because the tiers can be scaled indepedently and provide a seperation of concerns. |
| 33 | + |
| 34 | +Terraform is an ideal tool for building and managing these infrastructures. Each tier can |
| 35 | +be described as a collection of resources, and the depedencies between each tier is handled |
| 36 | +automatically; Terraform will ensure the database tier is available before the web servers |
| 37 | +are started and that the load balancers are aware of the web nodes. Each tier can then be |
| 38 | +scaled easily using Terraform by modifying a single `count` configuration value. Because |
| 39 | +the creation and provisioning of a resource is codified and automated, it becomes trivial |
| 40 | +to build autoscaling systems to elastically scale with load. |
| 41 | + |
| 42 | +#### Self-Service Clusters |
| 43 | + |
| 44 | +At a certain organizational size, it becomes very challenging for a centralized |
| 45 | +operations team to manage a large and growing infrastructure. Instead it becomes |
| 46 | +more attractive to make "self-serve" infrastructure, allowing product teams to |
| 47 | +manage their own infrastructure using tooling provided by the central operations team. |
| 48 | + |
| 49 | +Using Terraform, the knowledge of how to build and scale a service can be codified |
| 50 | +in a configuration. Terraform configurations can be shared within an organization |
| 51 | +enabling customer teams to use the configuration as a black box and use Terraform as |
| 52 | +a tool to manage their services. |
| 53 | + |
| 54 | +#### Software Demos |
| 55 | + |
| 56 | +Modern software is increasing networked and distributed. Although there exists |
| 57 | +tools like [Vagrant](http://www.vagrantup.com/) to build virtualized environments |
| 58 | +for demos, it is still very challenging to demo software on infrastructure providers |
| 59 | +which more closely match production environments or require a large number of nodes. |
| 60 | + |
| 61 | +Sofware writers can provide a Terraform configuration to create, provision and |
| 62 | +bootstrap a demo on cloud providers like AWS. This allows end users to easily demo |
| 63 | +the software on their own infrastructure, and even enables tweaking parameters like |
| 64 | +cluster size to more rigorously test tools at any scale. |
| 65 | + |
| 66 | +#### Disposable Environments |
| 67 | + |
| 68 | +It is common practice to have both a production and staging or QA environment. |
| 69 | +These environments are smaller clones of their production counterpart, but are |
| 70 | +used to test new applications before releasing in production. As the production |
| 71 | +environment grows larger and more complex, it becomes increasingly onerous to |
| 72 | +maintain an up-to-date staging environment. |
| 73 | + |
| 74 | +Using Terraform, the production environment can codified and then shared with |
| 75 | +staging, QA or dev. These configurations can be used to rapidly spin up new |
| 76 | +environments to test in, and then easily disposed of. Terraform can help tame |
| 77 | +the difficulty of maintaining parallel environments, and makes it practical |
| 78 | +to elastically create and destroy them. |
| 79 | + |
| 80 | +#### Software Defined Networking |
| 81 | + |
| 82 | +Software Defined Networking (SDN) is becoming increasingly prevalent in the |
| 83 | +datacenter, as it provides more control to operators and developers and |
| 84 | +allows the network to better support the applications running on top. Most SDN |
| 85 | +implementations have a control layer and infrastructure layer. |
| 86 | + |
| 87 | +Terraform can be used to codify the configuration for software defined networks. |
| 88 | +This configuration can then be used by Terraform to to automatically setup and modify |
| 89 | +settings by interfacing with the control layer. This allows configuration to be |
| 90 | +versioned and changes to be automated. As an example, [AWS VPC](http://aws.amazon.com/vpc/) |
| 91 | +is the largest deployments and commonly used SDN implementations, and [can be configured by |
| 92 | +Terraform](/docs/providers/aws/r/vpc.html). |
| 93 | + |
| 94 | +#### Resource Schedulers |
| 95 | + |
| 96 | +In large scale infrastructures, static assignment of applications to machines |
| 97 | +becomes increasingly challenging. To solve that problem, there are a number |
| 98 | +of schedulers like Borg, Mesos, YARN, and Kubernetes. These can be used to |
| 99 | +dynamically schedule Docker containers, Hadoop, Spark, and many other software |
| 100 | +tools. |
| 101 | + |
| 102 | +Terraform is not limited to physical providers like AWS. Resource schedulers |
| 103 | +can be treated as a provider, allowing Terraform to request resources from them. |
| 104 | +This allows Terraform to be used in layers: to setup the physical infrastructure |
| 105 | +running the schedulers as well as onto the scheduled grid. |
| 106 | + |
0 commit comments