Terraform Explained: Infrastructure as Code Fundamentals

Terraform helps teams describe infrastructure in version-controlled files, preview the difference, and make an approved change in a repeatable way. For a network engineer, that is a useful shift from remembering every click to reviewing a clear desired result.

TerraformInfrastructure as CodeStateAutomation
Nine-part learning path

Network Automation and Programmability Series

After programmable APIs and data-driven insight, Terraform introduces the declarative workflow used to manage infrastructure through code.

Part 8 of 9

The Terraform Workflow at a Glance

Terraform reads your configuration, compares it with its state and the real platform, then shows a plan. The important habit is review: treat the plan as a change proposal, not a formality.

Terraform workflow showing HCL configuration, plan, apply, and infrastructure across cloud and network platforms
Terraform makes the proposed change visible before it creates or updates infrastructure.

Terraform Concepts in Simple Words

Terraform files use HashiCorp Configuration Language, usually called HCL. It looks a little like JSON, but is designed to be easy to read and reuse.

Terraform guide explaining providers, resources, state, common use cases, and alternatives
Providers connect Terraform to platforms; resources describe the items you want Terraform to manage; state helps it understand what already exists.

Provider

A provider is a plugin that talks to a platform API, such as AWS, Azure, Google Cloud, Cisco, DNS, or IP address management.

Resource

A resource is an item you want to create or manage, such as a virtual machine, network, subnet, firewall rule, or DNS record.

State

State is Terraform's record of the objects it manages. Store it securely, especially when a team shares the same environment.

Alternatives: OpenTofu uses a very similar workflow. Pulumi uses general-purpose programming languages. Tools such as Ansible are usually better for configuring and checking existing devices after infrastructure is ready.

What Terraform Is

Terraform is an Infrastructure as Code tool. You write the desired infrastructure in human-readable configuration files. A provider translates that description into API calls for a platform such as a cloud service, DNS platform, IPAM system or network controller.

Declarative means: you state what you want, such as a network, subnet or policy. Terraform works out the actions needed to reach that result.

This is different from a script that only lists commands in order. Terraform still needs careful thinking, but it gives the team a clearer before-and-after view.

The Core Terraform Parts

Provider

The connector that knows how to talk to a platform API. It is the bridge between your code and a real system.

Resource

An object Terraform manages, such as a VNet, subnet, address record, VLAN or controller policy.

Variables and outputs

Variables make configuration reusable. Outputs show useful results to people or another automation stage.

resource "example_network" "training" {
  name     = "training-network"
  location = var.location
}

The example is deliberately simple. Real resource names and fields come from the provider documentation for the platform you manage.

Why State, Plan and Review Matter

Terraform state records the relationship between your configuration and real infrastructure. It lets Terraform calculate whether an object should be created, changed or removed. Because it can contain sensitive information, keep it protected and use a shared remote backend for team work.

  1. InitializeDownload and configure the providers and backend needed for the project.
  2. Validate and formatCatch basic mistakes before requesting a platform change.
  3. PlanRead the proposed change carefully, especially replacements and deletions.
  4. ApplyMake the reviewed change, then verify the real service and update the record.

Terraform with Cisco IOS XE and RESTCONF

Terraform can also manage supported network devices. In this example, the IOS XE provider reads your HCL file, sends API requests over HTTPS RESTCONF, and creates a loopback interface on the router.

Terraform workflow for Cisco IOS XE showing an HCL file, IOS XE provider, RESTCONF over HTTPS, router configuration, and replacement behavior
Terraform uses a provider to translate your desired interface configuration into RESTCONF API calls for the router.
terraform {
  required_providers {
    iosxe = { source = "CiscoDevNet/iosxe" }
  }
}

resource "iosxe_interface_loopback" "training" {
  name              = 100
  description       = "Terraform training loopback"
  shutdown          = false
  ipv4_address      = "1.1.1.1"
  ipv4_address_mask = "255.255.255.255"
}

This small example describes one loopback interface. Before using it, configure RESTCONF and HTTPS on a lab router, follow the provider documentation for your supported IOS XE release, and keep the router URL and login details outside the code.

Read the plan carefully: changing the loopback number can mean replacing the resource. Terraform will show this as a destroy-and-create change before it makes the change.
  • Provision cloud virtual networks, subnets, route tables, gateways and security rules.
  • Create repeatable environments for labs, application teams or branch deployments.
  • Manage API-driven network services alongside compute and application infrastructure.
  • Keep reviewed infrastructure definitions in Git with a clear history of why a change happened.
Important: Terraform is powerful because it can change many objects consistently. Protect production workspaces, use least-privilege credentials, and never treat a plan with deletions as routine.

The Final Lesson: Ansible

Terraform is often strongest when you need to create or manage infrastructure objects through an API. Ansible is commonly used to configure and validate many existing network devices. Together, they support a practical automation workflow.

Terraform Explained: Infrastructure as Code Fundamentals Frequently Asked Questions

What is Terraform used for?

It creates and manages infrastructure from version-controlled configuration files through supported provider APIs.

Is Terraform the same as Ansible?

No. Terraform focuses on desired infrastructure and state. Ansible commonly focuses on configuration tasks and operational workflows. They can work well together.

What is Terraform state?

It is Terraform's record of the real objects it manages. It helps calculate future changes and must be stored securely.

Why review terraform plan?

The plan shows what Terraform intends to change. Review prevents unexpected replacements or removals from reaching production.