Leanpub Header

Skip to main content

Topics

Terraform

From configuration, providers, state and plans to modules, drift, OpenTofu, Terragrunt and security review, Terraform as told through the free samples of Leanpub books.

Created from the free samples of 7 Leanpub books and the descriptions and tables of contents of 7 more, with every source cited.

Terraform is a tool for creating and changing infrastructure from text files. An engineer describes the networks, servers, databases and other objects that should exist; Terraform compares that description with its record of what it manages and with what is actually there, and proposes a set of operations against the platforms' programming interfaces to make the two agree.[1] It is the most widely used implementation of infrastructure as code, the practice of defining infrastructure in version-controlled, machine-readable files and giving those files the review, testing and change history that application code receives.[2]

The tool was released in 2014 and was designed from the start to work across platforms, with one language and one workflow whichever provider is targeted.[2] That reach now covers the large public clouds, private platforms and software services, through plugins called providers.[5] A change of licence in 2023 split its community: an open-source fork, OpenTofu, has developed alongside it since, and the books published afterwards mostly teach concepts that hold for both.[2]

This article covers the idea of infrastructure as code, how Terraform works, where it fits among other tools, the licence change and OpenTofu, versions and the toolchain, modules and larger organisations, security review, the clouds the books build on, and certification. Its sources are the free samples of seven Leanpub books and the descriptions and tables of contents of seven more, published between 2023 and 2026. Two of the samples carry most of the teaching text; several others consist of front matter and a table of contents, and are cited for what those say.

Where to start

A newcomer has several first books. Terraform A Complete Visual Guide (2026) is for readers new to Terraform and for systems engineers who want to put what they know in order; it builds a mental model with diagrams before any cloud is involved, using a local file as its first example.[1] Terraform: A Comprehensive Guide (2026) starts from no Terraform experience and aims at team-scale use, explaining why each feature works as it does and when to avoid it.[2] Terraform Quickstart: The Beginner's Guide to Infrastructure as Code (2026) is a step-by-step introduction whose exercises use free services, so that no paid cloud account is needed.[9] Terraform By Example (2024) teaches beginners through labs on one public cloud, and Introduction to Terraform (2023) covers a wide range in twenty-one short chapters.[10][8]

Application developers have two. Modern Cloud Infrastructure-as-Code for Developers (2023) assumes little cloud knowledge and builds three small deployable projects.[3] Terraform for Developers, Second Edition (2026) is a ten-chapter guide for developers and cloud administrators that reaches secrets management and container clusters.[4]

The rest have a particular reader. Architecting and Implementing DevOps for Infrastructure Management in Azure (2025) is for infrastructure engineers designing for one cloud. Infrastructure as Code with OpenTofu (2026) teaches the fork, including to those switching to it. Mastering Terragrunt (2026) and Infrastructure as Code Mastery (2026) are for teams whose Terraform is already in use and under strain. Infrastructure as Code for Security Engineers (2026) is for people who review Terraform and do not write it.[5][6][13][14][12] Two study guides, Hashicorp Terraform Associate Certification (Exam 004), Second Edition (2026) and Terraform Authoring and Operations Professional Study Guide (2025), prepare for the vendor's two certifications.[7][11]

Infrastructure as code

The practice arose from the failure of the manual alternative. One book opens with a small company whose engineers create servers by clicking through a cloud provider's console and installing software from commands on a wiki page. Six months and twenty-five servers later, nobody knows exactly what any machine runs, and one rebuilt after a failure is missing a security patch the others have.[2] The book sorts the trouble into five kinds: environments that cannot be reproduced, documentation that drifts from reality, inconsistency between people, changes that bypass review, and provisioning time that grows with the number of resources.[2]

Infrastructure as code answers these by making a file the thing that creates the infrastructure. A change is an edit in a repository, reviewed and merged like any other, which leaves a history of who changed what, when and why.[2] The same definitions build every environment, differing only in deliberate parameters, and a temporary environment can be created for a test and removed afterwards.[2] The visual guide adds a caution: the code is one part of the practice, and a repository full of configuration files with no protection of state, no review rules and no recovery procedure is not yet a reliable system.[1]

Two distinctions run through the books. The first is between imperative and declarative description. An imperative script lists steps in order and has to deal for itself with what already exists and with a step that fails halfway; a declarative configuration states the result, and the tool works out the steps.[2][1] The second is between mutable and immutable infrastructure. The first generation of tools configured existing servers in place, which allowed them to drift from their intended state over time; later tools, Terraform among them, prefer to replace a component with a new one when it has to change.[4]

How Terraform works

The visual guide reduces the tool to four records that must not be confused. Configuration expresses intent. State records which real object corresponds to which item of configuration. A plan proposes change. The remote platform holds the actual objects. Its analogy is a construction project: the blueprint, the asset register, the change order and the site itself, with providers as the specialist contractors who know how to deal with each platform.[1] An engineer who reads the configuration and says that production is configured a certain way has, on this account, said only what the repository currently asks for.[1]

Configuration is written in HCL, a declarative language meant to be readable by people without a deep infrastructure background.[4] Terraform reads all the configuration files in a directory as one whole, so the order of files and of blocks within them carries no meaning.[2][1] A provider is a plugin that translates the generic life cycle of a resource into calls against a particular platform, and it is part of the effective program: the same configuration can yield a different plan after a provider upgrade.[1] A resource is an object Terraform is expected to create, update and delete, while a data source only reads; the difference is ownership, and importing an existing object as a resource makes its later removal from the configuration a proposal to destroy it.[1]

Init, plan and apply

Work proceeds in three commands. Initialisation prepares a directory: it configures the backend, the place where state is stored, downloads the provider plugins the configuration requires, and writes a lock file recording the exact provider versions and their checksums.[2] The plan command then shows what Terraform intends to do, marking each resource to be created, changed in place or destroyed, before anything is touched; some values appear as known only after the change is applied, because the platform assigns them.[2] Apply carries the changes out, after a confirmation when run by hand.[2] A plan can be saved to a file and that exact plan applied later, which is how a pipeline ensures that what was reviewed is what runs.[2]

Running the plan again on an unchanged configuration reports nothing to do, the behaviour called idempotence.[2] The visual guide treats the exceptions as defects: when a plan still shows changes after a successful apply, something such as an unstable provider or a default computed by the platform is at fault and should be investigated.[1] It is equally plain about failure. A plan is a proposal made at one moment and guarantees nothing about what the interfaces will accept; there is no general transaction across remote platforms, so a failed apply may leave some changes made, and Terraform does not roll them back.[1] A small edit can also produce a large plan, since changing one argument may force a resource to be replaced, and the guide's instruction is to review the planned actions and not only the difference in the source.[1]

State

State is what distinguishes Terraform from a script. It is the stored mapping between addresses in the configuration and the identities of remote objects, together with the attributes needed for planning; without it Terraform could not safely tell that an existing network is the one a given block means.[1] One book lists explicit state among the tool's design principles and among its limitations in the same chapter: it can be inspected to see exactly what Terraform believes exists, and it is a single point of failure whose loss or corruption can leave infrastructure difficult or impossible to manage through the tool.[2] By default state is a file in the project directory; teams move it to a remote backend, and the questions to settle before adopting the tool include where state will be stored, locked, backed up and audited.[2][1] The same subject, with importing and reconciling existing resources, is an objective of the professional certification.[11]

The dependency graph and drift

Terraform orders its work with a graph. A reference from one resource to an attribute of another both supplies a value and creates a dependency, so the referenced resource is handled first, and independent branches of the graph are processed in parallel.[1][3] An explicit dependency declaration is kept for the rare case that cannot be expressed through a reference.[1]

Drift is a difference between a managed object and what the configuration or the state says about it, caused by a manual change, by another automation system or by the platform itself. In the ordinary command-line workflow Terraform does not watch for it. It acts when someone starts a command and finds drift at the next refresh or plan, which sets it apart from controllers that reconcile continuously.[1] A successful apply therefore proves only that the operation succeeded at that time.[1]

Where Terraform fits

The books place Terraform among three families of neighbours. The tools each cloud provider supplies for its own platform integrate deeply and often support new features first, but work for that platform alone, so the same infrastructure on two clouds means two languages.[2] Architecting and Implementing DevOps for Infrastructure Management in Azure makes the comparison for one cloud. That provider's own template language can describe only its resources, and the book gives Terraform's support for many platforms as the reason for its popularity, noting that large organisations seldom keep everything in one cloud.[5] The second family uses general-purpose programming languages in place of a declarative one. The same book's view is that this spares a team a new syntax and demands programming skill that infrastructure teams often lack, so for most of them a declarative tool is the shorter road.[5]

The third family is configuration management: tools such as Ansible, Chef and Puppet, which install and configure software on machines. They are less suited to creating networks, load balancers and databases, and many teams use both kinds, Terraform to provision and a configuration tool for what runs inside.[2] The Azure book warns against letting either practice swallow the other and holds that in a large organisation both should exist.[5]

The visual guide draws the boundary with a single test: is this a durable object, managed through an interface, with a life cycle worth reviewing, or a passing operational action? Networks, firewalls, databases, DNS records and identity roles are good fits. Repeated application releases, long procedures with many branches, and detailed configuration inside a machine are poor ones; they are possible, but someone has to justify the added difficulty of failure and recovery.[1] Terraform, in its words, is neither a general-purpose runner of commands nor a controller that runs continuously.[1]

The licence change and OpenTofu

Terraform was first released under an open-source licence. In August 2023 its owner changed this to a source-available licence that permits most use and restricts some commercial use, notably offering the tool as a managed service in competition with the owner's own; the change applies from version 1.6.[2] It prompted OpenTofu, a community fork that keeps the earlier open-source licence under the governance of a software foundation.[2] As of 2026 both are widely used and share most core behaviour, while differing in licence, governance and some features.[2]

The books respond in different ways. Terraform: A Comprehensive Guide and Infrastructure as Code Mastery teach concepts meant to apply to both.[2][14] Mastering Terragrunt names both in its subtitle.[13] Infrastructure as Code with OpenTofu teaches the fork directly, in eleven chapters from first configurations to modules, state and automated pipelines; its author presents the move as a matter of licensing cost and says that existing configurations carry over without an overhaul of a team's workflow.[6] Its sample holds the front matter and contents only.

Versions and the toolchain

A run can be trusted, in the visual guide's account, only when the executable, the provider plugins, the configuration, the credentials, the target account and the location of state are all known, because a version change or a mistaken identity can alter infrastructure although the source has not changed.[1] Its practices follow from that. The repository declares which versions of Terraform it accepts, and a run with any other stops with an error; each module declares the providers it needs and their compatible versions; and the lock file that records the exact selections is committed, so that every engineer and every pipeline uses the same builds.[1][2] The working directory of downloaded plugins is not committed and is rebuilt by initialisation.[2]

Credentials are kept out of the configuration and supplied from the environment or the platform, and writing them into configuration files is treated as a security fault.[2] An installation is checked against its publisher's checksums, with the guide's reminder that a matching checksum shows what the bytes are and not who published them.[1]

The books give their own baselines. The visual guide's examples target the 1.16 series, the comprehensive guide names 1.15 as current in the middle of 2026, and the associate-level study guide describes itself as updated for 1.12.[1][2][7] Providers are released separately from the core, so the provider's version matters as much as the tool's.[1]

Modules and larger organisations

A module packages related resources behind defined inputs and outputs, so that one pattern can be used in many places with different parameters. Modularity is among the design principles one book lists, and another describes modules as the means by which a team stops rewriting the same definitions for each new service.[2][4] Above single modules come the questions of repository layout, environments and many accounts, to which the visual guide gives its second half.[1]

Terragrunt is a separate open-source tool for that scale. Mastering Terragrunt describes it as an orchestration layer and not a replacement: it deals with the duplication and coordination that appear once infrastructure grows past a handful of environments, through shared parent configuration, declared dependencies between units and a defined order of execution. The book has chapters on when not to use it and on over-engineered hierarchies of includes.[13] Infrastructure as Code Mastery treats the same pressure as an organisational matter, addressed to teams whose Terraform works until several teams touch it, with version-controlled workflows, pipelines, policy as code, testing and operations after deployment as its subjects.[14] Both are cited from their descriptions; neither has a sample.

Security and review

Infrastructure as Code for Security Engineers starts from a consequence of all this. Infrastructure has become text in a repository, a single file can expose a network or grant access to a database, and the only record may be a merged change request, so a large share of an organisation's attack surface now sits in version control.[12] The book teaches security and compliance staff to read and audit Terraform without writing it. Its chapters take in order where secrets leak, why the state file is a liability that knows more than the code does, the scope of provider credentials, the threat model of the pipeline that applies changes, the limits of policy as code, supply-chain risk in modules and providers, and the turning of a review into evidence an auditor will accept. It holds that the plan is where the truth lies.[12] It has no sample, and these are its stated contents.

The teaching books touch the same points from the author's side: credentials outside the configuration, state protected and backed up, and plans reviewed before they are applied.[2][1] Sensitive data has a chapter of its own in the associate-level study guide, and the second edition for developers covers short-lived credentials issued by a secrets manager in place of stored ones.[7][4]

Clouds and first projects

The concepts are the same on every platform and the examples are not, so the cloud a book builds on is a practical reason to choose it. Modern Cloud Infrastructure-as-Code for Developers builds three projects on one public cloud: a static site served from object storage through a content delivery network, a serverless interface, and containers on a managed Kubernetes service. Its first project shows the usual shape of a small configuration, with separate files for variables, the provider, each resource and shared tags, followed by init, plan and apply.[3] Terraform By Example uses the same cloud for its labs and ends with fixes for specific errors.[10]

Architecting and Implementing DevOps for Infrastructure Management in Azure pairs another cloud's architectural guidance with the Terraform that implements it, and adds automated pipelines and configuration management; its sample covers the cloud's foundations and the case for infrastructure as code, and stops before any Terraform.[5] Terraform for Developers, Second Edition also sets its examples on that cloud.[4] Terraform Quickstart: The Beginner's Guide to Infrastructure as Code avoids the large clouds altogether and has the reader create and import repositories on a code-hosting service, a reminder that providers exist for far more than virtual machines.[9] Introduction to Terraform reaches serverless architectures, container orchestration and several providers at once in its later chapters.[8]

Certification

Two study guides follow the vendor's two examinations. Hashicorp Terraform Associate Certification (Exam 004), Second Edition prepares for the associate level in nine chapters that also serve as a course: infrastructure as code, fundamentals, the core workflow, resources, variables and outputs, dynamic configuration and dependencies, sensitive data, state, modules and the vendor's hosted platform, with review questions and two mock examinations.[7] Terraform Authoring and Operations Professional Study Guide prepares for the professional level, works through its six objectives with examples on one cloud, and assumes the reader already knows the basic workflow and the language.[11] The first is cited from its prologue and contents and the second from its description; neither sample includes chapter text.

Questions about Terraform

Which Terraform book should I start with?

A newcomer who wants the model before the cloud can start with Terraform A Complete Visual Guide (2026), which separates configuration, state, plan and real infrastructure with diagrams.[1] Terraform: A Comprehensive Guide (2026) starts from no experience and goes on to team-scale use.[2] A reader without a paid cloud account can use Terraform Quickstart: The Beginner's Guide to Infrastructure as Code (2026), whose exercises run on free services.[9]

What is Terraform state?

State is Terraform's stored mapping between the addresses in a configuration and the identities of the real objects it manages, with the attributes needed for planning.[1] It is a critical asset: its loss or corruption can leave infrastructure difficult or impossible to manage through the tool.[2]

What is the difference between Terraform and OpenTofu?

OpenTofu is a community fork created after Terraform's licence changed in August 2023 from an open-source licence to a source-available one that restricts some commercial use.[2] The two share most core behaviour and differ in licence, governance and some features.[2]

Does Terraform roll back a failed apply?

No. There is no general transaction across remote platforms, so some changes may succeed before a later one fails.[1] The next step is to inspect what changed and make a new plan.[1]

Should I use Terraform or Ansible?

They do different jobs. Terraform provisions resources such as networks, load balancers and databases, and configuration management tools such as Ansible install and configure software on machines; many teams use both.[2] One source advises against replacing either practice with the other in a large organisation.[5]

Does Terraform detect changes made outside it?

Only when it is run. In the ordinary command-line workflow Terraform does not watch infrastructure continuously and finds drift at the next refresh or plan.[1] A successful apply proves only that the operation succeeded at that time.[1]

Sources

Every source is a Leanpub book or course. The note after each says which part of it was read; where no sample was available, only the public description and table of contents were used.

  1. 1.
    Terraform A Complete Visual Guide, Reiner Braun: Complete Guide — Foundations, Architecture, Automation, Security, Scale, and Operations Free sample: the introduction, chapter 1 on the operating model, state, plans, the dependency graph, drift and where Terraform fits, and part of chapter 2 on installation, versions and the lock file. 2026. Free sample: PDF · EPUB
  2. 2.
    Terraform: A Comprehensive Guide, Steve Publications: From First Configuration to Production Infrastructure at Scale Free sample: chapter 1 on infrastructure as code, declarative tools, the licence change and design principles, and part of chapter 2 on installation and a first init, plan and apply. 2026. Free sample: PDF · EPUB
  3. 3.
    Modern Cloud Infrastructure-as-Code for Developers, Salie Lim Free sample: the introduction, short overviews of the tools, and most of the first project, a static site on object storage. 2023. Free sample: PDF · EPUB
  4. 4.
    Terraform for Developers, Second Edition, GitforGits | Asian Publishing House: Essentials of Infrastructure Automation and Provisioning Free sample: the prologue, the table of contents and the opening of chapter 1 on the history of infrastructure as code. 2026. Free sample: PDF
  5. 5.
    Architecting and Implementing DevOps for Infrastructure Management in Azure, Ashish Raj: Infrastructure DevOps in Azure: Configure, Deploy, & Automate Your Azure resources with terraform, GitHub Actions and Ansible Free sample: part of chapter 1 on cloud foundations and the choice of infrastructure-as-code tools; it stops before any Terraform. 2025. Free sample: PDF · EPUB
  6. 6.
    Infrastructure as Code with OpenTofu, GitforGits | Asian Publishing House: A perfect Terraform alternative to manage compute, storage, networking and other infrastructure resources Free sample: the prologue, the table of contents and the preface. 2026. Free sample: PDF
  7. 7.
    Hashicorp Terraform Associate Certification (Exam 004), Second Edition, GitforGits | Asian Publishing House: Pass terraform certification while you become a proficient Terraform developer to build production-ready infrastructure automation skills Free sample: the prologue and the table of contents. 2026. Free sample: PDF
  8. 8.
    Introduction to Terraform, Bobby Iliev: From Zero to Hero: Unleashing the Power of Terraform No sample: from the description and table of contents. 2023.
  9. 9.
    Terraform Quickstart: The Beginner's Guide to Infrastructure as Code, Kirshi Yin | Curious Devs Corner: The Beginner's Guide to Infrastructure as Code No sample: from the description and table of contents. 2026.
  10. 10.
    Terraform By Example, Luca Berton: A Practical Approach for Beginners to Learn Cloud Infrastructure with Terraform No sample: from the description and table of contents. 2024.
  11. 11.
    Terraform Authoring and Operations Professional Study Guide, Mattias Fjellström: Azure edition No sample: from the description and table of contents. 2025.
  12. 12.
    Infrastructure as Code for Security Engineers, Joshua Phillips No sample: from the description and table of contents. 2026.
  13. 13.
    Mastering Terragrunt, Steve Publications: Infrastructure Orchestration at Scale with Terraform and OpenTofu No sample: from the description and table of contents. 2026.
  14. 14.
    Infrastructure as Code Mastery, Nick Vyzas: A Hands-On Playbook for Terraform, OpenTofu, CI/CD, and Platform Engineering No sample: from the description. 2026.

Further reading

Other books in the library on the same ground, not cited above.

  • The Journey to DevOps, Harry Yan: A Practical Guide for Software Engineers and Enthusiasts An introduction to DevOps for software engineers, with a chapter on Terraform among chapters on containers, clusters and pipelines. 2024. Free sample: PDF
  • Build Your Own DevOps Lab, Osomudeya Zudonu: Zero-Cost Infrastructure Guide A DevOps lab built on a laptop without a cloud account, with Terraform and Ansible as one of its parts. 2026. Free sample: PDF
  • Windows Server Automation for DevOps, Steve Publications: Building Secure, Scalable, Production-Grade Infrastructure with PowerShell, DSC, Terraform, and CI/CD Automating Windows Server, with Terraform as one chapter among scripting, configuration and pipelines. 2026. Free sample: PDF · EPUB
  • Cyber Range Essentials, Nicholas McKinney: Construct a Hybrid Cloud-Physical Lab with Ansible and Terraform Building a security practice lab across physical hardware and cloud accounts with Ansible and Terraform. 2022.
  • DevSecOps Tools in Cloud Platform, Joseph Thachil George: DevSecOps Security tooling for cloud platforms, with a project on scanning Terraform code for vulnerabilities. 2022. Free sample: PDF

This is an article created from the free samples of 7 Leanpub books and the descriptions and tables of contents of 7 more. We're building these articles to provide you, the Leanpub reader, with a good jumping-off point to discover more Leanpub books that are interesting and relevant to you. We never use material which is paid-only when building these articles: we only use material which is already free on Leanpub. However, Leanpub authors can opt out from inclusion in articles from their book settings page.

Updated November 2026.

In the Leanpub store: 62 books in the Terraform category

All topics