Today, I would like to discuss a DevOps tool: Terraform, which we use a lot in Apiumhub.
As we all know, the target of the DevOps movement is to make code always in a deployable and maintainable state. Instead of making a new release every 3 months because the prod environment should be seldom touched, you can have up to a dozen or more releases per day.
Configuration management is the essential part of DevOps methodology and the tools like Chef, Puppet, Terraform are at the heart of the software development ecosystems. Terraform is gaining popularity and in this article I would like to showcase it’s benefits and use cases.
What is Terraform
Terraform is a Server Provisioning tool. When it comes to Terraform, you are not bound to one server image, but rather a complete infrastructure that can contain application servers, databases, CDN servers, load balancers, firewalls, and others. While configuration management tools ensure that each individual server is at the desired state, a server provisioning tool like Terraform ensures that the infrastructure as a whole is in the desired state.
Terraform is a free and open source tool created by HashiCorp and written in the Go programming language. It can be used to provision entire infrastructures that span across multiple public and private cloud providers like AWS, Google Cloud, Microsoft Azure, OpenStack and others. It manages external resources ( network appliances, software as a service, platform as a service, etc. ) with “providers”.
Basically, Terraform allows programmers to build, change, and version infrastructure safely and efficiently. Terraform can help with multi-cloud by having one workflow for all clouds. Terraform treats infrastructure as code (IaC), it is the example of next generation of configuration orchestration systems bringing a new layer of features and functionalities to the table.
Terraform is a stateful application. What that means is that it keeps track of everything it builds in your cloud environments, so that if you need to change something or delete something later, Terraform will know what it built, and it can go back and make those changes for you.
- Orchestration, not merely configuration
- Immutable infrastructure
- Declarative, not procedural code
- Client-only architecture
- Clearly mapped resource dependencies
- Consistent workflow
- Elegant user experience
- Strong Community
Terraform Use Cases
- Terraform can be used to codify the setup required for a Heroku application, ensuring that all the required add-ons are available, but it can go even further: configuring DNSimple to set a CNAME, or setting up Cloudflare as a CDN for the app. Best of all, Terraform can do all of this in under 30 seconds without using a web interface.
- The most common 2-tier architecture is 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 independently and provide a separation of concerns.Terraform is an ideal tool for building and managing these infrastructures. Each tier can be described as a collection of resources, and the dependencies between each tier are handled automatically. Terraform ensures 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 the creation and provisioning of a resource is codified and automated, elastically scaling with load becomes trivial.
- 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.
- Software writers can provide a Terraform configuration to create, provision and 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.
- It is common practice to have both a production and staging or QA environment. As the production environment grows larger and more complex, it becomes increasingly onerous to maintain an up-to-date staging environment. Using Terraform, the production environment can be codified and then shared with staging. These configurations can be used to rapidly spin up new environments to test in, and then be easily disposed of. Terraform can help tame the difficulty of maintaining parallel environments, and makes it practical to elastically create and destroy them.
- Terraform can be used to codify the configuration for software defined networks. This configuration can then be used by Terraform to automatically setup and modify settings by interfacing with the control layer. This allows configuration to be versioned and changes to be automated. As an example, AWS VPC is one of the most commonly used SDN implementations, and can be configured by Terraform.
- Resource schedulers can be treated as a provider, enabling Terraform to request resources from them. This allows Terraform to be used in layers: to setup the physical infrastructure running the schedulers as well as provisioning onto the scheduled grid.
- Terraform is cloud-agnostic and allows a single configuration to be used to manage multiple providers, and to even handle cross-cloud dependencies. This simplifies management and orchestration, helping operators build large-scale multi-cloud infrastructures.
- Also, with Terraform you can write declarative configuration files, collaborate and share configurations, evolve and version your infrastructure, automate provisioning, define infrastructure as code to manage the full lifecycle: create new resources, manage existing ones, and destroy those no longer needed.
- Create reproducible infrastructure: reproducible production, staging, and development environments. With Terraform you have shared modules for common infrastructure patterns and you can combine multiple providers consistently. Terraform makes it easy to re-use configurations for similar infrastructure, helping you avoid mistakes and save time.
- Share infrastructure as code. Terraform empowers teams to rapidly review, comment, and iterate on Infrastructure as Code. Terraform allows to have state management (storage, viewing, history, and locking), web UI for viewing and approving Terraform runs, collaborative Runs and private module registry.
- Automate consistent workflows and create a pipeline for provisioning Infrastructure as Code.
- VCS integration (Azure DevOps, Bitbucket, GitHub, and GitLab). With Terraform you can enable GitOps workflow and have notifications for run events (via Slack or webhooks). Also it offers full HTTP API for integrating with other tools and services.
Because Terraform uses a simple syntax, can provision infrastructure across multiple cloud and on-premises data centers, and can safely and efficiently re-provision infrastructure in response to configuration changes, it is currently one of the most popular infrastructure automation tools available. If your organization plans to deploy a hybrid cloud or multicloud environment, you’ll likely want or need to get to know Terraform.
If you would like to know more about Terraform, here you have a brilliant video by IBM explaining Terraform: Video