Last updated 10/06/2021
Welcome to the intro guide to Terraform! This guide is the best place to start with Terraform. We cover what Terraform is, what are its key features, its use cases, Terraform in DevOps, and how it compares to existing software
Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.
Configuration files describe to Terraform the components needed to run a single application or your entire datacenter. Terraform generates an execution plan describing what it will do to reach the desired state, and then executes it to build the described infrastructure. As the configuration changes, Terraform is able to determine what changed and create incremental execution plans which can be applied.
The infrastructure Terraform can manage includes low-level components such as compute instances, storage, and networking, as well as high-level components such as DNS entries, SaaS features, etc.
Infrastructure as Code
Infrastructure is described using a high-level configuration syntax. This allows a blueprint of your datacenter to be versioned and treated as you would any other code. Additionally, infrastructure can be shared and re-used.
Terraform has a "planning" step where it generates an execution plan. The execution plan shows what Terraform will do when you call apply. This lets you avoid any surprises when Terraform manipulates infrastructure.
Terraform builds a graph of all your resources, and parallelizes the creation and modification of any non-dependent resources. Because of this, Terraform builds infrastructure as efficiently as possible, and operators get insight into dependencies in their infrastructure.
Complex changes can be applied to your infrastructure with minimal human interaction. With the previously mentioned execution plan and resource graph, you know exactly what Terraform will change and in what order, avoiding many possible human errors.
Heroku App Setup
Heroku is a popular PaaS for hosting web apps. Developers create an app and then attach add-ons, such as a database, or email provider. One of the best features is 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 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.
A very common pattern is the N-tier architecture. 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 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 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.
Modern software is increasingly networked and distributed. Although tools like Vagrant exist to build virtualized environments for demos, it is still very challenging to demo software on real infrastructure which more closely matches production environments.
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. 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.
Using Terraform, the production environment can be codified and then shared with staging, QA or dev. 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.
Software-Defined Networking (SDN) is becoming increasingly prevalent in the data center, 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. 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.
In large-scale infrastructures, the static assignment of applications to machines 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 can be treated as a provider, enabling Terraform to request resources from them. This allows Terraform to be used in layers: to set up the physical infrastructure running the schedulers as well as provisioning onto the scheduled grid.
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 for infrastructure management are cloud-specific. 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.
Terraform is quietly revolutionizing DevOps by changing the way infrastructure is managed, and making it faster and more efficient to execute DevOps projects. Although this infrastructure builder shares the same core principle as other DevOps technologies (i.e. infrastructure as code), it’s unusual because it focuses on the automation of the infrastructure itself. This means that your entire Cloud infrastructure can be described in Terraform.
Unlike other comparable tools, Terraform isn’t locked to a particular platform and supports all major cloud providers. There are also a few other differences to comparable technologies. One of these is the way Terraform handles failure. When provisioning fails, Terraform marks the suspect resource and removes and re-provisions them at the next execution. The advantage of this approach to managing failed resources is that the system does not re-build resources that are successfully provisioned, instead of focusing its attention on those that are tainted.
Used as part of a multi-team DevOps process, Terraform also allows teams such as operations and security to work in parallel with developers. Each element in the DevOps process has a specifically designed tool, which means teams can focus on their particular tasks without blocking other teams working on the project. This transforms the DevOps process from a linear and slow waterfall-type project into one where teams can work in parallel.
This has the effect of allowing them to execute a DevOps model faster and more efficiently. This is why Terraform is having such an impact on the DevOps process and why it will do so in the future.
Terraform provides a flexible abstraction of resources and providers. This model allows for representing everything from physical hardware, virtual machines, and containers, to email and DNS providers. Because of this flexibility, Terraform can be used to solve many different problems. This means there are a number of existing tools that overlap with the capabilities of Terraform. We compare Terraform to a number of these tools, but it should be noted that Terraform is not mutually exclusive with other systems. It can be used to manage a single application or the entire datacenter.
NovelVista Learning Solutions is a professionally managed training organization with specialization in certification courses. The core management team consists of highly qualified professionals with vast industry experience. NovelVista is an Accredited Training Organization (ATO) to conduct all levels of ITIL Courses. We also conduct training on DevOps, AWS Solution Architect associate, Prince2, MSP, CSM, Cloud Computing, Apache Hadoop, Six Sigma, ISO 20000/27000 & Agile Methodologies.
* Your personal details are for internal use only and will remain confidential.
|AWS Solution Architect Associates|
|SIAM Professional Training & Certification|
|ITIL® 4 Foundation Certification|
|DevOps Foundation By DOI|
|Certified DevOps Developer|
|PRINCE2® Foundation & Practitioner|
|ITIL® 4 Managing Professional Bridge Course|
|Certified DevOps Engineer|
|DevOps Practitioner + Agile Scrum Master|
|ISO Lead Auditor Combo Certification|
|Microsoft Azure Administrator AZ-104|
|Digital Transformation Officer|
|Certified Full Stack Data Scientist|
|Microsoft Azure DevOps Engineer|
|Professional Scrum Product Owner II (PSPO II) Certification|
|Certified Associate in Project Management (CAPM)|
|Practitioner Certified In Business Analysis|
|Certified Blockchain Professional Program|
|Certified Cyber Security Foundation|
|Post Graduate Program in Project Management|
|Certified Data Science Professional|
|Certified PMO Professional|
|AWS Certified Cloud Practitioner (CLF-C01)|
|Certified Scrum Product Owners|
|Professional Scrum Product Owner-II|
|Professional Scrum Product Owner (PSPO) Training-I|
|GSDC Agile Scrum Master|
|ITIL® 4 Certification Scheme|
|Agile Project Management|
|FinOps Certified Practitioner certification|
|ITSM Foundation: ISO/IEC 20000:2011|
|Certified Design Thinking Professional|
|Certified Data Science Professional Certification|
|SRE Foundation and SRE Practitioner comb|
|Generative AI Certification|